Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
composable_kernel
Commits
c0c1d247
Commit
c0c1d247
authored
Sep 14, 2022
by
Po-Yen, Chen
Browse files
Add Tensor<>::AsSpan<>() to create view of tensor values
parent
b85e8611
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
library/include/ck/library/utility/host_tensor.hpp
library/include/ck/library/utility/host_tensor.hpp
+25
-0
No files found.
library/include/ck/library/utility/host_tensor.hpp
View file @
c0c1d247
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include <vector>
#include <vector>
#include "ck/utility/data_type.hpp"
#include "ck/utility/data_type.hpp"
#include "ck/utility/span.hpp"
template
<
typename
Range
>
template
<
typename
Range
>
std
::
ostream
&
LogRange
(
std
::
ostream
&
os
,
Range
&&
range
,
std
::
string
delim
)
std
::
ostream
&
LogRange
(
std
::
ostream
&
os
,
Range
&&
range
,
std
::
string
delim
)
...
@@ -444,6 +445,30 @@ struct Tensor
...
@@ -444,6 +445,30 @@ struct Tensor
typename
Data
::
size_type
size
()
const
{
return
mData
.
size
();
}
typename
Data
::
size_type
size
()
const
{
return
mData
.
size
();
}
template
<
typename
U
=
T
>
auto
AsSpan
()
const
{
constexpr
std
::
size_t
FromSize
=
sizeof
(
T
);
constexpr
std
::
size_t
ToSize
=
sizeof
(
U
);
static_assert
((
ToSize
<
FromSize
?
(
FromSize
%
ToSize
==
0
)
:
(
ToSize
%
FromSize
==
0
)));
using
Element
=
std
::
add_const_t
<
std
::
remove_reference_t
<
U
>>
;
return
ck
::
span
<
Element
>
{
reinterpret_cast
<
Element
*>
(
data
()),
size
()
*
FromSize
/
ToSize
};
}
template
<
typename
U
=
T
>
auto
AsSpan
()
{
constexpr
std
::
size_t
FromSize
=
sizeof
(
T
);
constexpr
std
::
size_t
ToSize
=
sizeof
(
U
);
static_assert
((
ToSize
<
FromSize
?
(
FromSize
%
ToSize
==
0
)
:
(
ToSize
%
FromSize
==
0
)));
using
Element
=
std
::
remove_reference_t
<
U
>
;
return
ck
::
span
<
Element
>
{
reinterpret_cast
<
Element
*>
(
data
()),
size
()
*
FromSize
/
ToSize
};
}
Descriptor
mDesc
;
Descriptor
mDesc
;
Data
mData
;
Data
mData
;
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment