Commit d3c89355 authored by Rostyslav Geyyer's avatar Rostyslav Geyyer
Browse files

Add conversion tests

parent cf7e20a8
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ck/utility/data_type.hpp" #include "ck/utility/data_type.hpp"
#include "ck/utility/type_convert.hpp" #include "ck/utility/type_convert.hpp"
using ck::f4_convert_rne;
using ck::f4_t; using ck::f4_t;
using ck::type_convert; using ck::type_convert;
...@@ -17,3 +18,29 @@ TEST(FP8, NumericLimits) ...@@ -17,3 +18,29 @@ TEST(FP8, NumericLimits)
EXPECT_EQ(ck::NumericLimits<f4_t>::MinSubnorm(), f4_t{0x1}); EXPECT_EQ(ck::NumericLimits<f4_t>::MinSubnorm(), f4_t{0x1});
EXPECT_EQ(ck::NumericLimits<f4_t>::MaxSubnorm(), 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.0f;
// convert 0 float to fp4 and back, check if holds
ASSERT_NEAR(0.0f, type_convert<float>(f4_convert_rne(0.0f)), 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.0f;
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.5f;
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.5f;
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.5f;
ASSERT_NEAR(neg_float, type_convert<float>(f4_convert_rne(neg_float)), abs_tol);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment