16
16
17
17
#include < CL/sycl.hpp>
18
18
#include < CL/sycl/INTEL/esimd.hpp>
19
+ #include < CL/sycl/builtins_esimd.hpp>
19
20
#include < iostream>
20
21
21
22
using namespace cl ::sycl;
@@ -35,7 +36,16 @@ struct InitDataFuncWide {
35
36
struct InitDataFuncNarrow {
36
37
void operator ()(float *In, float *Out, size_t Size) const {
37
38
for (auto I = 0 ; I < Size; ++I) {
38
- In[I] = 2 .0f + 16 .0f * ((float )I / (float )(Size - 1 )); // in [2..16] range
39
+ In[I] = 2 .0f + 16 .0f * ((float )I / (float )(Size - 1 )); // in [2..18] range
40
+ Out[I] = (float )0.0 ;
41
+ }
42
+ }
43
+ };
44
+
45
+ struct InitDataInRange0_5 {
46
+ void operator ()(float *In, float *Out, size_t Size) const {
47
+ for (auto I = 0 ; I < Size; ++I) {
48
+ In[I] = 5 .0f * ((float )I / (float )(Size - 1 )); // in [0..5] range
39
49
Out[I] = (float )0.0 ;
40
50
}
41
51
}
@@ -61,10 +71,19 @@ template <MathOp Op> float HostMathFunc(float X);
61
71
} \
62
72
}
63
73
64
- DEFINE_OP (sin, sin);
65
- DEFINE_OP (cos, cos);
66
- DEFINE_OP (exp, exp);
67
- DEFINE_OP (log, log);
74
+ #define DEFINE_OP_REUSE_SCALAR (Op, HostOp ) \
75
+ template <> float HostMathFunc<MathOp::Op>(float X) { return HostOp (X); } \
76
+ template <int VL> struct DeviceMathFunc <VL, MathOp::Op> { \
77
+ simd<float , VL> \
78
+ operator ()(const simd<float , VL> &X) const SYCL_ESIMD_FUNCTION { \
79
+ return sycl::Op<VL>(X); \
80
+ } \
81
+ }
82
+
83
+ DEFINE_OP_REUSE_SCALAR (sin, sin);
84
+ DEFINE_OP_REUSE_SCALAR (cos, cos);
85
+ DEFINE_OP_REUSE_SCALAR (exp, exp);
86
+ DEFINE_OP_REUSE_SCALAR (log, log);
68
87
DEFINE_OP (inv, 1 .0f /);
69
88
DEFINE_OP (sqrt, sqrt);
70
89
DEFINE_OP (rsqrt, 1 .0f / sqrt);
@@ -159,13 +178,10 @@ template <int VL> bool test(queue &Q) {
159
178
Pass &= test<MathOp::sqrt, VL>(Q, " sqrt" , InitDataFuncWide{});
160
179
Pass &= test<MathOp::inv, VL>(Q, " inv" );
161
180
Pass &= test<MathOp::rsqrt, VL>(Q, " rsqrt" );
162
- // TODO enable these tests after the implementation is fixed
163
- #if ENABLE_SIN_COS_EXP_LOG
164
181
Pass &= test<MathOp::sin, VL>(Q, " sin" , InitDataFuncWide{});
165
182
Pass &= test<MathOp::cos, VL>(Q, " cos" , InitDataFuncWide{});
166
- Pass &= test<MathOp::exp, VL>(Q, " exp" );
183
+ Pass &= test<MathOp::exp, VL>(Q, " exp" , InitDataInRange0_5{} );
167
184
Pass &= test<MathOp::log, VL>(Q, " log" , InitDataFuncWide{});
168
- #endif
169
185
return Pass;
170
186
}
171
187
0 commit comments