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
jerrrrry
infinicore
Commits
86c701a8
Commit
86c701a8
authored
Mar 14, 2025
by
PanZezhong
Browse files
issue/68/fix 使用utils中的cast函数
parent
eab61cb3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
37 deletions
+4
-37
src/infiniop-test/include/utils.hpp
src/infiniop-test/include/utils.hpp
+1
-34
src/infiniop-test/src/tensor.cpp
src/infiniop-test/src/tensor.cpp
+3
-3
No files found.
src/infiniop-test/include/utils.hpp
View file @
86c701a8
...
...
@@ -7,43 +7,10 @@
#define CHECK_OR(cmd, action) CHECK_API_OR(cmd, INFINI_STATUS_SUCCESS, action)
inline
float
f16_to_f32
(
uint16_t
h
)
{
uint32_t
sign
=
(
h
&
0x8000
)
<<
16
;
int32_t
exponent
=
(
h
>>
10
)
&
0x1F
;
uint32_t
mantissa
=
h
&
0x3FF
;
uint32_t
f32
;
if
(
exponent
==
31
)
{
if
(
mantissa
!=
0
)
{
f32
=
sign
|
0x7F800000
|
(
mantissa
<<
13
);
}
else
{
f32
=
sign
|
0x7F800000
;
}
}
else
if
(
exponent
==
0
)
{
if
(
mantissa
==
0
)
{
f32
=
sign
;
}
else
{
exponent
=
-
14
;
while
((
mantissa
&
0x400
)
==
0
)
{
mantissa
<<=
1
;
exponent
--
;
}
mantissa
&=
0x3FF
;
f32
=
sign
|
((
exponent
+
127
)
<<
23
)
|
(
mantissa
<<
13
);
}
}
else
{
f32
=
sign
|
((
exponent
+
127
-
15
)
<<
23
)
|
(
mantissa
<<
13
);
}
float
result
;
memcpy
(
&
result
,
&
f32
,
sizeof
(
result
));
return
result
;
}
inline
double
getVal
(
void
*
ptr
,
GGML_TYPE
ggml_type
)
{
switch
(
ggml_type
)
{
case
GGML_TYPE_F16
:
return
f16_to_f32
(
*
(
uint
16_t
*
)
ptr
);
return
utils
::
cast
<
double
>
(
*
(
fp
16_t
*
)
ptr
);
case
GGML_TYPE_F32
:
return
*
(
float
*
)
ptr
;
case
GGML_TYPE_F64
:
...
...
src/infiniop-test/src/tensor.cpp
View file @
86c701a8
...
...
@@ -20,11 +20,11 @@ void printData(const T *data, const std::vector<size_t> &shape, const std::vecto
}
template
<
>
void
printData
(
const
uint
16_t
*
data
,
const
std
::
vector
<
size_t
>
&
shape
,
void
printData
(
const
fp
16_t
*
data
,
const
std
::
vector
<
size_t
>
&
shape
,
const
std
::
vector
<
ptrdiff_t
>
&
strides
,
size_t
dim
)
{
if
(
dim
==
shape
.
size
()
-
1
)
{
for
(
size_t
i
=
0
;
i
<
shape
[
dim
];
i
++
)
{
std
::
cout
<<
f16_to_f32
(
*
(
data
+
i
*
strides
[
dim
]))
<<
" "
;
std
::
cout
<<
utils
::
cast
<
float
>
(
*
(
data
+
i
*
strides
[
dim
]))
<<
" "
;
}
}
else
if
(
dim
<
shape
.
size
()
-
1
)
{
for
(
size_t
i
=
0
;
i
<
shape
[
dim
];
i
++
)
{
...
...
@@ -177,7 +177,7 @@ void Tensor::debug() const {
std
::
cout
<<
"Tensor: "
<<
tensor
->
info
()
<<
std
::
endl
;
switch
(
_ggml_type
)
{
case
GGML_TYPE_F16
:
printData
((
uint
16_t
*
)(
tensor
->
data
()),
_shape
,
_strides
,
0
);
printData
((
fp
16_t
*
)(
tensor
->
data
()),
_shape
,
_strides
,
0
);
break
;
case
GGML_TYPE_F32
:
printData
((
float
*
)(
tensor
->
data
()),
_shape
,
_strides
,
0
);
...
...
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