diff --git a/SYCL/ESIMD/ext_math.cpp b/SYCL/ESIMD/ext_math.cpp index b90a4901ad..da0985e0e6 100644 --- a/SYCL/ESIMD/ext_math.cpp +++ b/SYCL/ESIMD/ext_math.cpp @@ -53,7 +53,7 @@ struct InitDataInRange0_5 { // --- Math operation identification -enum class MathOp { sin, cos, exp, sqrt, inv, log, rsqrt }; +enum class MathOp { sin, cos, exp, sqrt, inv, log, rsqrt, trunc }; // --- Template functions calculating given math operation on host and device @@ -71,6 +71,16 @@ template float HostMathFunc(float X); } \ } +// The same as above but adds explicit template parameter for esimd_##Op. +#define DEFINE_ESIMD_RT_OP(Op, HostOp) \ + template <> float HostMathFunc(float X) { return HostOp(X); } \ + template struct DeviceMathFunc { \ + simd \ + operator()(const simd &X) const SYCL_ESIMD_FUNCTION { \ + return esimd_##Op(X); \ + } \ + } + #define DEFINE_SIMD_OVERLOADED_STD_SYCL_OP(Op, HostOp) \ template <> float HostMathFunc(float X) { return HostOp(X); } \ template struct DeviceMathFunc { \ @@ -87,6 +97,7 @@ DEFINE_SIMD_OVERLOADED_STD_SYCL_OP(log, log); DEFINE_ESIMD_OP(inv, 1.0f /); DEFINE_ESIMD_OP(sqrt, sqrt); DEFINE_ESIMD_OP(rsqrt, 1.0f / sqrt); +DEFINE_ESIMD_RT_OP(trunc, trunc); // --- Generic kernel calculating an extended math operation on array elements @@ -182,6 +193,7 @@ template bool test(queue &Q) { Pass &= test(Q, "cos", InitDataFuncWide{}); Pass &= test(Q, "exp", InitDataInRange0_5{}); Pass &= test(Q, "log", InitDataFuncWide{}); + Pass &= test(Q, "trunc", InitDataFuncWide{}); return Pass; }