18# include <sycl/sycl.hpp>
22namespace alpaka::math::internal
24 template<
typename T_Arg>
25 requires(std::is_arithmetic_v<T_Arg>)
26 struct Abs::Op<SyclMath, T_Arg>
28 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
30 if constexpr(std::is_integral_v<T_Arg>)
31 return sycl::abs(arg);
32 else if constexpr(std::is_floating_point_v<T_Arg>)
33 return sycl::fabs(arg);
35 static_assert(!
sizeof(T_Arg),
"Unsupported data type");
39 template<std::
floating_po
int T_Arg>
40 struct Sin::Op<SyclMath, T_Arg>
42 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
44 return sycl::sin(arg);
48 template<std::
floating_po
int T_Arg>
49 struct Acosh::Op<SyclMath, T_Arg>
51 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
53 return sycl::acosh(arg);
57 template<std::
floating_po
int T_Arg>
58 struct Asinh::Op<SyclMath, T_Arg>
60 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
62 return sycl::asinh(arg);
66 template<std::
floating_po
int T_Arg>
67 struct Sinh::Op<SyclMath, T_Arg>
69 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
71 return sycl::sinh(arg);
75 template<std::
floating_po
int T_Arg>
76 struct Atan::Op<SyclMath, T_Arg>
78 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
80 return sycl::atan(arg);
84 template<std::
floating_po
int T_Arg>
85 struct Atanh::Op<SyclMath, T_Arg>
87 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
89 return sycl::atanh(arg);
93 template<std::
floating_po
int T_Arg>
94 struct Tanh::Op<SyclMath, T_Arg>
96 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
98 return sycl::tanh(arg);
102 template<
typename T_Arg>
103 requires(std::is_arithmetic_v<T_Arg>)
104 struct Cbrt::Op<SyclMath, T_Arg>
106 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
108 if constexpr(std::is_integral_v<T_Arg>)
109 return sycl::cbrt(
static_cast<double>(arg));
110 else if constexpr(std::is_floating_point_v<T_Arg>)
111 return sycl::cbrt(arg);
113 static_assert(!
sizeof(T_Arg),
"Unsupported data type");
117 template<std::
floating_po
int T_Arg>
118 struct Ceil::Op<SyclMath, T_Arg>
120 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
122 return sycl::ceil(arg);
126 template<std::
floating_po
int T_Arg>
127 struct Round::Op<SyclMath, T_Arg>
129 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
131 return sycl::round(arg);
135 template<std::
floating_po
int T_Arg>
136 struct Lround::Op<SyclMath, T_Arg>
138 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
140 return static_cast<long>(sycl::round(arg));
144 template<std::
floating_po
int T_Arg>
145 struct Llround::Op<SyclMath, T_Arg>
147 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
149 return static_cast<long long>(sycl::round(arg));
153 template<std::
floating_po
int T_Arg>
154 struct SinCos::Op<SyclMath, T_Arg>
156 constexpr auto operator()(SyclMath, T_Arg
const& arg, T_Arg& result_sin, T_Arg& result_cos)
const
158 result_sin = sycl::sincos(arg, &result_cos);
162 template<
typename T_Arg>
163 requires(std::is_arithmetic_v<T_Arg>)
164 struct Arg::Op<SyclMath, T_Arg>
166 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
168 if constexpr(std::is_integral_v<T_Arg>)
169 return sycl::atan2(0.0,
static_cast<double>(arg));
170 else if constexpr(std::is_floating_point_v<T_Arg>)
171 return sycl::atan2(
static_cast<T_Arg
>(0.0), arg);
173 static_assert(!
sizeof(T_Arg),
"Unsupported data type");
177 template<std::
floating_po
int T_Y, std::
floating_po
int T_X>
178 struct Atan2::Op<SyclMath, T_Y, T_X>
180 using CommonT_Bpe = std::common_type_t<T_Y, T_X>;
182 auto operator()(SyclMath, T_Y
const& y, T_X
const& x)
const
184 return sycl::atan2(
static_cast<CommonT_Bpe
>(y),
static_cast<CommonT_Bpe
>(x));
188 template<std::
floating_po
int T_Arg>
189 struct Exp::Op<SyclMath, T_Arg>
191 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
193 return sycl::exp(arg);
197 template<std::
floating_po
int T_Arg>
198 struct Sqrt::Op<SyclMath, T_Arg>
200 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
202 return sycl::sqrt(arg);
206 template<
typename T_Arg>
207 requires(std::is_arithmetic_v<T_Arg>)
208 struct Rsqrt::Op<SyclMath, T_Arg>
210 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
212 if constexpr(std::is_floating_point_v<T_Arg>)
213 return sycl::rsqrt(arg);
214 else if constexpr(std::is_integral_v<T_Arg>)
217 return sycl::rsqrt(
static_cast<double>(arg));
220 static_assert(!
sizeof(T_Arg),
"Unsupported data type");
224 template<std::
floating_po
int T_Arg>
225 struct Trunc::Op<SyclMath, T_Arg>
227 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
229 return sycl::trunc(arg);
233 template<std::
floating_po
int T_Arg>
234 struct Cos::Op<SyclMath, T_Arg>
236 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
238 return sycl::cos(arg);
242 template<std::
floating_po
int T_Arg>
243 struct Cosh::Op<SyclMath, T_Arg>
245 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
247 return sycl::cosh(arg);
251 template<std::
floating_po
int T_Arg>
252 struct Floor::Op<SyclMath, T_Arg>
254 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
256 return sycl::floor(arg);
260 template<std::
floating_po
int T_Arg>
261 struct Erf::Op<SyclMath, T_Arg>
263 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
265 return sycl::erf(arg);
269 template<std::
floating_po
int T_Arg>
270 struct Log::Op<SyclMath, T_Arg>
272 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
274 return sycl::log(arg);
278 template<std::
floating_po
int T_Arg>
279 struct Log2::Op<SyclMath, T_Arg>
281 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
283 return sycl::log2(arg);
287 template<std::
floating_po
int T_Arg>
288 struct Log10::Op<SyclMath, T_Arg>
290 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
292 return sycl::log10(arg);
296 template<std::
floating_po
int T_Arg>
297 struct Tan::Op<SyclMath, T_Arg>
299 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
301 return sycl::tan(arg);
305 template<std::
floating_po
int T_Arg>
306 struct Asin::Op<SyclMath, T_Arg>
308 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
310 return sycl::asin(arg);
314 template<std::
floating_po
int T_Arg>
315 struct Acos::Op<SyclMath, T_Arg>
317 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
319 return sycl::acos(arg);
324 template<std::
floating_po
int T_Arg>
325 struct Isnan::Op<SyclMath, T_Arg>
327 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
329 return ieeeIsnan(arg);
333 template<std::
floating_po
int T_Arg>
334 struct Isinf::Op<SyclMath, T_Arg>
336 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
338 return ieeeIsinf(arg);
342 template<std::
floating_po
int T_Arg>
343 struct Isfinite::Op<SyclMath, T_Arg>
345 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
347 return ieeeIsfinite(arg);
351 template<std::
floating_po
int T_Arg>
352 struct Conj::Op<SyclMath, T_Arg>
354 constexpr auto operator()(SyclMath, T_Arg
const& arg)
const
356 return Complex<T_Arg>{
arg, T_Arg{0.0}};
360 template<std::
floating_po
int TMag, std::
floating_po
int TSgn>
361 struct Copysign::Op<SyclMath, TMag, TSgn>
363 using TCommon = std::common_type_t<TMag, TSgn>;
365 constexpr auto operator()(SyclMath, TMag
const& mag, TSgn
const& sgn)
const
367 return sycl::copysign(
static_cast<TCommon
>(mag),
static_cast<TCommon
>(sgn));
371 template<
typename T_A,
typename T_B>
372 requires(std::is_arithmetic_v<T_A> && std::is_arithmetic_v<T_B>)
373 struct Min::Op<SyclMath, T_A, T_B>
375 constexpr auto operator()(SyclMath, T_A
const& a, T_B
const& b)
const
377 if constexpr(std::is_integral_v<T_A> && std::is_integral_v<T_B>)
378 return sycl::min(a, b);
379 else if constexpr(std::is_floating_point_v<T_A> || std::is_floating_point_v<T_B>)
380 return sycl::fmin(a, b);
382 (std::is_floating_point_v<T_A> && std::is_integral_v<T_B>)
383 || (std::is_integral_v<T_A> && std::is_floating_point_v<T_B>) )
384 return sycl::fmin(
static_cast<double>(a),
static_cast<double>(b));
386 static_assert(!
sizeof(T_A),
"Unsupported data types");
390 template<
typename T_A,
typename T_B>
391 requires(std::is_arithmetic_v<T_A> && std::is_arithmetic_v<T_B>)
392 struct Max::Op<SyclMath, T_A, T_B>
394 constexpr auto operator()(SyclMath, T_A
const& a, T_B
const& b)
const
396 if constexpr(std::is_integral_v<T_A> && std::is_integral_v<T_B>)
397 return sycl::max(a, b);
398 else if constexpr(std::is_floating_point_v<T_A> || std::is_floating_point_v<T_B>)
399 return sycl::fmax(a, b);
401 (std::is_floating_point_v<T_A> && std::is_integral_v<T_B>)
402 || (std::is_integral_v<T_A> && std::is_floating_point_v<T_B>) )
403 return sycl::fmax(
static_cast<double>(a),
static_cast<double>(b));
405 static_assert(!
sizeof(T_A),
"Unsupported data types");
409 template<std::
floating_po
int T_Base, std::
floating_po
int T_Exp>
410 struct Pow::Op<SyclMath, T_Base, T_Exp>
412 using TCommon = std::common_type_t<T_Base, T_Exp>;
414 constexpr auto operator()(SyclMath, T_Base
const& base, T_Exp
const& exp)
const
416 return sycl::pow(
static_cast<TCommon
>(base),
static_cast<TCommon
>(exp));
420 template<std::
floating_po
int T_X, std::
floating_po
int T_Y>
421 struct Fmod::Op<SyclMath, T_X, T_Y>
423 using TCommon = std::common_type_t<T_X, T_Y>;
425 constexpr auto operator()(SyclMath, T_X
const& x, T_Y
const& y)
const
427 return sycl::fmod(
static_cast<TCommon
>(x),
static_cast<TCommon
>(y));
431 template<std::
floating_po
int T_X, std::
floating_po
int T_Y>
432 struct Remainder::Op<SyclMath, T_X, T_Y>
434 using TCommon = std::common_type_t<T_X, T_Y>;
436 constexpr auto operator()(SyclMath, T_X
const& x, T_Y
const& y)
const
438 return sycl::remainder(
static_cast<TCommon
>(x),
static_cast<TCommon
>(y));
442 template<std::
floating_po
int T_X, std::
floating_po
int T_Y, std::
floating_po
int T_Z>
443 struct Fma::Op<SyclMath, T_X, T_Y, T_Z>
445 constexpr auto operator()(SyclMath, T_X
const& x, T_Y
const& y, T_Z
const& z)
const
447 return sycl::fma(x, y, z);
constexpr auto arg(auto const &arg)