Skip to content

Commit 770c8ab

Browse files
authored
[SYCL][CUDA] Add ftz test (intel#1440)
1 parent 2942225 commit 770c8ab

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -Xclang -fdenormal-fp-math-f32="preserve-sign,preserve-sign" %s -o %t.out
2+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
3+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
6+
#include <cassert>
7+
#include <sycl/sycl.hpp>
8+
#include <type_traits>
9+
10+
using namespace sycl;
11+
12+
constexpr float eps = 1e-6;
13+
14+
template <typename T> bool checkClose(T A, T B) { return ((A - B) / A) < eps; }
15+
16+
#define __TEST_FFMATH_UNARY(func) \
17+
template <typename T> void test_ffmath_##func(queue &deviceQueue) { \
18+
T input[4] = {1.0004f, 1e-4f, 1.4f, 14.0f}; \
19+
T res[4] = {-1, -1, -1, -1}; \
20+
{ \
21+
buffer<T> input_buff{input, sycl::range{4}}; \
22+
buffer<T> res_buff{res, sycl::range{4}}; \
23+
deviceQueue.submit([&](handler &cgh) { \
24+
accessor res_acc{res_buff, cgh}; \
25+
accessor input_acc{input_buff, cgh}; \
26+
cgh.parallel_for(sycl::range{4}, [=](sycl::id<1> idx) { \
27+
res_acc[idx] = sycl::func(input_acc[idx]); \
28+
}); \
29+
}); \
30+
} \
31+
for (auto i = 0; i < 4; ++i) \
32+
assert(checkClose(res[i], sycl::func(input[i]))); \
33+
}
34+
35+
#define __TEST_FFMATH_BINARY(func) \
36+
template <typename T> void test_ffmath_##func(queue &deviceQueue) { \
37+
T input[2][4] = {{1.0004f, 1e-4f, 1.4f, 14.0f}, \
38+
{1.0004f, 1e-4f, 1.4f, 14.0f}}; \
39+
T res[4] = {-1, -1, -1, -1}; \
40+
{ \
41+
buffer<T> input1_buff{input[0], sycl::range{4}}; \
42+
buffer<T> input2_buff{input[1], sycl::range{4}}; \
43+
buffer<T> res_buff{res, sycl::range{4}}; \
44+
deviceQueue.submit([&](handler &cgh) { \
45+
accessor res_acc{res_buff, cgh}; \
46+
accessor input1_acc{input1_buff, cgh}; \
47+
accessor input2_acc{input2_buff, cgh}; \
48+
cgh.parallel_for(sycl::range{4}, [=](sycl::id<1> idx) { \
49+
res_acc[idx] = sycl::func(input1_acc[idx], input2_acc[idx]); \
50+
}); \
51+
}); \
52+
} \
53+
for (auto i = 0; i < 4; ++i) \
54+
assert(checkClose(res[i], sycl::func(input[0][i], input[1][i]))); \
55+
}
56+
57+
__TEST_FFMATH_UNARY(cos)
58+
__TEST_FFMATH_UNARY(exp)
59+
__TEST_FFMATH_UNARY(exp2)
60+
__TEST_FFMATH_UNARY(exp10)
61+
__TEST_FFMATH_UNARY(log)
62+
__TEST_FFMATH_UNARY(log2)
63+
__TEST_FFMATH_UNARY(log10)
64+
__TEST_FFMATH_UNARY(rsqrt)
65+
__TEST_FFMATH_UNARY(sin)
66+
__TEST_FFMATH_UNARY(sqrt)
67+
__TEST_FFMATH_UNARY(tan)
68+
69+
__TEST_FFMATH_BINARY(powr)
70+
71+
int main() {
72+
73+
queue q;
74+
test_ffmath_cos<float>(q);
75+
test_ffmath_exp<float>(q);
76+
test_ffmath_exp2<float>(q);
77+
test_ffmath_exp10<float>(q);
78+
test_ffmath_log<float>(q);
79+
test_ffmath_log2<float>(q);
80+
test_ffmath_log10<float>(q);
81+
test_ffmath_powr<float>(q);
82+
test_ffmath_rsqrt<float>(q);
83+
test_ffmath_sin<float>(q);
84+
test_ffmath_sqrt<float>(q);
85+
test_ffmath_tan<float>(q);
86+
test_ffmath_powr<float>(q);
87+
88+
return 0;
89+
}

0 commit comments

Comments
 (0)