alpaka
Abstraction Library for Parallel Kernel Acceleration
MathStdLib.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
3  * SPDX-License-Identifier: MPL-2.0
4  */
5 
6 #pragma once
7 
8 #include "alpaka/core/Decay.hpp"
9 #include "alpaka/math/Traits.hpp"
10 
11 namespace alpaka::math
12 {
13  //! The standard library abs, implementation covered by the general template.
14  class AbsStdLib : public interface::Implements<ConceptMathAbs, AbsStdLib>
15  {
16  };
17 
18  //! The standard library acos, implementation covered by the general template.
19  class AcosStdLib : public interface::Implements<ConceptMathAcos, AcosStdLib>
20  {
21  };
22 
23  //! The standard library acos, implementation covered by the general template.
24  class AcoshStdLib : public interface::Implements<ConceptMathAcosh, AcoshStdLib>
25  {
26  };
27 
28  //! The standard library arg, implementation covered by the general template.
29  class ArgStdLib : public interface::Implements<ConceptMathArg, ArgStdLib>
30  {
31  };
32 
33  //! The standard library asin, implementation covered by the general template.
34  class AsinStdLib : public interface::Implements<ConceptMathAsin, AsinStdLib>
35  {
36  };
37 
38  //! The standard library asinh, implementation covered by the general template.
39  class AsinhStdLib : public interface::Implements<ConceptMathAsinh, AsinhStdLib>
40  {
41  };
42 
43  //! The standard library atan, implementation covered by the general template.
44  class AtanStdLib : public interface::Implements<ConceptMathAtan, AtanStdLib>
45  {
46  };
47 
48  //! The standard library atanh, implementation covered by the general template.
49  class AtanhStdLib : public interface::Implements<ConceptMathAtanh, AtanhStdLib>
50  {
51  };
52 
53  //! The standard library atan2, implementation covered by the general template.
54  class Atan2StdLib : public interface::Implements<ConceptMathAtan2, Atan2StdLib>
55  {
56  };
57 
58  //! The standard library cbrt, implementation covered by the general template.
59  class CbrtStdLib : public interface::Implements<ConceptMathCbrt, CbrtStdLib>
60  {
61  };
62 
63  //! The standard library ceil, implementation covered by the general template.
64  class CeilStdLib : public interface::Implements<ConceptMathCeil, CeilStdLib>
65  {
66  };
67 
68  //! The standard library conj, implementation covered by the general template.
69  class ConjStdLib : public interface::Implements<ConceptMathConj, ConjStdLib>
70  {
71  };
72 
73  //! The standard library copysign, implementation covered by the general template.
74  class CopysignStdLib : public interface::Implements<ConceptMathCopysign, CopysignStdLib>
75  {
76  };
77 
78  //! The standard library cos, implementation covered by the general template.
79  class CosStdLib : public interface::Implements<ConceptMathCos, CosStdLib>
80  {
81  };
82 
83  //! The standard library cosh, implementation covered by the general template.
84  class CoshStdLib : public interface::Implements<ConceptMathCosh, CoshStdLib>
85  {
86  };
87 
88  //! The standard library erf, implementation covered by the general template.
89  class ErfStdLib : public interface::Implements<ConceptMathErf, ErfStdLib>
90  {
91  };
92 
93  //! The standard library exp, implementation covered by the general template.
94  class ExpStdLib : public interface::Implements<ConceptMathExp, ExpStdLib>
95  {
96  };
97 
98  //! The standard library floor, implementation covered by the general template.
99  class FloorStdLib : public interface::Implements<ConceptMathFloor, FloorStdLib>
100  {
101  };
102 
103  //! The standard library fma, implementation covered by the general template.
104  class FmaStdLib : public interface::Implements<ConceptMathFma, FmaStdLib>
105  {
106  };
107 
108  //! The standard library fmod, implementation covered by the general template.
109  class FmodStdLib : public interface::Implements<ConceptMathFmod, FmodStdLib>
110  {
111  };
112 
113  //! The standard library isfinite, implementation covered by the general template.
114  class IsfiniteStdLib : public interface::Implements<ConceptMathIsfinite, IsfiniteStdLib>
115  {
116  };
117 
118  //! The standard library isinf, implementation covered by the general template.
119  class IsinfStdLib : public interface::Implements<ConceptMathIsinf, IsinfStdLib>
120  {
121  };
122 
123  //! The standard library isnan, implementation covered by the general template.
124  class IsnanStdLib : public interface::Implements<ConceptMathIsnan, IsnanStdLib>
125  {
126  };
127 
128  //! The standard library log, implementation covered by the general template.
129  class LogStdLib : public interface::Implements<ConceptMathLog, LogStdLib>
130  {
131  };
132 
133  //! The standard library log2, implementation covered by the general template.
134  class Log2StdLib : public interface::Implements<ConceptMathLog2, Log2StdLib>
135  {
136  };
137 
138  //! The standard library log10, implementation covered by the general template.
139  class Log10StdLib : public interface::Implements<ConceptMathLog10, Log10StdLib>
140  {
141  };
142 
143  //! The standard library max.
144  class MaxStdLib : public interface::Implements<ConceptMathMax, MaxStdLib>
145  {
146  };
147 
148  //! The standard library min.
149  class MinStdLib : public interface::Implements<ConceptMathMin, MinStdLib>
150  {
151  };
152 
153  //! The standard library pow, implementation covered by the general template.
154  class PowStdLib : public interface::Implements<ConceptMathPow, PowStdLib>
155  {
156  };
157 
158  //! The standard library remainder, implementation covered by the general template.
159  class RemainderStdLib : public interface::Implements<ConceptMathRemainder, RemainderStdLib>
160  {
161  };
162 
163  //! The standard library round, implementation covered by the general template.
164  class RoundStdLib : public interface::Implements<ConceptMathRound, RoundStdLib>
165  {
166  };
167 
168  //! The standard library rsqrt, implementation covered by the general template.
169  class RsqrtStdLib : public interface::Implements<ConceptMathRsqrt, RsqrtStdLib>
170  {
171  };
172 
173  //! The standard library sin, implementation covered by the general template.
174  class SinStdLib : public interface::Implements<ConceptMathSin, SinStdLib>
175  {
176  };
177 
178  //! The standard library sinh, implementation covered by the general template.
179  class SinhStdLib : public interface::Implements<ConceptMathSinh, SinhStdLib>
180  {
181  };
182 
183  //! The standard library sincos, implementation covered by the general template.
184  class SinCosStdLib : public interface::Implements<ConceptMathSinCos, SinCosStdLib>
185  {
186  };
187 
188  //! The standard library sqrt, implementation covered by the general template.
189  class SqrtStdLib : public interface::Implements<ConceptMathSqrt, SqrtStdLib>
190  {
191  };
192 
193  //! The standard library tan, implementation covered by the general template.
194  class TanStdLib : public interface::Implements<ConceptMathTan, TanStdLib>
195  {
196  };
197 
198  //! The standard library tanh, implementation covered by the general template.
199  class TanhStdLib : public interface::Implements<ConceptMathTanh, TanhStdLib>
200  {
201  };
202 
203  //! The standard library trunc, implementation covered by the general template.
204  class TruncStdLib : public interface::Implements<ConceptMathTrunc, TruncStdLib>
205  {
206  };
207 
208  //! The standard library math trait specializations.
210  : public AbsStdLib
211  , public AcosStdLib
212  , public AcoshStdLib
213  , public ArgStdLib
214  , public AsinStdLib
215  , public AsinhStdLib
216  , public AtanStdLib
217  , public AtanhStdLib
218  , public Atan2StdLib
219  , public CbrtStdLib
220  , public CeilStdLib
221  , public ConjStdLib
222  , public CopysignStdLib
223  , public CosStdLib
224  , public CoshStdLib
225  , public ErfStdLib
226  , public ExpStdLib
227  , public FloorStdLib
228  , public FmaStdLib
229  , public FmodStdLib
230  , public LogStdLib
231  , public Log2StdLib
232  , public Log10StdLib
233  , public MaxStdLib
234  , public MinStdLib
235  , public PowStdLib
236  , public RemainderStdLib
237  , public RoundStdLib
238  , public RsqrtStdLib
239  , public SinStdLib
240  , public SinhStdLib
241  , public SinCosStdLib
242  , public SqrtStdLib
243  , public TanStdLib
244  , public TanhStdLib
245  , public TruncStdLib
246  , public IsnanStdLib
247  , public IsinfStdLib
248  , public IsfiniteStdLib
249  {
250  };
251 
252  namespace trait
253  {
254  //! The standard library max trait specialization.
255  template<typename Tx, typename Ty>
256  struct Max<MaxStdLib, Tx, Ty, std::enable_if_t<std::is_arithmetic_v<Tx> && std::is_arithmetic_v<Ty>>>
257  {
258  ALPAKA_FN_HOST auto operator()(MaxStdLib const& /* max_ctx */, Tx const& x, Ty const& y)
259  {
260  using std::fmax;
261  using std::max;
262 
263  if constexpr(std::is_integral_v<Tx> && std::is_integral_v<Ty>)
264  return max(x, y);
265  else if constexpr(
266  is_decayed_v<Tx, float> || is_decayed_v<Ty, float> || is_decayed_v<Tx, double>
267  || is_decayed_v<Ty, double>)
268  return fmax(x, y);
269  else
270  static_assert(!sizeof(Tx), "Unsupported data type");
271 
272  ALPAKA_UNREACHABLE(std::common_type_t<Tx, Ty>{});
273  }
274  };
275 
276  //! The standard library min trait specialization.
277  template<typename Tx, typename Ty>
278  struct Min<MinStdLib, Tx, Ty, std::enable_if_t<std::is_arithmetic_v<Tx> && std::is_arithmetic_v<Ty>>>
279  {
280  ALPAKA_FN_HOST auto operator()(MinStdLib const& /* min_ctx */, Tx const& x, Ty const& y)
281  {
282  using std::fmin;
283  using std::min;
284 
285  if constexpr(std::is_integral_v<Tx> && std::is_integral_v<Ty>)
286  return min(x, y);
287  else if constexpr(
288  is_decayed_v<Tx, float> || is_decayed_v<Ty, float> || is_decayed_v<Tx, double>
289  || is_decayed_v<Ty, double>)
290  return fmin(x, y);
291  else
292  static_assert(!sizeof(Tx), "Unsupported data type");
293 
294  ALPAKA_UNREACHABLE(std::common_type_t<Tx, Ty>{});
295  }
296  };
297  } // namespace trait
298 
299 } // namespace alpaka::math
#define ALPAKA_UNREACHABLE(...)
Before CUDA 11.5 nvcc is unable to correctly identify return statements in 'if constexpr' branches....
Definition: Unreachable.hpp:24
The standard library abs, implementation covered by the general template.
Definition: MathStdLib.hpp:15
The standard library acos, implementation covered by the general template.
Definition: MathStdLib.hpp:20
The standard library acos, implementation covered by the general template.
Definition: MathStdLib.hpp:25
The standard library arg, implementation covered by the general template.
Definition: MathStdLib.hpp:30
The standard library asin, implementation covered by the general template.
Definition: MathStdLib.hpp:35
The standard library asinh, implementation covered by the general template.
Definition: MathStdLib.hpp:40
The standard library atan2, implementation covered by the general template.
Definition: MathStdLib.hpp:55
The standard library atan, implementation covered by the general template.
Definition: MathStdLib.hpp:45
The standard library atanh, implementation covered by the general template.
Definition: MathStdLib.hpp:50
The standard library cbrt, implementation covered by the general template.
Definition: MathStdLib.hpp:60
The standard library ceil, implementation covered by the general template.
Definition: MathStdLib.hpp:65
The standard library conj, implementation covered by the general template.
Definition: MathStdLib.hpp:70
The standard library copysign, implementation covered by the general template.
Definition: MathStdLib.hpp:75
The standard library cos, implementation covered by the general template.
Definition: MathStdLib.hpp:80
The standard library cosh, implementation covered by the general template.
Definition: MathStdLib.hpp:85
The standard library erf, implementation covered by the general template.
Definition: MathStdLib.hpp:90
The standard library exp, implementation covered by the general template.
Definition: MathStdLib.hpp:95
The standard library floor, implementation covered by the general template.
Definition: MathStdLib.hpp:100
The standard library fma, implementation covered by the general template.
Definition: MathStdLib.hpp:105
The standard library fmod, implementation covered by the general template.
Definition: MathStdLib.hpp:110
The standard library isfinite, implementation covered by the general template.
Definition: MathStdLib.hpp:115
The standard library isinf, implementation covered by the general template.
Definition: MathStdLib.hpp:120
The standard library isnan, implementation covered by the general template.
Definition: MathStdLib.hpp:125
The standard library log10, implementation covered by the general template.
Definition: MathStdLib.hpp:140
The standard library log2, implementation covered by the general template.
Definition: MathStdLib.hpp:135
The standard library log, implementation covered by the general template.
Definition: MathStdLib.hpp:130
The standard library math trait specializations.
Definition: MathStdLib.hpp:249
The standard library max.
Definition: MathStdLib.hpp:145
The standard library min.
Definition: MathStdLib.hpp:150
The standard library pow, implementation covered by the general template.
Definition: MathStdLib.hpp:155
The standard library remainder, implementation covered by the general template.
Definition: MathStdLib.hpp:160
The standard library round, implementation covered by the general template.
Definition: MathStdLib.hpp:165
The standard library rsqrt, implementation covered by the general template.
Definition: MathStdLib.hpp:170
The standard library sincos, implementation covered by the general template.
Definition: MathStdLib.hpp:185
The standard library sin, implementation covered by the general template.
Definition: MathStdLib.hpp:175
The standard library sinh, implementation covered by the general template.
Definition: MathStdLib.hpp:180
The standard library sqrt, implementation covered by the general template.
Definition: MathStdLib.hpp:190
The standard library tan, implementation covered by the general template.
Definition: MathStdLib.hpp:195
The standard library tanh, implementation covered by the general template.
Definition: MathStdLib.hpp:200
The standard library trunc, implementation covered by the general template.
Definition: MathStdLib.hpp:205
#define ALPAKA_FN_HOST
Definition: Common.hpp:40
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 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
Tag used in class inheritance hierarchies that describes that a specific interface (TInterface) is im...
Definition: Interface.hpp:15
The max trait.
Definition: Traits.hpp:637
The min trait.
Definition: Traits.hpp:650