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
dbd20ecc
Commit
dbd20ecc
authored
May 18, 2023
by
Rostyslav Geyyer
Browse files
Add a datatype test
parent
b9bf7fb8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
test/data_type/CMakeLists.txt
test/data_type/CMakeLists.txt
+3
-0
test/data_type/fp8.cpp
test/data_type/fp8.cpp
+61
-0
No files found.
test/data_type/CMakeLists.txt
View file @
dbd20ecc
...
@@ -2,3 +2,6 @@ if (USE_BITINT_EXTENSION_INT4)
...
@@ -2,3 +2,6 @@ if (USE_BITINT_EXTENSION_INT4)
add_gtest_executable
(
test_int4 int4.cpp
)
add_gtest_executable
(
test_int4 int4.cpp
)
target_link_libraries
(
test_int4 PRIVATE utility
)
target_link_libraries
(
test_int4 PRIVATE utility
)
endif
()
endif
()
add_gtest_executable
(
test_fp8 fp8.cpp
)
target_link_libraries
(
test_fp8 PRIVATE utility
)
\ No newline at end of file
test/data_type/fp8.cpp
0 → 100644
View file @
dbd20ecc
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
#include "gtest/gtest.h"
#include "ck/utility/data_type.hpp"
using
ck
::
f8_t
;
using
ck
::
type_convert
;
using
ck
::
f8_convert_sr
;
TEST
(
FP8
,
NumericLimits
)
{
EXPECT_EQ
(
ck
::
NumericLimits
<
f8_t
>::
Min
(),
0x08
);
EXPECT_EQ
(
ck
::
NumericLimits
<
f8_t
>::
Max
(),
0x77
);
EXPECT_EQ
(
ck
::
NumericLimits
<
f8_t
>::
Lowest
(),
0xF7
);
EXPECT_EQ
(
ck
::
NumericLimits
<
f8_t
>::
QuietNaN
(),
0x80
);
}
TEST
(
FP8
,
ConvertFP32Nearest
)
{
// fix the tolerance value
float
abs_tol
=
1e-6
;
// convert 0 float to fp8 and back, check if holds
ASSERT_NEAR
(
0.0
f
,
type_convert
<
float
>
(
type_convert
<
f8_t
>
(
0.0
f
)),
abs_tol
);
// convert minimal float to fp8 and back, check if holds
ASSERT_NEAR
(
std
::
numeric_limits
<
float
>::
min
(),
type_convert
<
float
>
(
type_convert
<
f8_t
>
(
std
::
numeric_limits
<
float
>::
min
())),
abs_tol
);
// convert maximal f8_t to float and check if equal to 240.0
ASSERT_NEAR
(
240.0
f
,
type_convert
<
float
>
(
type_convert
<
f8_t
>
(
240.0
f
)),
abs_tol
);
// convert maximal float to fp8 and back, check if clipped to 240.0
ASSERT_NEAR
(
240.0
f
,
type_convert
<
float
>
(
type_convert
<
f8_t
>
(
std
::
numeric_limits
<
float
>::
max
())),
abs_tol
);
// convert inf float to f8_t and check if it is qNan
ASSERT_NEAR
(
0x80
,
type_convert
<
f8_t
>
(
std
::
numeric_limits
<
float
>::
infinity
()),
abs_tol
);
// positive float value to fp8 and back, check if holds
float
pos_float
=
0.0078125
f
;
ASSERT_NEAR
(
pos_float
,
type_convert
<
float
>
(
type_convert
<
f8_t
>
(
pos_float
)),
abs_tol
);
// negative float value to fp8 and back, check if holds
float
neg_float
=
0.0156250
f
;
ASSERT_NEAR
(
neg_float
,
type_convert
<
float
>
(
type_convert
<
f8_t
>
(
neg_float
)),
abs_tol
);
}
TEST
(
FP8
,
ConvertFP32Stochastic
)
{
// fix the tolerance value
float
abs_tol
=
1e-6
;
// convert 0 float to fp8 and back, check if holds
ASSERT_NEAR
(
0.0
f
,
type_convert
<
float
>
(
f8_convert_sr
<
f8_t
>
(
0.0
f
)),
abs_tol
);
// convert minimal float to fp8 and back, check if holds
ASSERT_NEAR
(
std
::
numeric_limits
<
float
>::
min
(),
type_convert
<
float
>
(
f8_convert_sr
<
f8_t
>
(
std
::
numeric_limits
<
float
>::
min
())),
abs_tol
);
// convert maximal f8_t to float and check if equal to 240.0
ASSERT_NEAR
(
240.0
f
,
type_convert
<
float
>
(
f8_convert_sr
<
f8_t
>
(
240.0
f
)),
abs_tol
);
// convert maximal float to fp8 and back, check if clipped to 240.0
ASSERT_NEAR
(
240.0
f
,
type_convert
<
float
>
(
f8_convert_sr
<
f8_t
>
(
std
::
numeric_limits
<
float
>::
max
())),
abs_tol
);
// convert inf float to f8_t and check if it is qNan
ASSERT_NEAR
(
0x80
,
f8_convert_sr
<
f8_t
>
(
std
::
numeric_limits
<
float
>::
infinity
()),
abs_tol
);
// positive float value to fp8 and back, check if holds
float
pos_float
=
0.0078125
f
;
ASSERT_NEAR
(
pos_float
,
type_convert
<
float
>
(
f8_convert_sr
<
f8_t
>
(
pos_float
)),
abs_tol
);
// negative float value to fp8 and back, check if holds
float
neg_float
=
0.0156250
f
;
ASSERT_NEAR
(
neg_float
,
type_convert
<
float
>
(
f8_convert_sr
<
f8_t
>
(
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