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
b58786f2
Commit
b58786f2
authored
Nov 13, 2022
by
Anthony Chang
Browse files
serialize tensor object in readable format
parent
d1567094
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
0 deletions
+56
-0
include/ck/utility/data_type.hpp
include/ck/utility/data_type.hpp
+10
-0
library/include/ck/library/utility/host_tensor.hpp
library/include/ck/library/utility/host_tensor.hpp
+46
-0
No files found.
include/ck/utility/data_type.hpp
View file @
b58786f2
...
...
@@ -1057,3 +1057,13 @@ struct NumericLimits<int4_t>
#endif // CK_EXPERIMENTAL_BIT_INT_EXTENSION_INT4
}
// namespace ck
namespace
std
{
inline
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ck
::
half_t
&
p
)
{
os
<<
static_cast
<
float
>
(
p
);
return
os
;
}
}
// namespace std
library/include/ck/library/utility/host_tensor.hpp
View file @
b58786f2
...
...
@@ -470,3 +470,49 @@ struct Tensor
Descriptor
mDesc
;
Data
mData
;
};
template
<
typename
T
>
void
SerializeTensor
(
std
::
ostream
&
os
,
const
Tensor
<
T
>&
tensor
,
std
::
vector
<
size_t
>&
idx
,
size_t
rank
)
{
if
(
rank
==
tensor
.
mDesc
.
GetNumOfDimension
()
-
1
)
{
os
<<
"("
;
for
(
size_t
i
=
0
;
i
<
rank
;
i
++
)
{
os
<<
idx
[
i
]
<<
(
i
==
rank
-
1
?
", x) : "
:
", "
);
}
size_t
dimz
=
tensor
.
mDesc
.
GetLengths
()[
rank
];
os
<<
"["
;
for
(
size_t
i
=
0
;
i
<
dimz
;
i
++
)
{
idx
[
rank
]
=
i
;
os
<<
tensor
(
idx
)
<<
(
i
==
dimz
-
1
?
"]"
:
", "
);
}
os
<<
"
\n
"
;
return
;
}
for
(
size_t
i
=
0
;
i
<
tensor
.
mDesc
.
GetLengths
()[
rank
];
i
++
)
{
idx
[
rank
]
=
i
;
SerializeTensor
(
os
,
tensor
,
idx
,
rank
+
1
);
}
}
// Example format for Tensor(2, 2, 3):
// (0, 0, x) : [0, 1, 2]
// (0, 1, x) : [3, 4, 5]
// (1, 0, x) : [6, 7, 8]
// (1, 1, x) : [9, 10, 11]
template
<
typename
T
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
Tensor
<
T
>&
tensor
)
{
std
::
vector
<
size_t
>
idx
(
tensor
.
mDesc
.
GetNumOfDimension
(),
0
);
SerializeTensor
(
os
,
tensor
,
idx
,
0
);
return
os
;
}
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