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_ROCM
Commits
d3c89355
Commit
d3c89355
authored
Oct 30, 2024
by
Rostyslav Geyyer
Browse files
Add conversion tests
parent
cf7e20a8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
test/data_type/test_fp4.cpp
test/data_type/test_fp4.cpp
+27
-0
No files found.
test/data_type/test_fp4.cpp
View file @
d3c89355
...
...
@@ -5,6 +5,7 @@
#include "ck/utility/data_type.hpp"
#include "ck/utility/type_convert.hpp"
using
ck
::
f4_convert_rne
;
using
ck
::
f4_t
;
using
ck
::
type_convert
;
...
...
@@ -17,3 +18,29 @@ TEST(FP8, NumericLimits)
EXPECT_EQ
(
ck
::
NumericLimits
<
f4_t
>::
MinSubnorm
(),
f4_t
{
0x1
});
EXPECT_EQ
(
ck
::
NumericLimits
<
f4_t
>::
MaxSubnorm
(),
f4_t
{
0x1
});
}
TEST
(
FP8
,
ConvertFP32Nearest
)
{
// fix the tolerance value
float
abs_tol
=
1e-6
;
float
max_fp4
=
6.0
f
;
// convert 0 float to fp4 and back, check if holds
ASSERT_NEAR
(
0.0
f
,
type_convert
<
float
>
(
f4_convert_rne
(
0.0
f
)),
abs_tol
);
// convert maximal f4_t to float and check if equal to 6.0
ASSERT_NEAR
(
max_fp4
,
type_convert
<
float
>
(
f4_convert_rne
(
max_fp4
)),
abs_tol
);
// convert maximal float to fp4 and back, check if clipped to 6.0
ASSERT_NEAR
(
max_fp4
,
type_convert
<
float
>
(
f4_convert_rne
(
std
::
numeric_limits
<
float
>::
max
())),
abs_tol
);
// positive norm float value to fp4 and back, check if holds
float
pos_float
=
1.0
f
;
ASSERT_NEAR
(
pos_float
,
type_convert
<
float
>
(
f4_convert_rne
(
pos_float
)),
abs_tol
);
// negative norm float value to fp4 and back, check if holds
float
neg_float
=
-
1.5
f
;
ASSERT_NEAR
(
neg_float
,
type_convert
<
float
>
(
f4_convert_rne
(
neg_float
)),
abs_tol
);
// positive subnorm float value to fp4 and back, check if holds
pos_float
=
0.5
f
;
ASSERT_NEAR
(
pos_float
,
type_convert
<
float
>
(
f4_convert_rne
(
pos_float
)),
abs_tol
);
// negative subnorm float value to fp4 and back, check if holds
neg_float
=
-
0.5
f
;
ASSERT_NEAR
(
neg_float
,
type_convert
<
float
>
(
f4_convert_rne
(
neg_float
)),
abs_tol
);
}
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