5#include "testing/testing.h"
17TEST(math_half, half_to_float_scalar)
44TEST(math_half, float_to_half_scalar)
46#define HFUN(v) math::float_to_half(v)
66 EXPECT_EQ(
HFUN(std::numeric_limits<float>::infinity()), 31744);
68 EXPECT_EQ(
HFUN(std::numeric_limits<float>::quiet_NaN()), 32256);
78 EXPECT_EQ(
HFUN(-std::numeric_limits<float>::infinity()), 64512);
82TEST(math_half, float_to_half_make_finite_scalar)
84#define HFUN(v) math::float_to_half_make_finite(v)
105 EXPECT_EQ(
HFUN(std::numeric_limits<float>::infinity()), 31743);
109 EXPECT_EQ(
HFUN(std::numeric_limits<float>::signaling_NaN()), 0);
120 EXPECT_EQ(
HFUN(-std::numeric_limits<float>::infinity()), 64511);
122 EXPECT_EQ(
HFUN(-std::numeric_limits<float>::quiet_NaN()), 32768);
123 EXPECT_EQ(
HFUN(-std::numeric_limits<float>::signaling_NaN()), 32768);
127TEST(math_half, half_to_float_array)
130 0, 1, 6789, 16383, 16384, 31743, 31744, 32768, 32769, 46765, 54501, 64511, 64512};
132 const float exp[14] = {
139 std::numeric_limits<float>::infinity(),
145 -std::numeric_limits<float>::infinity(),
152 EXPECT_EQ_ARRAY(
exp, dst, 14);
155TEST(math_half, half_to_float_array_flush_to_zero)
159 const uint16_t src[8] = {0, 1, 32, 511, 1023, 1024, 32769, 33791};
160 const float exp[8] = {
177 EXPECT_EQ_ARRAY(
exp, dst, 8);
180TEST(math_half, float_to_half_array)
182 const float src[13] = {0.0f,
188 std::numeric_limits<float>::infinity(),
194 -std::numeric_limits<float>::infinity()};
197 0, 1, 6789, 16383, 16384, 31743, 31744, 32768, 32769, 46765, 54501, 64511, 64512, 12345};
202 EXPECT_EQ_ARRAY(
exp, dst, 14);
205TEST(math_half, float_to_half_clamp_array)
207 const float src[17] = {
214 std::numeric_limits<float>::infinity(),
220 -std::numeric_limits<float>::infinity(),
223 std::numeric_limits<float>::quiet_NaN(),
224 -std::numeric_limits<float>::quiet_NaN(),
248 EXPECT_EQ_ARRAY(
exp, dst, 18);
251TEST(math_half, float_to_half_make_finite_array)
253 const float src[17] = {
260 std::numeric_limits<float>::infinity(),
266 -std::numeric_limits<float>::infinity(),
269 std::numeric_limits<float>::quiet_NaN(),
270 -std::numeric_limits<float>::quiet_NaN(),
294 EXPECT_EQ_ARRAY(
exp, dst, 18);
312TEST(math_half_perf, half_to_float_scalar)
316 for (
int i = 0; i < 100'000'000; i++) {
319 memcpy(&fu, &f,
sizeof(f));
323 printf(
"- FP16->FP32 scalar: %.3fs sum %zu\n", t1 - t0, sum);
326TEST(math_half_perf, half_to_float_array)
328 const int test_size = 100'000'000;
330 float *dst =
new float[test_size];
331 for (
int i = 0; i < test_size; i++) {
337 for (
int i = 0; i < test_size; i++) {
339 memcpy(&fu, &dst[i],
sizeof(fu));
343 printf(
"- FP16->FP32 array : %.3fs sum %zu\n", t1 - t0, sum);
361TEST(math_half_perf, float_to_half_scalar)
365 for (
int i = 0; i < 100'000'000; i++) {
366 float f = ((i & 0xFFFF) - 0x8000) + 0.1f;
371 printf(
"- FP32->FP16 scalar: %.3fs sum %u\n", t1 - t0, sum);
374TEST(math_half_perf, float_to_half_array)
376 const int test_size = 100'000'000;
377 float *src =
new float[test_size];
379 for (
int i = 0; i < test_size; i++) {
380 src[i] = ((i & 0xFFFF) - 0x8000) + 0.1f;
386 for (
int i = 0; i < test_size; i++) {
390 printf(
"- FP32->FP16 array : %.3fs sum %u\n", t1 - t0, sum);
395TEST(math_half_perf, float_to_half_make_finite_array)
397 const int test_size = 100'000'000;
398 float *src =
new float[test_size];
400 for (
int i = 0; i < test_size; i++) {
401 src[i] = ((i & 0xFFFF) - 0x8000) + 0.1f;
406 for (
int i = 0; i < test_size; i++) {
410 printf(
"- FP32->FP16 finite array : %.3fs sum %u\n", t1 - t0, sum);
Platform independent time functions.
#define EXPECT_TRUE(result)
void float_to_half_array(const float *src, uint16_t *dst, size_t length)
uint16_t float_to_half(float v)
void float_to_half_clamp_array(const float *src, uint16_t *dst, size_t length, float min_value, float max_value)
void half_to_float_array(const uint16_t *src, float *dst, size_t length)
void float_to_half_make_finite_array(const float *src, uint16_t *dst, size_t length)
float half_to_float(uint16_t v)
TEST(any_virtual, DefaultConstructor)
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
double BLI_time_now_seconds()