|
8 | 8 | #endif
|
9 | 9 | #include <cmath>
|
10 | 10 |
|
11 |
| -#include <sycl/sycl.hpp> |
12 |
| - |
13 |
| -#define TEST(FUNC, MARRAY_ELEM_TYPE, DIM, EXPECTED, DELTA, ...) \ |
14 |
| - { \ |
15 |
| - { \ |
16 |
| - MARRAY_ELEM_TYPE result[DIM]; \ |
17 |
| - { \ |
18 |
| - sycl::buffer<MARRAY_ELEM_TYPE> b(result, sycl::range{DIM}); \ |
19 |
| - deviceQueue.submit([&](sycl::handler &cgh) { \ |
20 |
| - sycl::accessor res_access{b, cgh}; \ |
21 |
| - cgh.single_task([=]() { \ |
22 |
| - sycl::marray<MARRAY_ELEM_TYPE, DIM> res = FUNC(__VA_ARGS__); \ |
23 |
| - for (int i = 0; i < DIM; i++) \ |
24 |
| - res_access[i] = res[i]; \ |
25 |
| - }); \ |
26 |
| - }); \ |
27 |
| - } \ |
28 |
| - for (int i = 0; i < DIM; i++) \ |
29 |
| - assert(abs(result[i] - EXPECTED[i]) <= DELTA); \ |
30 |
| - } \ |
31 |
| - } |
32 |
| - |
33 |
| -#define EXPECTED(TYPE, ...) ((TYPE[]){__VA_ARGS__}) |
| 11 | +#include "helpers.hpp" |
34 | 12 |
|
35 | 13 | int main() {
|
36 |
| - sycl::queue deviceQueue; |
37 |
| - sycl::device dev = deviceQueue.get_device(); |
| 14 | + using namespace sycl; |
| 15 | + |
| 16 | + marray<float, 2> ma1{1.0f, 2.0f}; |
| 17 | + marray<float, 2> ma2{1.0f, 2.0f}; |
| 18 | + marray<float, 2> ma3{3.0f, 2.0f}; |
| 19 | + marray<double, 2> ma4{1.0, 2.0}; |
| 20 | + marray<float, 3> ma5{M_PI, M_PI, M_PI}; |
| 21 | + marray<double, 3> ma6{M_PI, M_PI, M_PI}; |
| 22 | + marray<half, 3> ma7{M_PI, M_PI, M_PI}; |
| 23 | + marray<float, 2> ma8{0.3f, 0.6f}; |
| 24 | + marray<double, 2> ma9{5.0, 8.0}; |
| 25 | + marray<float, 3> ma10{180, 180, 180}; |
| 26 | + marray<double, 3> ma11{180, 180, 180}; |
| 27 | + marray<half, 3> ma12{180, 180, 180}; |
| 28 | + marray<half, 3> ma13{181, 179, 181}; |
| 29 | + marray<float, 2> ma14{+0.0f, -0.6f}; |
| 30 | + marray<double, 2> ma15{-0.0, 0.6f}; |
38 | 31 |
|
39 |
| - sycl::marray<float, 2> ma1{1.0f, 2.0f}; |
40 |
| - sycl::marray<float, 2> ma2{1.0f, 2.0f}; |
41 |
| - sycl::marray<float, 2> ma3{3.0f, 2.0f}; |
42 |
| - sycl::marray<double, 2> ma4{1.0, 2.0}; |
43 |
| - sycl::marray<float, 3> ma5{M_PI, M_PI, M_PI}; |
44 |
| - sycl::marray<double, 3> ma6{M_PI, M_PI, M_PI}; |
45 |
| - sycl::marray<sycl::half, 3> ma7{M_PI, M_PI, M_PI}; |
46 |
| - sycl::marray<float, 2> ma8{0.3f, 0.6f}; |
47 |
| - sycl::marray<double, 2> ma9{5.0, 8.0}; |
48 |
| - sycl::marray<float, 3> ma10{180, 180, 180}; |
49 |
| - sycl::marray<double, 3> ma11{180, 180, 180}; |
50 |
| - sycl::marray<sycl::half, 3> ma12{180, 180, 180}; |
51 |
| - sycl::marray<sycl::half, 3> ma13{181, 179, 181}; |
52 |
| - sycl::marray<float, 2> ma14{+0.0f, -0.6f}; |
53 |
| - sycl::marray<double, 2> ma15{-0.0, 0.6f}; |
| 32 | + bool has_fp16 = queue{}.get_device().has(sycl::aspect::fp16); |
| 33 | + bool has_fp64 = queue{}.get_device().has(sycl::aspect::fp64); |
54 | 34 |
|
55 |
| - // sycl::clamp |
56 |
| - TEST(sycl::clamp, float, 2, EXPECTED(float, 1.0f, 2.0f), 0, ma1, ma2, ma3); |
57 |
| - TEST(sycl::clamp, float, 2, EXPECTED(float, 1.0f, 2.0f), 0, ma1, 1.0f, 3.0f); |
58 |
| - if (dev.has(sycl::aspect::fp64)) |
59 |
| - TEST(sycl::clamp, double, 2, EXPECTED(double, 1.0, 2.0), 0, ma4, 1.0, 3.0); |
60 |
| - // sycl::degrees |
61 |
| - TEST(sycl::degrees, float, 3, EXPECTED(float, 180, 180, 180), 0, ma5); |
62 |
| - if (dev.has(sycl::aspect::fp64)) |
63 |
| - TEST(sycl::degrees, double, 3, EXPECTED(double, 180, 180, 180), 0, ma6); |
64 |
| - if (dev.has(sycl::aspect::fp16)) |
65 |
| - TEST(sycl::degrees, sycl::half, 3, EXPECTED(sycl::half, 180, 180, 180), 0.2, |
66 |
| - ma7); |
67 |
| - // sycl::max |
68 |
| - TEST(sycl::max, float, 2, EXPECTED(float, 3.0f, 2.0f), 0, ma1, ma3); |
69 |
| - TEST(sycl::max, float, 2, EXPECTED(float, 1.5f, 2.0f), 0, ma1, 1.5f); |
70 |
| - if (dev.has(sycl::aspect::fp64)) |
71 |
| - TEST(sycl::max, double, 2, EXPECTED(double, 1.5, 2.0), 0, ma4, 1.5); |
72 |
| - // sycl::min |
73 |
| - TEST(sycl::min, float, 2, EXPECTED(float, 1.0f, 2.0f), 0, ma1, ma3); |
74 |
| - TEST(sycl::min, float, 2, EXPECTED(float, 1.0f, 1.5f), 0, ma1, 1.5f); |
75 |
| - if (dev.has(sycl::aspect::fp64)) |
76 |
| - TEST(sycl::min, double, 2, EXPECTED(double, 1.0, 1.5), 0, ma4, 1.5); |
77 |
| - // sycl::mix |
78 |
| - TEST(sycl::mix, float, 2, EXPECTED(float, 1.6f, 2.0f), 0, ma1, ma3, ma8); |
79 |
| - TEST(sycl::mix, float, 2, EXPECTED(float, 1.4f, 2.0f), 0, ma1, ma3, 0.2); |
80 |
| - if (dev.has(sycl::aspect::fp64)) |
81 |
| - TEST(sycl::mix, double, 2, EXPECTED(double, 3.0, 5.0), 0, ma4, ma9, 0.5); |
82 |
| - // sycl::radians |
83 |
| - TEST(sycl::radians, float, 3, EXPECTED(float, M_PI, M_PI, M_PI), 0, ma10); |
84 |
| - if (dev.has(sycl::aspect::fp64)) |
85 |
| - TEST(sycl::radians, double, 3, EXPECTED(double, M_PI, M_PI, M_PI), 0, ma11); |
86 |
| - if (dev.has(sycl::aspect::fp16)) |
87 |
| - TEST(sycl::radians, sycl::half, 3, EXPECTED(sycl::half, M_PI, M_PI, M_PI), |
88 |
| - 0.002, ma12); |
89 |
| - // sycl::step |
90 |
| - TEST(sycl::step, float, 2, EXPECTED(float, 1.0f, 1.0f), 0, ma1, ma3); |
91 |
| - if (dev.has(sycl::aspect::fp64)) |
92 |
| - TEST(sycl::step, double, 2, EXPECTED(double, 1.0, 1.0), 0, ma4, ma9); |
93 |
| - if (dev.has(sycl::aspect::fp16)) |
94 |
| - TEST(sycl::step, sycl::half, 3, EXPECTED(sycl::half, 1.0, 0.0, 1.0), 0, |
95 |
| - ma12, ma13); |
96 |
| - TEST(sycl::step, float, 2, EXPECTED(float, 1.0f, 0.0f), 0, 2.5f, ma3); |
97 |
| - if (dev.has(sycl::aspect::fp64)) |
98 |
| - TEST(sycl::step, double, 2, EXPECTED(double, 0.0f, 1.0f), 0, 6.0f, ma9); |
99 |
| - // sycl::smoothstep |
100 |
| - TEST(sycl::smoothstep, float, 2, EXPECTED(float, 1.0f, 1.0f), 0, ma8, ma1, |
101 |
| - ma2); |
102 |
| - if (dev.has(sycl::aspect::fp64)) |
103 |
| - TEST(sycl::smoothstep, double, 2, EXPECTED(double, 1.0, 1.0f), 0.00000001, |
104 |
| - ma4, ma9, ma9); |
105 |
| - if (dev.has(sycl::aspect::fp16)) |
106 |
| - TEST(sycl::smoothstep, sycl::half, 3, EXPECTED(sycl::half, 1.0, 1.0, 1.0), |
107 |
| - 0, ma7, ma12, ma13); |
108 |
| - TEST(sycl::smoothstep, float, 2, EXPECTED(float, 0.0553936f, 0.0f), 0.0000001, |
109 |
| - 2.5f, 6.0f, ma3); |
110 |
| - if (dev.has(sycl::aspect::fp64)) |
111 |
| - TEST(sycl::smoothstep, double, 2, EXPECTED(double, 0.0f, 1.0f), 0, 6.0f, |
112 |
| - 8.0f, ma9); |
| 35 | + // clamp |
| 36 | + test(F(clamp), marray<float, 2>{1.0f, 2.0f}, ma1, ma2, ma3); |
| 37 | + test(F(clamp), marray<float, 2>{1.0f, 2.0f}, ma1, 1.0f, 3.0f); |
| 38 | + test(has_fp64, F(clamp), marray<double, 2>{1.0, 2.0}, ma4, 1.0, 3.0); |
| 39 | + // degrees |
| 40 | + test(F(degrees), marray<float, 3>{180, 180, 180}, ma5); |
| 41 | + test(has_fp64, F(degrees), marray<double, 3>{180, 180, 180}, ma6); |
| 42 | + test(has_fp16, 0.2, F(degrees), marray<half, 3>{180, 180, 180}, ma7); |
| 43 | + // max |
| 44 | + test(F(max), marray<float, 2>{3.0f, 2.0f}, ma1, ma3); |
| 45 | + test(F(max), marray<float, 2>{1.5f, 2.0f}, ma1, 1.5f); |
| 46 | + test(has_fp64, F(max), marray<double, 2>{1.5, 2.0}, ma4, 1.5); |
| 47 | + // min |
| 48 | + test(F(min), marray<float, 2>{1.0f, 2.0f}, ma1, ma3); |
| 49 | + test(F(min), marray<float, 2>{1.0f, 1.5f}, ma1, 1.5f); |
| 50 | + test(has_fp64, F(min), marray<double, 2>{1.0, 1.5}, ma4, 1.5); |
| 51 | + // mix |
| 52 | + test(F(mix), marray<float, 2>{1.6f, 2.0f}, ma1, ma3, ma8); |
| 53 | + test(F(mix), marray<float, 2>{1.4f, 2.0f}, ma1, ma3, 0.2f); |
| 54 | + test(has_fp64, F(mix), marray<double, 2>{3.0, 5.0}, ma4, ma9, 0.5); |
| 55 | + // radians |
| 56 | + test(F(radians), marray<float, 3>{M_PI, M_PI, M_PI}, ma10); |
| 57 | + test(has_fp64, F(radians), marray<double, 3>{M_PI, M_PI, M_PI}, ma11); |
| 58 | + test(has_fp16, 0.002, F(radians), marray<half, 3>{M_PI, M_PI, M_PI}, ma12); |
| 59 | + // step |
| 60 | + test(F(step), marray<float, 2>{1.0f, 1.0f}, ma1, ma3); |
| 61 | + test(has_fp64, F(step), marray<double, 2>{1.0, 1.0}, ma4, ma9); |
| 62 | + test(has_fp16, F(step), marray<half, 3>{1.0, 0.0, 1.0}, ma12, ma13); |
| 63 | + test(F(step), marray<float, 2>{1.0f, 0.0f}, 2.5f, ma3); |
| 64 | + test(has_fp64, F(step), marray<double, 2>{0.0f, 1.0f}, 6.0f, ma9); |
| 65 | + // smoothstep |
| 66 | + test(F(smoothstep), marray<float, 2>{1.0f, 1.0f}, ma8, ma1, ma2); |
| 67 | + test(has_fp64, 0.00000001, F(smoothstep), marray<double, 2>{1.0, 1.0f}, ma4, |
| 68 | + ma9, ma9); |
| 69 | + test(has_fp16, F(smoothstep), marray<half, 3>{1.0, 1.0, 1.0}, ma7, ma12, |
| 70 | + ma13); |
| 71 | + test(0.0000001, F(smoothstep), marray<float, 2>{0.0553936f, 0.0f}, 2.5f, 6.0f, |
| 72 | + ma3); |
| 73 | + test(has_fp64, F(smoothstep), marray<double, 2>{0.0f, 1.0f}, 6.0f, 8.0f, ma9); |
113 | 74 | // sign
|
114 |
| - TEST(sycl::sign, float, 2, EXPECTED(float, +0.0f, -1.0f), 0, ma14); |
115 |
| - if (dev.has(sycl::aspect::fp64)) |
116 |
| - TEST(sycl::sign, double, 2, EXPECTED(double, -0.0, 1.0), 0, ma15); |
117 |
| - if (dev.has(sycl::aspect::fp16)) |
118 |
| - TEST(sycl::sign, sycl::half, 3, EXPECTED(sycl::half, 1.0, 1.0, 1.0), 0, |
119 |
| - ma12); |
| 75 | + test(F(sign), marray<float, 2>{+0.0f, -1.0f}, ma14); |
| 76 | + test(has_fp64, F(sign), marray<double, 2>{-0.0, 1.0}, ma15); |
| 77 | + test(has_fp16, F(sign), marray<half, 3>{1.0, 1.0, 1.0}, ma12); |
120 | 78 |
|
121 | 79 | return 0;
|
122 | 80 | }
|
0 commit comments