Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 6a8d13d

Browse files
[ESIMD] Enable math functions: cos,sin,exp,log (#312)
* [ESIMD] Enable math functions: cos,sin,exp,log
1 parent 56d12a2 commit 6a8d13d

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

SYCL/ESIMD/ext_math.cpp

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
// UNSUPPORTED: cuda
1010
// RUN: %clangxx -fsycl %s -o %t.out
1111
// RUN: %GPU_RUN_PLACEHOLDER %t.out
12+
// Enable when driver fixes will be propagated into the official release
13+
// XFAIL: windows
1214

1315
// This test checks extended math operations.
1416

1517
#include "esimd_test_utils.hpp"
1618

1719
#include <CL/sycl.hpp>
1820
#include <CL/sycl/INTEL/esimd.hpp>
21+
#include <CL/sycl/builtins_esimd.hpp>
1922
#include <iostream>
2023

2124
using namespace cl::sycl;
@@ -35,7 +38,16 @@ struct InitDataFuncWide {
3538
struct InitDataFuncNarrow {
3639
void operator()(float *In, float *Out, size_t Size) const {
3740
for (auto I = 0; I < Size; ++I) {
38-
In[I] = 2.0f + 16.0f * ((float)I / (float)(Size - 1)); // in [2..16] range
41+
In[I] = 2.0f + 16.0f * ((float)I / (float)(Size - 1)); // in [2..18] range
42+
Out[I] = (float)0.0;
43+
}
44+
}
45+
};
46+
47+
struct InitDataInRange0_5 {
48+
void operator()(float *In, float *Out, size_t Size) const {
49+
for (auto I = 0; I < Size; ++I) {
50+
In[I] = 5.0f * ((float)I / (float)(Size - 1)); // in [0..5] range
3951
Out[I] = (float)0.0;
4052
}
4153
}
@@ -52,7 +64,7 @@ template <MathOp Op> float HostMathFunc(float X);
5264

5365
// --- Specializations per each extended math operation
5466

55-
#define DEFINE_OP(Op, HostOp) \
67+
#define DEFINE_ESIMD_OP(Op, HostOp) \
5668
template <> float HostMathFunc<MathOp::Op>(float X) { return HostOp(X); } \
5769
template <int VL> struct DeviceMathFunc<VL, MathOp::Op> { \
5870
simd<float, VL> \
@@ -61,13 +73,22 @@ template <MathOp Op> float HostMathFunc(float X);
6173
} \
6274
}
6375

64-
DEFINE_OP(sin, sin);
65-
DEFINE_OP(cos, cos);
66-
DEFINE_OP(exp, exp);
67-
DEFINE_OP(log, log);
68-
DEFINE_OP(inv, 1.0f /);
69-
DEFINE_OP(sqrt, sqrt);
70-
DEFINE_OP(rsqrt, 1.0f / sqrt);
76+
#define DEFINE_SIMD_OVERLOADED_STD_SYCL_OP(Op, HostOp) \
77+
template <> float HostMathFunc<MathOp::Op>(float X) { return HostOp(X); } \
78+
template <int VL> struct DeviceMathFunc<VL, MathOp::Op> { \
79+
simd<float, VL> \
80+
operator()(const simd<float, VL> &X) const SYCL_ESIMD_FUNCTION { \
81+
return sycl::Op<VL>(X); \
82+
} \
83+
}
84+
85+
DEFINE_SIMD_OVERLOADED_STD_SYCL_OP(sin, sin);
86+
DEFINE_SIMD_OVERLOADED_STD_SYCL_OP(cos, cos);
87+
DEFINE_SIMD_OVERLOADED_STD_SYCL_OP(exp, exp);
88+
DEFINE_SIMD_OVERLOADED_STD_SYCL_OP(log, log);
89+
DEFINE_ESIMD_OP(inv, 1.0f /);
90+
DEFINE_ESIMD_OP(sqrt, sqrt);
91+
DEFINE_ESIMD_OP(rsqrt, 1.0f / sqrt);
7192

7293
// --- Generic kernel calculating an extended math operation on array elements
7394

@@ -159,13 +180,10 @@ template <int VL> bool test(queue &Q) {
159180
Pass &= test<MathOp::sqrt, VL>(Q, "sqrt", InitDataFuncWide{});
160181
Pass &= test<MathOp::inv, VL>(Q, "inv");
161182
Pass &= test<MathOp::rsqrt, VL>(Q, "rsqrt");
162-
// TODO enable these tests after the implementation is fixed
163-
#if ENABLE_SIN_COS_EXP_LOG
164183
Pass &= test<MathOp::sin, VL>(Q, "sin", InitDataFuncWide{});
165184
Pass &= test<MathOp::cos, VL>(Q, "cos", InitDataFuncWide{});
166-
Pass &= test<MathOp::exp, VL>(Q, "exp");
185+
Pass &= test<MathOp::exp, VL>(Q, "exp", InitDataInRange0_5{});
167186
Pass &= test<MathOp::log, VL>(Q, "log", InitDataFuncWide{});
168-
#endif
169187
return Pass;
170188
}
171189

0 commit comments

Comments
 (0)