alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
MathUniformCudaHipBuiltIn.hpp
Go to the documentation of this file.
1/* Copyright 2024 Axel Huebl, Benjamin Worpitz, Matthias Werner, Bert Wesarg, Valentin Gehrke, René Widera,
2 * Jan Stephan, Andrea Bocci, Bernhard Manfred Gruber, Jeffrey Kelling, Sergei Bastrakov
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
6#pragma once
7
10#include "alpaka/core/Decay.hpp"
16
17#include <type_traits>
18
19#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) || defined(ALPAKA_ACC_GPU_HIP_ENABLED)
20
21namespace alpaka::math
22{
23 //! The CUDA built in abs.
24 class AbsUniformCudaHipBuiltIn : public interface::Implements<ConceptMathAbs, AbsUniformCudaHipBuiltIn>
25 {
26 };
27
28 //! The CUDA built in acos.
29 class AcosUniformCudaHipBuiltIn : public interface::Implements<ConceptMathAcos, AcosUniformCudaHipBuiltIn>
30 {
31 };
32
33 //! The CUDA built in acosh.
34 class AcoshUniformCudaHipBuiltIn : public interface::Implements<ConceptMathAcosh, AcoshUniformCudaHipBuiltIn>
35 {
36 };
37
38 //! The CUDA built in arg.
39 class ArgUniformCudaHipBuiltIn : public interface::Implements<ConceptMathArg, ArgUniformCudaHipBuiltIn>
40 {
41 };
42
43 //! The CUDA built in asin.
44 class AsinUniformCudaHipBuiltIn : public interface::Implements<ConceptMathAsin, AsinUniformCudaHipBuiltIn>
45 {
46 };
47
48 //! The CUDA built in asinh.
49 class AsinhUniformCudaHipBuiltIn : public interface::Implements<ConceptMathAsinh, AsinhUniformCudaHipBuiltIn>
50 {
51 };
52
53 //! The CUDA built in atan.
54 class AtanUniformCudaHipBuiltIn : public interface::Implements<ConceptMathAtan, AtanUniformCudaHipBuiltIn>
55 {
56 };
57
58 //! The CUDA built in atanh.
59 class AtanhUniformCudaHipBuiltIn : public interface::Implements<ConceptMathAtanh, AtanhUniformCudaHipBuiltIn>
60 {
61 };
62
63 //! The CUDA built in atan2.
64 class Atan2UniformCudaHipBuiltIn : public interface::Implements<ConceptMathAtan2, Atan2UniformCudaHipBuiltIn>
65 {
66 };
67
68 //! The CUDA built in cbrt.
69 class CbrtUniformCudaHipBuiltIn : public interface::Implements<ConceptMathCbrt, CbrtUniformCudaHipBuiltIn>
70 {
71 };
72
73 //! The CUDA built in ceil.
74 class CeilUniformCudaHipBuiltIn : public interface::Implements<ConceptMathCeil, CeilUniformCudaHipBuiltIn>
75 {
76 };
77
78 //! The CUDA built in conj.
79 class ConjUniformCudaHipBuiltIn : public interface::Implements<ConceptMathConj, ConjUniformCudaHipBuiltIn>
80 {
81 };
82
83 //! The CUDA built in copysign.
85 : public interface::Implements<ConceptMathCopysign, CopysignUniformCudaHipBuiltIn>
86 {
87 };
88
89 //! The CUDA built in cos.
90 class CosUniformCudaHipBuiltIn : public interface::Implements<ConceptMathCos, CosUniformCudaHipBuiltIn>
91 {
92 };
93
94 //! The CUDA built in cosh.
95 class CoshUniformCudaHipBuiltIn : public interface::Implements<ConceptMathCosh, CoshUniformCudaHipBuiltIn>
96 {
97 };
98
99 //! The CUDA built in erf.
100 class ErfUniformCudaHipBuiltIn : public interface::Implements<ConceptMathErf, ErfUniformCudaHipBuiltIn>
101 {
102 };
103
104 //! The CUDA built in exp.
105 class ExpUniformCudaHipBuiltIn : public interface::Implements<ConceptMathExp, ExpUniformCudaHipBuiltIn>
106 {
107 };
108
109 //! The CUDA built in floor.
110 class FloorUniformCudaHipBuiltIn : public interface::Implements<ConceptMathFloor, FloorUniformCudaHipBuiltIn>
111 {
112 };
113
114 //! The CUDA built in fma.
115 class FmaUniformCudaHipBuiltIn : public interface::Implements<ConceptMathFma, FmaUniformCudaHipBuiltIn>
116 {
117 };
118
119 //! The CUDA built in fmod.
120 class FmodUniformCudaHipBuiltIn : public interface::Implements<ConceptMathFmod, FmodUniformCudaHipBuiltIn>
121 {
122 };
123
124 //! The CUDA built in isfinite.
126 : public interface::Implements<ConceptMathIsfinite, IsfiniteUniformCudaHipBuiltIn>
127 {
128 };
129
130 //! The CUDA built in isinf.
131 class IsinfUniformCudaHipBuiltIn : public interface::Implements<ConceptMathIsinf, IsinfUniformCudaHipBuiltIn>
132 {
133 };
134
135 //! The CUDA built in isnan.
136 class IsnanUniformCudaHipBuiltIn : public interface::Implements<ConceptMathIsnan, IsnanUniformCudaHipBuiltIn>
137 {
138 };
139
140 // ! The CUDA built in log.
141 class LogUniformCudaHipBuiltIn : public interface::Implements<ConceptMathLog, LogUniformCudaHipBuiltIn>
142 {
143 };
144
145 // ! The CUDA built in log2.
146 class Log2UniformCudaHipBuiltIn : public interface::Implements<ConceptMathLog2, Log2UniformCudaHipBuiltIn>
147 {
148 };
149
150 // ! The CUDA built in log10.
151 class Log10UniformCudaHipBuiltIn : public interface::Implements<ConceptMathLog10, Log10UniformCudaHipBuiltIn>
152 {
153 };
154
155 //! The CUDA built in max.
156 class MaxUniformCudaHipBuiltIn : public interface::Implements<ConceptMathMax, MaxUniformCudaHipBuiltIn>
157 {
158 };
159
160 //! The CUDA built in min.
161 class MinUniformCudaHipBuiltIn : public interface::Implements<ConceptMathMin, MinUniformCudaHipBuiltIn>
162 {
163 };
164
165 //! The CUDA built in pow.
166 class PowUniformCudaHipBuiltIn : public interface::Implements<ConceptMathPow, PowUniformCudaHipBuiltIn>
167 {
168 };
169
170 //! The CUDA built in remainder.
172 : public interface::Implements<ConceptMathRemainder, RemainderUniformCudaHipBuiltIn>
173 {
174 };
175
176 //! The CUDA round.
177 class RoundUniformCudaHipBuiltIn : public interface::Implements<ConceptMathRound, RoundUniformCudaHipBuiltIn>
178 {
179 };
180
181 //! The CUDA rsqrt.
182 class RsqrtUniformCudaHipBuiltIn : public interface::Implements<ConceptMathRsqrt, RsqrtUniformCudaHipBuiltIn>
183 {
184 };
185
186 //! The CUDA sin.
187 class SinUniformCudaHipBuiltIn : public interface::Implements<ConceptMathSin, SinUniformCudaHipBuiltIn>
188 {
189 };
190
191 //! The CUDA sinh.
192 class SinhUniformCudaHipBuiltIn : public interface::Implements<ConceptMathSinh, SinhUniformCudaHipBuiltIn>
193 {
194 };
195
196 //! The CUDA sincos.
197 class SinCosUniformCudaHipBuiltIn : public interface::Implements<ConceptMathSinCos, SinCosUniformCudaHipBuiltIn>
198 {
199 };
200
201 //! The CUDA sqrt.
202 class SqrtUniformCudaHipBuiltIn : public interface::Implements<ConceptMathSqrt, SqrtUniformCudaHipBuiltIn>
203 {
204 };
205
206 //! The CUDA tan.
207 class TanUniformCudaHipBuiltIn : public interface::Implements<ConceptMathTan, TanUniformCudaHipBuiltIn>
208 {
209 };
210
211 //! The CUDA tanh.
212 class TanhUniformCudaHipBuiltIn : public interface::Implements<ConceptMathTanh, TanhUniformCudaHipBuiltIn>
213 {
214 };
215
216 //! The CUDA trunc.
217 class TruncUniformCudaHipBuiltIn : public interface::Implements<ConceptMathTrunc, TruncUniformCudaHipBuiltIn>
218 {
219 };
220
221 //! The standard library math trait specializations.
262 {
263 };
264
265# if !defined(ALPAKA_HOST_ONLY)
266
267# if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && !BOOST_LANG_CUDA
268# error If ALPAKA_ACC_GPU_CUDA_ENABLED is set, the compiler has to support CUDA!
269# endif
270
271# if defined(ALPAKA_ACC_GPU_HIP_ENABLED) && !BOOST_LANG_HIP
272# error If ALPAKA_ACC_GPU_HIP_ENABLED is set, the compiler has to support HIP!
273# endif
274
275# if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && defined(__CUDA_ARCH__)
276# include <cuda_runtime.h>
277# endif
278
279# if defined(ALPAKA_ACC_GPU_HIP_ENABLED) && defined(__HIP_DEVICE_COMPILE__)
280# include <hip/math_functions.h>
281# endif
282
283 namespace trait
284 {
285 //! The CUDA abs trait specialization for real types.
286 template<typename TArg>
287 struct Abs<AbsUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_signed_v<TArg>>>
288 {
289 __host__ __device__ auto operator()(AbsUniformCudaHipBuiltIn const& /* abs_ctx */, TArg const& arg)
290 {
291 if constexpr(is_decayed_v<TArg, float>)
292 return ::fabsf(arg);
293 else if constexpr(is_decayed_v<TArg, double>)
294 return ::fabs(arg);
295 else if constexpr(is_decayed_v<TArg, int>)
296 return ::abs(arg);
297 else if constexpr(is_decayed_v<TArg, long int>)
298 return ::labs(arg);
299 else if constexpr(is_decayed_v<TArg, long long int>)
300 return ::llabs(arg);
301 else
302 static_assert(!sizeof(TArg), "Unsupported data type");
303
304 ALPAKA_UNREACHABLE(TArg{});
305 }
306 };
307
308 //! The CUDA acos trait specialization for real types.
309 template<typename TArg>
310 struct Acos<AcosUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
311 {
312 __host__ __device__ auto operator()(AcosUniformCudaHipBuiltIn const& /* acos_ctx */, TArg const& arg)
313 {
314 if constexpr(is_decayed_v<TArg, float>)
315 return ::acosf(arg);
316 else if constexpr(is_decayed_v<TArg, double>)
317 return ::acos(arg);
318 else
319 static_assert(!sizeof(TArg), "Unsupported data type");
320
321 ALPAKA_UNREACHABLE(TArg{});
322 }
323 };
324
325 //! The CUDA acosh trait specialization for real types.
326 template<typename TArg>
327 struct Acosh<AcoshUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
328 {
329 __host__ __device__ auto operator()(AcoshUniformCudaHipBuiltIn const& /* acosh_ctx */, TArg const& arg)
330 {
331 if constexpr(is_decayed_v<TArg, float>)
332 return ::acoshf(arg);
333 else if constexpr(is_decayed_v<TArg, double>)
334 return ::acosh(arg);
335 else
336 static_assert(!sizeof(TArg), "Unsupported data type");
337
338 ALPAKA_UNREACHABLE(TArg{});
339 }
340 };
341
342 //! The CUDA arg trait specialization for real types.
343 template<typename TArgument>
344 struct Arg<ArgUniformCudaHipBuiltIn, TArgument, std::enable_if_t<std::is_floating_point_v<TArgument>>>
345 {
346 //! Take context as original (accelerator) type, since we call other math functions
347 template<typename TCtx>
348 __host__ __device__ auto operator()(TCtx const& ctx, TArgument const& argument)
349 {
350 // Fall back to atan2 so that boundary cases are resolved consistently
351 return atan2(ctx, TArgument{0.0}, argument);
352 }
353 };
354
355 //! The CUDA asin trait specialization for real types.
356 template<typename TArg>
357 struct Asin<AsinUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
358 {
359 __host__ __device__ auto operator()(AsinUniformCudaHipBuiltIn const& /* asin_ctx */, TArg const& arg)
360 {
361 if constexpr(is_decayed_v<TArg, float>)
362 return ::asinf(arg);
363 else if constexpr(is_decayed_v<TArg, double>)
364 return ::asin(arg);
365 else
366 static_assert(!sizeof(TArg), "Unsupported data type");
367
368 ALPAKA_UNREACHABLE(TArg{});
369 }
370 };
371
372 //! The CUDA asinh trait specialization for real types.
373 template<typename TArg>
374 struct Asinh<AsinhUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
375 {
376 __host__ __device__ auto operator()(AsinhUniformCudaHipBuiltIn const& /* asinh_ctx */, TArg const& arg)
377 {
378 if constexpr(is_decayed_v<TArg, float>)
379 return ::asinhf(arg);
380 else if constexpr(is_decayed_v<TArg, double>)
381 return ::asinh(arg);
382 else
383 static_assert(!sizeof(TArg), "Unsupported data type");
384
385 ALPAKA_UNREACHABLE(TArg{});
386 }
387 };
388
389 //! The CUDA atan trait specialization for real types.
390 template<typename TArg>
391 struct Atan<AtanUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
392 {
393 __host__ __device__ auto operator()(AtanUniformCudaHipBuiltIn const& /* atan_ctx */, TArg const& arg)
394 {
395 if constexpr(is_decayed_v<TArg, float>)
396 return ::atanf(arg);
397 else if constexpr(is_decayed_v<TArg, double>)
398 return ::atan(arg);
399 else
400 static_assert(!sizeof(TArg), "Unsupported data type");
401
402 ALPAKA_UNREACHABLE(TArg{});
403 }
404 };
405
406 //! The CUDA atanh trait specialization for real types.
407 template<typename TArg>
408 struct Atanh<AtanhUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
409 {
410 __host__ __device__ auto operator()(AtanhUniformCudaHipBuiltIn const& /* atanh_ctx */, TArg const& arg)
411 {
412 if constexpr(is_decayed_v<TArg, float>)
413 return ::atanhf(arg);
414 else if constexpr(is_decayed_v<TArg, double>)
415 return ::atanh(arg);
416 else
417 static_assert(!sizeof(TArg), "Unsupported data type");
418
419 ALPAKA_UNREACHABLE(TArg{});
420 }
421 };
422
423 //! The CUDA atan2 trait specialization.
424 template<typename Ty, typename Tx>
425 struct Atan2<
426 Atan2UniformCudaHipBuiltIn,
427 Ty,
428 Tx,
429 std::enable_if_t<std::is_floating_point_v<Ty> && std::is_floating_point_v<Tx>>>
430 {
431 __host__ __device__ auto operator()(
432 Atan2UniformCudaHipBuiltIn const& /* atan2_ctx */,
433 Ty const& y,
434 Tx const& x)
435 {
436 if constexpr(is_decayed_v<Ty, float> && is_decayed_v<Tx, float>)
437 return ::atan2f(y, x);
438 else if constexpr(is_decayed_v<Ty, double> || is_decayed_v<Tx, double>)
439 return ::atan2(y, x);
440 else
441 static_assert(!sizeof(Ty), "Unsupported data type");
442
443 ALPAKA_UNREACHABLE(Ty{});
444 }
445 };
446
447 //! The CUDA cbrt trait specialization.
448 template<typename TArg>
449 struct Cbrt<CbrtUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_arithmetic_v<TArg>>>
450 {
451 __host__ __device__ auto operator()(CbrtUniformCudaHipBuiltIn const& /* cbrt_ctx */, TArg const& arg)
452 {
453 if constexpr(is_decayed_v<TArg, float>)
454 return ::cbrtf(arg);
455 else if constexpr(is_decayed_v<TArg, double> || std::is_integral_v<TArg>)
456 return ::cbrt(arg);
457 else
458 static_assert(!sizeof(TArg), "Unsupported data type");
459
460 ALPAKA_UNREACHABLE(TArg{});
461 }
462 };
463
464 //! The CUDA ceil trait specialization.
465 template<typename TArg>
466 struct Ceil<CeilUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
467 {
468 __host__ __device__ auto operator()(CeilUniformCudaHipBuiltIn const& /* ceil_ctx */, TArg const& arg)
469 {
470 if constexpr(is_decayed_v<TArg, float>)
471 return ::ceilf(arg);
472 else if constexpr(is_decayed_v<TArg, double>)
473 return ::ceil(arg);
474 else
475 static_assert(!sizeof(TArg), "Unsupported data type");
476
477 ALPAKA_UNREACHABLE(TArg{});
478 }
479 };
480
481 //! The CUDA conj trait specialization for real types.
482 template<typename TArg>
483 struct Conj<ConjUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
484 {
485 __host__ __device__ auto operator()(ConjUniformCudaHipBuiltIn const& /* conj_ctx */, TArg const& arg)
486 {
487 return Complex<TArg>{arg, TArg{0.0}};
488 }
489 };
490
491 //! The CUDA copysign trait specialization for real types.
492 template<typename TMag, typename TSgn>
493 struct Copysign<
494 CopysignUniformCudaHipBuiltIn,
495 TMag,
496 TSgn,
497 std::enable_if_t<std::is_floating_point_v<TMag> && std::is_floating_point_v<TSgn>>>
498 {
499 __host__ __device__ auto operator()(
500 CopysignUniformCudaHipBuiltIn const& /* copysign_ctx */,
501 TMag const& mag,
502 TSgn const& sgn)
503 {
504 if constexpr(is_decayed_v<TMag, float> && is_decayed_v<TSgn, float>)
505 return ::copysignf(mag, sgn);
506 else if constexpr(is_decayed_v<TMag, double> || is_decayed_v<TSgn, double>)
507 return ::copysign(mag, sgn);
508 else
509 static_assert(!sizeof(TMag), "Unsupported data type");
510
511 ALPAKA_UNREACHABLE(TMag{});
512 }
513 };
514
515 //! The CUDA cos trait specialization for real types.
516 template<typename TArg>
517 struct Cos<CosUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
518 {
519 __host__ __device__ auto operator()(CosUniformCudaHipBuiltIn const& /* cos_ctx */, TArg const& arg)
520 {
521 if constexpr(is_decayed_v<TArg, float>)
522 return ::cosf(arg);
523 else if constexpr(is_decayed_v<TArg, double>)
524 return ::cos(arg);
525 else
526 static_assert(!sizeof(TArg), "Unsupported data type");
527
528 ALPAKA_UNREACHABLE(TArg{});
529 }
530 };
531
532 //! The CUDA cosh trait specialization for real types.
533 template<typename TArg>
534 struct Cosh<CoshUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
535 {
536 __host__ __device__ auto operator()(CoshUniformCudaHipBuiltIn const& /* cos_ctx */, TArg const& arg)
537 {
538 if constexpr(is_decayed_v<TArg, float>)
539 return ::coshf(arg);
540 else if constexpr(is_decayed_v<TArg, double>)
541 return ::cosh(arg);
542 else
543 static_assert(!sizeof(TArg), "Unsupported data type");
544
545 ALPAKA_UNREACHABLE(TArg{});
546 }
547 };
548
549 //! The CUDA erf trait specialization.
550 template<typename TArg>
551 struct Erf<ErfUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
552 {
553 __host__ __device__ auto operator()(ErfUniformCudaHipBuiltIn const& /* erf_ctx */, TArg const& arg)
554 {
555 if constexpr(is_decayed_v<TArg, float>)
556 return ::erff(arg);
557 else if constexpr(is_decayed_v<TArg, double>)
558 return ::erf(arg);
559 else
560 static_assert(!sizeof(TArg), "Unsupported data type");
561
562 ALPAKA_UNREACHABLE(TArg{});
563 }
564 };
565
566 //! The CUDA exp trait specialization for real types.
567 template<typename TArg>
568 struct Exp<ExpUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
569 {
570 __host__ __device__ auto operator()(ExpUniformCudaHipBuiltIn const& /* exp_ctx */, TArg const& arg)
571 {
572 if constexpr(is_decayed_v<TArg, float>)
573 return ::expf(arg);
574 else if constexpr(is_decayed_v<TArg, double>)
575 return ::exp(arg);
576 else
577 static_assert(!sizeof(TArg), "Unsupported data type");
578
579 ALPAKA_UNREACHABLE(TArg{});
580 }
581 };
582
583 //! The CUDA floor trait specialization.
584 template<typename TArg>
585 struct Floor<FloorUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
586 {
587 __host__ __device__ auto operator()(FloorUniformCudaHipBuiltIn const& /* floor_ctx */, TArg const& arg)
588 {
589 if constexpr(is_decayed_v<TArg, float>)
590 return ::floorf(arg);
591 else if constexpr(is_decayed_v<TArg, double>)
592 return ::floor(arg);
593 else
594 static_assert(!sizeof(TArg), "Unsupported data type");
595
596 ALPAKA_UNREACHABLE(TArg{});
597 }
598 };
599
600 //! The CUDA fma trait specialization.
601 template<typename Tx, typename Ty, typename Tz>
602 struct Fma<
603 FmaUniformCudaHipBuiltIn,
604 Tx,
605 Ty,
606 Tz,
607 std::enable_if_t<
608 std::is_floating_point_v<Tx> && std::is_floating_point_v<Ty> && std::is_floating_point_v<Tz>>>
609 {
610 __host__ __device__ auto operator()(
611 FmaUniformCudaHipBuiltIn const& /* fma_ctx */,
612 Tx const& x,
613 Ty const& y,
614 Tz const& z)
615 {
616 if constexpr(is_decayed_v<Tx, float> && is_decayed_v<Ty, float> && is_decayed_v<Tz, float>)
617 return ::fmaf(x, y, z);
618 else if constexpr(is_decayed_v<Tx, double> || is_decayed_v<Ty, double> || is_decayed_v<Tz, double>)
619 return ::fma(x, y, z);
620 else
621 static_assert(!sizeof(Tx), "Unsupported data type");
622
623 using Ret [[maybe_unused]] = std::conditional_t<
624 is_decayed_v<Tx, float> && is_decayed_v<Ty, float> && is_decayed_v<Tz, float>,
625 float,
626 double>;
627 ALPAKA_UNREACHABLE(Ret{});
628 }
629 };
630
631 //! The CUDA fmod trait specialization.
632 template<typename Tx, typename Ty>
633 struct Fmod<
634 FmodUniformCudaHipBuiltIn,
635 Tx,
636 Ty,
637 std::enable_if_t<std::is_floating_point_v<Tx> && std::is_floating_point_v<Ty>>>
638 {
639 __host__ __device__ auto operator()(
640 FmodUniformCudaHipBuiltIn const& /* fmod_ctx */,
641 Tx const& x,
642 Ty const& y)
643 {
644 if constexpr(is_decayed_v<Tx, float> && is_decayed_v<Ty, float>)
645 return ::fmodf(x, y);
646 else if constexpr(is_decayed_v<Tx, double> || is_decayed_v<Ty, double>)
647 return ::fmod(x, y);
648 else
649 static_assert(!sizeof(Tx), "Unsupported data type");
650
651 using Ret [[maybe_unused]]
652 = std::conditional_t<is_decayed_v<Tx, float> && is_decayed_v<Ty, float>, float, double>;
653 ALPAKA_UNREACHABLE(Ret{});
654 }
655 };
656
657 //! The CUDA isfinite trait specialization.
658 template<typename TArg>
659 struct Isfinite<IsfiniteUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
660 {
661 __host__ __device__ auto operator()(IsfiniteUniformCudaHipBuiltIn const& /* ctx */, TArg const& arg)
662 {
663 return ::isfinite(arg);
664 }
665 };
666
667 //! The CUDA isinf trait specialization.
668 template<typename TArg>
669 struct Isinf<IsinfUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
670 {
671 __host__ __device__ auto operator()(IsinfUniformCudaHipBuiltIn const& /* ctx */, TArg const& arg)
672 {
673 return ::isinf(arg);
674 }
675 };
676
677 //! The CUDA isnan trait specialization.
678 template<typename TArg>
679 struct Isnan<IsnanUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
680 {
681 __host__ __device__ auto operator()(IsnanUniformCudaHipBuiltIn const& /* ctx */, TArg const& arg)
682 {
683 return ::isnan(arg);
684 }
685 };
686
687 //! The CUDA log trait specialization for real types.
688 template<typename TArg>
689 struct Log<LogUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
690 {
691 __host__ __device__ auto operator()(LogUniformCudaHipBuiltIn const& /* log_ctx */, TArg const& arg)
692 {
693 if constexpr(is_decayed_v<TArg, float>)
694 return ::logf(arg);
695 else if constexpr(is_decayed_v<TArg, double>)
696 return ::log(arg);
697 else
698 static_assert(!sizeof(TArg), "Unsupported data type");
699
700 ALPAKA_UNREACHABLE(TArg{});
701 }
702 };
703
704 //! The CUDA log2 trait specialization for real types.
705 template<typename TArg>
706 struct Log2<Log2UniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
707 {
708 __host__ __device__ auto operator()(Log2UniformCudaHipBuiltIn const& /* log2_ctx */, TArg const& arg)
709 {
710 if constexpr(is_decayed_v<TArg, float>)
711 return ::log2f(arg);
712 else if constexpr(is_decayed_v<TArg, double>)
713 return ::log2(arg);
714 else
715 static_assert(!sizeof(TArg), "Unsupported data type");
716
717 ALPAKA_UNREACHABLE(TArg{});
718 }
719 };
720
721 //! The CUDA log10 trait specialization for real types.
722 template<typename TArg>
723 struct Log10<Log10UniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
724 {
725 __host__ __device__ auto operator()(Log10UniformCudaHipBuiltIn const& /* log10_ctx */, TArg const& arg)
726 {
727 if constexpr(is_decayed_v<TArg, float>)
728 return ::log10f(arg);
729 else if constexpr(is_decayed_v<TArg, double>)
730 return ::log10(arg);
731 else
732 static_assert(!sizeof(TArg), "Unsupported data type");
733
734 ALPAKA_UNREACHABLE(TArg{});
735 }
736 };
737
738 //! The CUDA max trait specialization.
739 template<typename Tx, typename Ty>
740 struct Max<
741 MaxUniformCudaHipBuiltIn,
742 Tx,
743 Ty,
744 std::enable_if_t<std::is_arithmetic_v<Tx> && std::is_arithmetic_v<Ty>>>
745 {
746 __host__ __device__ auto operator()(
747 MaxUniformCudaHipBuiltIn const& /* max_ctx */,
748 Tx const& x,
749 Ty const& y)
750 {
751 if constexpr(std::is_integral_v<Tx> && std::is_integral_v<Ty>)
752 return ::max(x, y);
753 else if constexpr(is_decayed_v<Tx, float> && is_decayed_v<Ty, float>)
754 return ::fmaxf(x, y);
755 else if constexpr(
756 is_decayed_v<Tx, double> || is_decayed_v<Ty, double>
757 || (is_decayed_v<Tx, float> && std::is_integral_v<Ty>)
758 || (std::is_integral_v<Tx> && is_decayed_v<Ty, float>) )
759 return ::fmax(x, y);
760 else
761 static_assert(!sizeof(Tx), "Unsupported data type");
762
763 using Ret [[maybe_unused]] = std::conditional_t<
764 std::is_integral_v<Tx> && std::is_integral_v<Ty>,
765 decltype(::max(x, y)),
766 std::conditional_t<is_decayed_v<Tx, float> && is_decayed_v<Ty, float>, float, double>>;
767 ALPAKA_UNREACHABLE(Ret{});
768 }
769 };
770
771 //! The CUDA min trait specialization.
772 template<typename Tx, typename Ty>
773 struct Min<
774 MinUniformCudaHipBuiltIn,
775 Tx,
776 Ty,
777 std::enable_if_t<std::is_arithmetic_v<Tx> && std::is_arithmetic_v<Ty>>>
778 {
779 __host__ __device__ auto operator()(
780 MinUniformCudaHipBuiltIn const& /* min_ctx */,
781 Tx const& x,
782 Ty const& y)
783 {
784 if constexpr(std::is_integral_v<Tx> && std::is_integral_v<Ty>)
785 return ::min(x, y);
786 else if constexpr(is_decayed_v<Tx, float> && is_decayed_v<Ty, float>)
787 return ::fminf(x, y);
788 else if constexpr(
789 is_decayed_v<Tx, double> || is_decayed_v<Ty, double>
790 || (is_decayed_v<Tx, float> && std::is_integral_v<Ty>)
791 || (std::is_integral_v<Tx> && is_decayed_v<Ty, float>) )
792 return ::fmin(x, y);
793 else
794 static_assert(!sizeof(Tx), "Unsupported data type");
795
796 using Ret [[maybe_unused]] = std::conditional_t<
797 std::is_integral_v<Tx> && std::is_integral_v<Ty>,
798 decltype(::min(x, y)),
799 std::conditional_t<is_decayed_v<Tx, float> && is_decayed_v<Ty, float>, float, double>>;
800 ALPAKA_UNREACHABLE(Ret{});
801 }
802 };
803
804 //! The CUDA pow trait specialization for real types.
805 template<typename TBase, typename TExp>
806 struct Pow<
807 PowUniformCudaHipBuiltIn,
808 TBase,
809 TExp,
810 std::enable_if_t<std::is_floating_point_v<TBase> && std::is_floating_point_v<TExp>>>
811 {
812 __host__ __device__ auto operator()(
813 PowUniformCudaHipBuiltIn const& /* pow_ctx */,
814 TBase const& base,
815 TExp const& exp)
816 {
817 if constexpr(is_decayed_v<TBase, float> && is_decayed_v<TExp, float>)
818 return ::powf(base, exp);
819 else if constexpr(is_decayed_v<TBase, double> || is_decayed_v<TExp, double>)
820 return ::pow(static_cast<double>(base), static_cast<double>(exp));
821 else
822 static_assert(!sizeof(TBase), "Unsupported data type");
823
824 using Ret [[maybe_unused]]
825 = std::conditional_t<is_decayed_v<TBase, float> && is_decayed_v<TExp, float>, float, double>;
826 ALPAKA_UNREACHABLE(Ret{});
827 }
828 };
829
830 //! The CUDA remainder trait specialization.
831 template<typename Tx, typename Ty>
832 struct Remainder<
833 RemainderUniformCudaHipBuiltIn,
834 Tx,
835 Ty,
836 std::enable_if_t<std::is_floating_point_v<Tx> && std::is_floating_point_v<Ty>>>
837 {
838 __host__ __device__ auto operator()(
839 RemainderUniformCudaHipBuiltIn const& /* remainder_ctx */,
840 Tx const& x,
841 Ty const& y)
842 {
843 if constexpr(is_decayed_v<Tx, float> && is_decayed_v<Ty, float>)
844 return ::remainderf(x, y);
845 else if constexpr(is_decayed_v<Tx, double> || is_decayed_v<Ty, double>)
846 return ::remainder(x, y);
847 else
848 static_assert(!sizeof(Tx), "Unsupported data type");
849
850 using Ret [[maybe_unused]]
851 = std::conditional_t<is_decayed_v<Tx, float> && is_decayed_v<Ty, float>, float, double>;
852 ALPAKA_UNREACHABLE(Ret{});
853 }
854 };
855
856 //! The CUDA round trait specialization.
857 template<typename TArg>
858 struct Round<RoundUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
859 {
860 __host__ __device__ auto operator()(RoundUniformCudaHipBuiltIn const& /* round_ctx */, TArg const& arg)
861 {
862 if constexpr(is_decayed_v<TArg, float>)
863 return ::roundf(arg);
864 else if constexpr(is_decayed_v<TArg, double>)
865 return ::round(arg);
866 else
867 static_assert(!sizeof(TArg), "Unsupported data type");
868
869 ALPAKA_UNREACHABLE(TArg{});
870 }
871 };
872
873 //! The CUDA lround trait specialization.
874 template<typename TArg>
875 struct Lround<RoundUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
876 {
877 __host__ __device__ auto operator()(RoundUniformCudaHipBuiltIn const& /* lround_ctx */, TArg const& arg)
878 {
879 if constexpr(is_decayed_v<TArg, float>)
880 return ::lroundf(arg);
881 else if constexpr(is_decayed_v<TArg, double>)
882 return ::lround(arg);
883 else
884 static_assert(!sizeof(TArg), "Unsupported data type");
885
886 ALPAKA_UNREACHABLE(long{});
887 }
888 };
889
890 //! The CUDA llround trait specialization.
891 template<typename TArg>
892 struct Llround<RoundUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
893 {
894 __host__ __device__ auto operator()(RoundUniformCudaHipBuiltIn const& /* llround_ctx */, TArg const& arg)
895 {
896 if constexpr(is_decayed_v<TArg, float>)
897 return ::llroundf(arg);
898 else if constexpr(is_decayed_v<TArg, double>)
899 return ::llround(arg);
900 else
901 static_assert(!sizeof(TArg), "Unsupported data type");
902
903 // NVCC versions before 11.3 are unable to compile 'long long{}': "type name is not allowed".
904 using Ret [[maybe_unused]] = long long;
905 ALPAKA_UNREACHABLE(Ret{});
906 }
907 };
908
909 //! The CUDA rsqrt trait specialization for real types.
910 template<typename TArg>
911 struct Rsqrt<RsqrtUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_arithmetic_v<TArg>>>
912 {
913 __host__ __device__ auto operator()(RsqrtUniformCudaHipBuiltIn const& /* rsqrt_ctx */, TArg const& arg)
914 {
915 if constexpr(is_decayed_v<TArg, float>)
916 return ::rsqrtf(arg);
917 else if constexpr(is_decayed_v<TArg, double> || std::is_integral_v<TArg>)
918 return ::rsqrt(arg);
919 else
920 static_assert(!sizeof(TArg), "Unsupported data type");
921
922 ALPAKA_UNREACHABLE(TArg{});
923 }
924 };
925
926 //! The CUDA sin trait specialization for real types.
927 template<typename TArg>
928 struct Sin<SinUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
929 {
930 __host__ __device__ auto operator()(SinUniformCudaHipBuiltIn const& /* sin_ctx */, TArg const& arg)
931 {
932 if constexpr(is_decayed_v<TArg, float>)
933 return ::sinf(arg);
934 else if constexpr(is_decayed_v<TArg, double>)
935 return ::sin(arg);
936 else
937 static_assert(!sizeof(TArg), "Unsupported data type");
938
939 ALPAKA_UNREACHABLE(TArg{});
940 }
941 };
942
943 //! The CUDA sinh trait specialization for real types.
944 template<typename TArg>
945 struct Sinh<SinhUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
946 {
947 __host__ __device__ auto operator()(SinhUniformCudaHipBuiltIn const& /* sinh_ctx */, TArg const& arg)
948 {
949 if constexpr(is_decayed_v<TArg, float>)
950 return ::sinhf(arg);
951 else if constexpr(is_decayed_v<TArg, double>)
952 return ::sinh(arg);
953 else
954 static_assert(!sizeof(TArg), "Unsupported data type");
955
956 ALPAKA_UNREACHABLE(TArg{});
957 }
958 };
959
960 //! The CUDA sincos trait specialization for real types.
961 template<typename TArg>
962 struct SinCos<SinCosUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
963 {
964 __host__ __device__ auto operator()(
965 SinCosUniformCudaHipBuiltIn const& /* sincos_ctx */,
966 TArg const& arg,
967 TArg& result_sin,
968 TArg& result_cos) -> void
969 {
970 if constexpr(is_decayed_v<TArg, float>)
971 ::sincosf(arg, &result_sin, &result_cos);
972 else if constexpr(is_decayed_v<TArg, double>)
973 ::sincos(arg, &result_sin, &result_cos);
974 else
975 static_assert(!sizeof(TArg), "Unsupported data type");
976 }
977 };
978
979 //! The CUDA sqrt trait specialization for real types.
980 template<typename TArg>
981 struct Sqrt<SqrtUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_arithmetic_v<TArg>>>
982 {
983 __host__ __device__ auto operator()(SqrtUniformCudaHipBuiltIn const& /* sqrt_ctx */, TArg const& arg)
984 {
985 if constexpr(is_decayed_v<TArg, float>)
986 return ::sqrtf(arg);
987 else if constexpr(is_decayed_v<TArg, double> || std::is_integral_v<TArg>)
988 return ::sqrt(arg);
989 else
990 static_assert(!sizeof(TArg), "Unsupported data type");
991
992 ALPAKA_UNREACHABLE(TArg{});
993 }
994 };
995
996 //! The CUDA tan trait specialization for real types.
997 template<typename TArg>
998 struct Tan<TanUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
999 {
1000 __host__ __device__ auto operator()(TanUniformCudaHipBuiltIn const& /* tan_ctx */, TArg const& arg)
1001 {
1002 if constexpr(is_decayed_v<TArg, float>)
1003 return ::tanf(arg);
1004 else if constexpr(is_decayed_v<TArg, double>)
1005 return ::tan(arg);
1006 else
1007 static_assert(!sizeof(TArg), "Unsupported data type");
1008
1009 ALPAKA_UNREACHABLE(TArg{});
1010 }
1011 };
1012
1013 //! The CUDA tanh trait specialization for real types.
1014 template<typename TArg>
1015 struct Tanh<TanhUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
1016 {
1017 __host__ __device__ auto operator()(TanhUniformCudaHipBuiltIn const& /* tanh_ctx */, TArg const& arg)
1018 {
1019 if constexpr(is_decayed_v<TArg, float>)
1020 return ::tanhf(arg);
1021 else if constexpr(is_decayed_v<TArg, double>)
1022 return ::tanh(arg);
1023 else
1024 static_assert(!sizeof(TArg), "Unsupported data type");
1025
1026 ALPAKA_UNREACHABLE(TArg{});
1027 }
1028 };
1029
1030 //! The CUDA trunc trait specialization.
1031 template<typename TArg>
1032 struct Trunc<TruncUniformCudaHipBuiltIn, TArg, std::enable_if_t<std::is_floating_point_v<TArg>>>
1033 {
1034 __host__ __device__ auto operator()(TruncUniformCudaHipBuiltIn const& /* trunc_ctx */, TArg const& arg)
1035 {
1036 if constexpr(is_decayed_v<TArg, float>)
1037 return ::truncf(arg);
1038 else if constexpr(is_decayed_v<TArg, double>)
1039 return ::trunc(arg);
1040 else
1041 static_assert(!sizeof(TArg), "Unsupported data type");
1042
1043 ALPAKA_UNREACHABLE(TArg{});
1044 }
1045 };
1046 } // namespace trait
1047# endif
1048} // namespace alpaka::math
1049
1050#endif
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
The standard library math trait specializations.
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto max(T const &max_ctx, Tx const &x, Ty const &y)
Returns the larger of two arguments. NaNs are treated as missing data (between a NaN and a numeric va...
Definition Traits.hpp:1263
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto exp(T const &exp_ctx, TArg const &arg)
Computes the e (Euler's number, 2.7182818) raised to the given power arg.
Definition Traits.hpp:1102
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto sincos(T const &sincos_ctx, TArg const &arg, TArg &result_sin, TArg &result_cos) -> void
Computes the sine and cosine (measured in radians).
Definition Traits.hpp:1423
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto min(T const &min_ctx, Tx const &x, Ty const &y)
Returns the smaller of two arguments. NaNs are treated as missing data (between a NaN and a numeric v...
Definition Traits.hpp:1280
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto atan2(T const &atan2_ctx, Ty const &y, Tx const &x)
Computes the arc tangent of y/x using the signs of arguments to determine the correct quadrant.
Definition Traits.hpp:988
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto arg(T const &arg_ctx, TArgument const &argument)
Computes the complex argument of the value.
Definition Traits.hpp:912
STL namespace.
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition Interface.hpp:15
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:298
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:311
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:324
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto operator()(T const &, TArgument const &argument)
Definition Traits.hpp:340
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:353
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:366
ALPAKA_FN_HOST_ACC auto operator()(T const &, Ty const &y, Tx const &x)
Definition Traits.hpp:405
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:379
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:392
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:418
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:431
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:444
ALPAKA_FN_HOST_ACC auto operator()(T const &, TMag const &mag, TSgn const &sgn)
Definition Traits.hpp:457
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:470
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:483
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:495
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:508
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:521
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y, Tz const &z)
Definition Traits.hpp:534
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition Traits.hpp:547
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:560
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:573
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:586
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:716
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:625
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:612
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:599
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:703
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition Traits.hpp:638
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition Traits.hpp:651
ALPAKA_FN_HOST_ACC auto operator()(T const &, TBase const &base, TExp const &exp)
Definition Traits.hpp:664
ALPAKA_FN_HOST_ACC auto operator()(T const &, Tx const &x, Ty const &y)
Definition Traits.hpp:677
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:690
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:741
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg, TArg &result_sin, TArg &result_cos)
Definition Traits.hpp:794
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:754
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:767
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:807
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:820
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:833
ALPAKA_FN_HOST_ACC auto operator()(T const &, TArg const &arg)
Definition Traits.hpp:846