alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
stlMathImpl.hpp
Go to the documentation of this file.
1/* Copyright 2023 Alexander Matthes, Axel Huebl, Benjamin Worpitz, Matthias Werner, Bernhard Manfred Gruber,
2 * Jeffrey Kelling, Sergei Bastrakov, Andrea Bocci, René Widera, Mehmet Yusufoglu
3 * SPDX-License-Identifier: MPL-2.0
4 */
5
6#pragma once
7
8/** @file This file contains specializations of methods where we do not want to fall back to `std::*` functions.
9 */
10
12#include "alpaka/core/decay.hpp"
16
17#include <cmath>
18#include <type_traits>
19
20namespace alpaka::math::internal
21{
22 template<typename T_A, typename T_B>
23 requires(std::is_arithmetic_v<T_A> && std::is_arithmetic_v<T_B>)
24 struct Min::Op<StlMath, T_A, T_B>
25 {
26 constexpr auto operator()(StlMath, T_A const& a, T_B const& b) const
27 {
28 if constexpr(std::is_integral_v<T_A> && std::is_integral_v<T_B>)
29 {
30 using std::min;
31 return min(a, b);
32 }
33 else if constexpr(
36 {
37 using std::fmin;
38 return fmin(a, b);
39 }
40 else
41 static_assert(!sizeof(T_A), "Unsupported data type");
42
43 ALPAKA_UNREACHABLE(std::common_type_t<T_A, T_B>{});
44 }
45 };
46
47 template<typename T_A, typename T_B>
48 requires(std::is_arithmetic_v<T_A> && std::is_arithmetic_v<T_B>)
49 struct Max::Op<StlMath, T_A, T_B>
50 {
51 constexpr auto operator()(StlMath, T_A const& a, T_B const& b) const
52 {
53 if constexpr(std::is_integral_v<T_A> && std::is_integral_v<T_B>)
54 {
55 using std::max;
56 return max(a, b);
57 }
58 else if constexpr(
61 {
62 using std::fmax;
63 return fmax(a, b);
64 }
65 else
66 static_assert(!sizeof(T_A), "Unsupported data type");
67
68 ALPAKA_UNREACHABLE(std::common_type_t<T_A, T_B>{});
69 }
70 };
71
72 //! Custom IEEE 754 bitwise implementation of isnan
73 //! std counterpart does not work correctly for `-ffast-math` flags at CPU.
74 template<std::floating_point T_Arg>
75 struct Isnan::Op<StlMath, T_Arg>
76 {
77 constexpr auto operator()(StlMath, T_Arg const& arg) const -> bool
78 {
79 return ieeeIsnan(arg);
80 }
81 };
82
83 //! Custom IEEE 754 bitwise implementation of isinf
84 //! std counterpart does not work correctly for `-ffast-math` flags at CPU.
85 template<std::floating_point T_Arg>
86 struct Isinf::Op<StlMath, T_Arg>
87 {
88 constexpr auto operator()(StlMath, T_Arg const& arg) const -> bool
89 {
90 return ieeeIsinf(arg);
91 }
92 };
93
94 //! Custom IEEE 754 bitwise implementation of isinf
95 //! std counterpart does not work correctly for `-ffast-math` flags at CPU.
96 template<std::floating_point T_Arg>
97 struct Isfinite::Op<StlMath, T_Arg>
98 {
99 constexpr auto operator()(StlMath, T_Arg const& arg) const -> bool
100 {
101 return ieeeIsfinite(arg);
102 }
103 };
104
105 //! Custom IEEE 754 bitwise implementation of isnan
106 //! std counterpart does not work correctly for `-ffast-math` flags at CPU.
107} // namespace alpaka::math::internal
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
constexpr auto min(auto const &a, auto const &b)
Definition math.hpp:272
constexpr auto max(auto const &a, auto const &b)
Definition math.hpp:278
constexpr auto is_decayed_v
Provides a decaying wrapper around std::is_same. Example: is_decayed_v<volatile float,...
Definition decay.hpp:13