Kokkos Core Kernels Package  Version of the Day
Kokkos_NumericTraits.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 3.0
6 // Copyright (2020) National Technology & Engineering
7 // Solutions of Sandia, LLC (NTESS).
8 //
9 // Under the terms of Contract DE-NA0003525 with NTESS,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY NTESS "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NTESS OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Christian R. Trott (crtrott@sandia.gov)
40 //
41 // ************************************************************************
42 //@HEADER
43 */
44 
45 #ifndef KOKKOS_NUMERIC_TRAITS_HPP
46 #define KOKKOS_NUMERIC_TRAITS_HPP
47 
48 #include <Kokkos_Macros.hpp>
49 #include <cfloat>
50 #include <climits>
51 #include <cmath>
52 #include <cstdint>
53 #include <type_traits>
54 
55 namespace Kokkos {
56 namespace Experimental {
57 namespace Impl {
58 // clang-format off
59 template <class> struct infinity_helper;
60 template <> struct infinity_helper<float> { static constexpr float value = HUGE_VALF; };
61 template <> struct infinity_helper<double> { static constexpr double value = HUGE_VAL; };
62 template <> struct infinity_helper<long double> { static constexpr long double value = HUGE_VALL; };
63 template <class> struct finite_min_helper;
64 template <> struct finite_min_helper<bool> { static constexpr bool value = false; };
65 template <> struct finite_min_helper<char> { static constexpr char value = CHAR_MIN; };
66 template <> struct finite_min_helper<signed char> { static constexpr signed char value = SCHAR_MIN; };
67 template <> struct finite_min_helper<unsigned char> { static constexpr unsigned char value = 0; };
68 template <> struct finite_min_helper<short> { static constexpr short value = SHRT_MIN; };
69 template <> struct finite_min_helper<unsigned short> { static constexpr unsigned short value = 0; };
70 template <> struct finite_min_helper<int> { static constexpr int value = INT_MIN; };
71 template <> struct finite_min_helper<unsigned int> { static constexpr unsigned int value = 0; };
72 template <> struct finite_min_helper<long int> { static constexpr long int value = LONG_MIN; };
73 template <> struct finite_min_helper<unsigned long int> { static constexpr unsigned long int value = 0; };
74 template <> struct finite_min_helper<long long int> { static constexpr long long int value = LLONG_MIN; };
75 template <> struct finite_min_helper<unsigned long long int> { static constexpr unsigned long long int value = 0; };
76 template <> struct finite_min_helper<float> { static constexpr float value = -FLT_MAX; };
77 template <> struct finite_min_helper<double> { static constexpr double value = -DBL_MAX; };
78 template <> struct finite_min_helper<long double> { static constexpr long double value = -LDBL_MAX; };
79 template <class> struct finite_max_helper;
80 template <> struct finite_max_helper<bool> { static constexpr bool value = true; };
81 template <> struct finite_max_helper<char> { static constexpr char value = CHAR_MAX; };
82 template <> struct finite_max_helper<signed char> { static constexpr signed char value = SCHAR_MAX; };
83 template <> struct finite_max_helper<unsigned char> { static constexpr unsigned char value = UCHAR_MAX; };
84 template <> struct finite_max_helper<short> { static constexpr short value = SHRT_MAX; };
85 template <> struct finite_max_helper<unsigned short> { static constexpr unsigned short value = USHRT_MAX; };
86 template <> struct finite_max_helper<int> { static constexpr int value = INT_MAX; };
87 template <> struct finite_max_helper<unsigned int> { static constexpr unsigned int value = UINT_MAX; };
88 template <> struct finite_max_helper<long int> { static constexpr long int value = LONG_MAX; };
89 template <> struct finite_max_helper<unsigned long int> { static constexpr unsigned long int value = ULONG_MAX; };
90 template <> struct finite_max_helper<long long int> { static constexpr long long int value = LLONG_MAX; };
91 template <> struct finite_max_helper<unsigned long long int> { static constexpr unsigned long long int value = ULLONG_MAX; };
92 template <> struct finite_max_helper<float> { static constexpr float value = FLT_MAX; };
93 template <> struct finite_max_helper<double> { static constexpr double value = DBL_MAX; };
94 template <> struct finite_max_helper<long double> { static constexpr long double value = LDBL_MAX; };
95 template <class> struct epsilon_helper;
96 namespace{
97  // FIXME workaround for LDL_EPSILON with XL
98  template<typename T>
99  constexpr T machineeps() {
100  T epsilon = 1, prev = 1, expression = 1;
101  do {
102  prev = epsilon;
103  epsilon /= 2;
104  expression = 1 + epsilon;
105  } while (expression > 1);
106  return prev;
107  }
108 }
109 template <> struct epsilon_helper<float> { static constexpr float value = FLT_EPSILON; };
110 template <> struct epsilon_helper<double> { static constexpr double value = DBL_EPSILON; };
111 template <> struct epsilon_helper<long double> {
112 #ifdef KOKKOS_COMPILER_IBM
113  static constexpr long double value = machineeps<long double>();
114 #else
115  static constexpr long double value = LDBL_EPSILON;
116 #endif
117 };
118 template <class> struct round_error_helper;
119 template <> struct round_error_helper<float> { static constexpr float value = 0.5F; };
120 template <> struct round_error_helper<double> { static constexpr double value = 0.5; };
121 template <> struct round_error_helper<long double> { static constexpr long double value = 0.5L; };
122 template <class> struct norm_min_helper;
123 template <> struct norm_min_helper<float> { static constexpr float value = FLT_MIN; };
124 template <> struct norm_min_helper<double> { static constexpr double value = DBL_MIN; };
125 template <> struct norm_min_helper<long double> { static constexpr long double value = LDBL_MIN; };
126 template <class> struct digits_helper;
127 template <> struct digits_helper<bool> { static constexpr int value = 1; };
128 template <> struct digits_helper<char> { static constexpr int value = CHAR_BIT - std::is_signed<char>::value; };
129 template <> struct digits_helper<signed char> { static constexpr int value = CHAR_BIT - 1; };
130 template <> struct digits_helper<unsigned char> { static constexpr int value = CHAR_BIT; };
131 template <> struct digits_helper<short> { static constexpr int value = CHAR_BIT*sizeof(short)-1; };
132 template <> struct digits_helper<unsigned short> { static constexpr int value = CHAR_BIT*sizeof(short); };
133 template <> struct digits_helper<int> { static constexpr int value = CHAR_BIT*sizeof(int)-1; };
134 template <> struct digits_helper<unsigned int> { static constexpr int value = CHAR_BIT*sizeof(int); };
135 template <> struct digits_helper<long int> { static constexpr int value = CHAR_BIT*sizeof(long int)-1; };
136 template <> struct digits_helper<unsigned long int> { static constexpr int value = CHAR_BIT*sizeof(long int); };
137 template <> struct digits_helper<long long int> { static constexpr int value = CHAR_BIT*sizeof(long long int)-1; };
138 template <> struct digits_helper<unsigned long long int> { static constexpr int value = CHAR_BIT*sizeof(long long int); };
139 template <> struct digits_helper<float> { static constexpr int value = FLT_MANT_DIG; };
140 template <> struct digits_helper<double> { static constexpr int value = DBL_MANT_DIG; };
141 template <> struct digits_helper<long double> { static constexpr int value = LDBL_MANT_DIG; };
142 template <class> struct digits10_helper;
143 template <> struct digits10_helper<bool> { static constexpr int value = 0; };
144 constexpr double log10_2 = 2.41;
145 #define DIGITS10_HELPER_INTEGRAL(TYPE) \
146 template <> struct digits10_helper<TYPE> { static constexpr int value = digits_helper<TYPE>::value * log10_2; };
147 DIGITS10_HELPER_INTEGRAL(char)
148 DIGITS10_HELPER_INTEGRAL(signed char)
149 DIGITS10_HELPER_INTEGRAL(unsigned char)
150 DIGITS10_HELPER_INTEGRAL(short)
151 DIGITS10_HELPER_INTEGRAL(unsigned short)
152 DIGITS10_HELPER_INTEGRAL(int)
153 DIGITS10_HELPER_INTEGRAL(unsigned int)
154 DIGITS10_HELPER_INTEGRAL(long int)
155 DIGITS10_HELPER_INTEGRAL(unsigned long int)
156 DIGITS10_HELPER_INTEGRAL(long long int)
157 DIGITS10_HELPER_INTEGRAL(unsigned long long int)
158 #undef DIGITS10_HELPER_INTEGRAL
159 template <> struct digits10_helper<float> { static constexpr int value = FLT_DIG; };
160 template <> struct digits10_helper<double> { static constexpr int value = DBL_DIG; };
161 template <> struct digits10_helper<long double> { static constexpr int value = LDBL_DIG; };
162 template <class> struct max_digits10_helper;
163 // FIXME not sure why were not defined in my <cfloat>
164 //template <> struct max_digits10_helper<float> { static constexpr int value = FLT_DECIMAL_DIG; };
165 //template <> struct max_digits10_helper<double> { static constexpr int value = DBL_DECIMAL_DIG; };
166 //template <> struct max_digits10_helper<long double> { static constexpr int value = LDBL_DECIMAL_DIG; };
167 template <> struct max_digits10_helper<float> { static constexpr int value = 9; };
168 template <> struct max_digits10_helper<double> { static constexpr int value = 17; };
169 template <> struct max_digits10_helper<long double> { static constexpr int value = 21; };
170 template <class> struct radix_helper;
171 template <> struct radix_helper<bool> { static constexpr int value = 2; };
172 template <> struct radix_helper<char> { static constexpr int value = 2; };
173 template <> struct radix_helper<signed char> { static constexpr int value = 2; };
174 template <> struct radix_helper<unsigned char> { static constexpr int value = 2; };
175 template <> struct radix_helper<short> { static constexpr int value = 2; };
176 template <> struct radix_helper<unsigned short> { static constexpr int value = 2; };
177 template <> struct radix_helper<int> { static constexpr int value = 2; };
178 template <> struct radix_helper<unsigned int> { static constexpr int value = 2; };
179 template <> struct radix_helper<long int> { static constexpr int value = 2; };
180 template <> struct radix_helper<unsigned long int> { static constexpr int value = 2; };
181 template <> struct radix_helper<long long int> { static constexpr int value = 2; };
182 template <> struct radix_helper<unsigned long long int> { static constexpr int value = 2; };
183 template <> struct radix_helper<float> { static constexpr int value = FLT_RADIX; };
184 template <> struct radix_helper<double> { static constexpr int value = FLT_RADIX; };
185 template <> struct radix_helper<long double> { static constexpr int value = FLT_RADIX; };
186 template <class> struct min_exponent_helper;
187 template <> struct min_exponent_helper<float> { static constexpr int value = FLT_MIN_EXP; };
188 template <> struct min_exponent_helper<double> { static constexpr int value = DBL_MIN_EXP; };
189 template <> struct min_exponent_helper<long double> { static constexpr int value = LDBL_MIN_EXP; };
190 template <class> struct min_exponent10_helper;
191 template <> struct min_exponent10_helper<float> { static constexpr int value = FLT_MIN_10_EXP; };
192 template <> struct min_exponent10_helper<double> { static constexpr int value = DBL_MIN_10_EXP; };
193 template <> struct min_exponent10_helper<long double> { static constexpr int value = LDBL_MIN_10_EXP; };
194 template <class> struct max_exponent_helper;
195 template <> struct max_exponent_helper<float> { static constexpr int value = FLT_MAX_EXP; };
196 template <> struct max_exponent_helper<double> { static constexpr int value = DBL_MAX_EXP; };
197 template <> struct max_exponent_helper<long double> { static constexpr int value = LDBL_MAX_EXP; };
198 template <class> struct max_exponent10_helper;
199 template <> struct max_exponent10_helper<float> { static constexpr int value = FLT_MAX_10_EXP; };
200 template <> struct max_exponent10_helper<double> { static constexpr int value = DBL_MAX_10_EXP; };
201 template <> struct max_exponent10_helper<long double> { static constexpr int value = LDBL_MAX_10_EXP; };
202 // clang-format on
203 } // namespace Impl
204 
205 #if defined(KOKKOS_ENABLE_CXX17)
206 #define KOKKOS_IMPL_DEFINE_TRAIT(TRAIT) \
207  template <class T> \
208  struct TRAIT : Impl::TRAIT##_helper<T> {}; \
209  template <class T> \
210  inline constexpr auto TRAIT##_v = TRAIT<T>::value;
211 #else
212 #define KOKKOS_IMPL_DEFINE_TRAIT(TRAIT) \
213  template <class T> \
214  struct TRAIT : Impl::TRAIT##_helper<T> {};
215 #endif
216 
217 // Numeric distinguished value traits
218 KOKKOS_IMPL_DEFINE_TRAIT(infinity)
219 KOKKOS_IMPL_DEFINE_TRAIT(finite_min)
220 KOKKOS_IMPL_DEFINE_TRAIT(finite_max)
221 KOKKOS_IMPL_DEFINE_TRAIT(epsilon)
222 KOKKOS_IMPL_DEFINE_TRAIT(round_error)
223 KOKKOS_IMPL_DEFINE_TRAIT(norm_min)
224 
225 // Numeric characteristics traits
226 KOKKOS_IMPL_DEFINE_TRAIT(digits)
227 KOKKOS_IMPL_DEFINE_TRAIT(digits10)
228 KOKKOS_IMPL_DEFINE_TRAIT(max_digits10)
229 KOKKOS_IMPL_DEFINE_TRAIT(radix)
230 KOKKOS_IMPL_DEFINE_TRAIT(min_exponent)
231 KOKKOS_IMPL_DEFINE_TRAIT(min_exponent10)
232 KOKKOS_IMPL_DEFINE_TRAIT(max_exponent)
233 KOKKOS_IMPL_DEFINE_TRAIT(max_exponent10)
234 
235 #undef KOKKOS_IMPL_DEFINE_TRAIT
236 
237 } // namespace Experimental
238 
239 template <class T>
240 struct reduction_identity; /*{
241  KOKKOS_FORCEINLINE_FUNCTION constexpr static T sum() { return T(); } // 0
242  KOKKOS_FORCEINLINE_FUNCTION constexpr static T prod() // 1
243  { static_assert( false, "Missing specialization of
244 Kokkos::reduction_identity for custom prod reduction type"); return T(); }
245  KOKKOS_FORCEINLINE_FUNCTION constexpr static T max() // minimum value
246  { static_assert( false, "Missing specialization of
247 Kokkos::reduction_identity for custom max reduction type"); return T(); }
248  KOKKOS_FORCEINLINE_FUNCTION constexpr static T min() // maximum value
249  { static_assert( false, "Missing specialization of
250 Kokkos::reduction_identity for custom min reduction type"); return T(); }
251  KOKKOS_FORCEINLINE_FUNCTION constexpr static T bor() // 0, only for integer
252 type { static_assert( false, "Missing specialization of
253 Kokkos::reduction_identity for custom bor reduction type"); return T(); }
254  KOKKOS_FORCEINLINE_FUNCTION constexpr static T band() // !0, only for integer
255 type { static_assert( false, "Missing specialization of
256 Kokkos::reduction_identity for custom band reduction type"); return T(); }
257  KOKKOS_FORCEINLINE_FUNCTION constexpr static T lor() // 0, only for integer
258 type { static_assert( false, "Missing specialization of
259 Kokkos::reduction_identity for custom lor reduction type"); return T(); }
260  KOKKOS_FORCEINLINE_FUNCTION constexpr static T land() // !0, only for integer
261 type { static_assert( false, "Missing specialization of
262 Kokkos::reduction_identity for custom land reduction type"); return T(); }
263 };*/
264 
265 template <>
266 struct reduction_identity<signed char> {
267  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char sum() {
268  return static_cast<signed char>(0);
269  }
270  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char prod() {
271  return static_cast<signed char>(1);
272  }
273  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char max() {
274  return SCHAR_MIN;
275  }
276  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char min() {
277  return SCHAR_MAX;
278  }
279  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char bor() {
280  return static_cast<signed char>(0x0);
281  }
282  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char band() {
283  return ~static_cast<signed char>(0x0);
284  }
285  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char lor() {
286  return static_cast<signed char>(0);
287  }
288  KOKKOS_FORCEINLINE_FUNCTION constexpr static signed char land() {
289  return static_cast<signed char>(1);
290  }
291 };
292 
293 template <>
294 struct reduction_identity<short> {
295  KOKKOS_FORCEINLINE_FUNCTION constexpr static short sum() {
296  return static_cast<short>(0);
297  }
298  KOKKOS_FORCEINLINE_FUNCTION constexpr static short prod() {
299  return static_cast<short>(1);
300  }
301  KOKKOS_FORCEINLINE_FUNCTION constexpr static short max() { return SHRT_MIN; }
302  KOKKOS_FORCEINLINE_FUNCTION constexpr static short min() { return SHRT_MAX; }
303  KOKKOS_FORCEINLINE_FUNCTION constexpr static short bor() {
304  return static_cast<short>(0x0);
305  }
306  KOKKOS_FORCEINLINE_FUNCTION constexpr static short band() {
307  return ~static_cast<short>(0x0);
308  }
309  KOKKOS_FORCEINLINE_FUNCTION constexpr static short lor() {
310  return static_cast<short>(0);
311  }
312  KOKKOS_FORCEINLINE_FUNCTION constexpr static short land() {
313  return static_cast<short>(1);
314  }
315 };
316 
317 template <>
318 struct reduction_identity<int> {
319  KOKKOS_FORCEINLINE_FUNCTION constexpr static int sum() {
320  return static_cast<int>(0);
321  }
322  KOKKOS_FORCEINLINE_FUNCTION constexpr static int prod() {
323  return static_cast<int>(1);
324  }
325  KOKKOS_FORCEINLINE_FUNCTION constexpr static int max() { return INT_MIN; }
326  KOKKOS_FORCEINLINE_FUNCTION constexpr static int min() { return INT_MAX; }
327  KOKKOS_FORCEINLINE_FUNCTION constexpr static int bor() {
328  return static_cast<int>(0x0);
329  }
330  KOKKOS_FORCEINLINE_FUNCTION constexpr static int band() {
331  return ~static_cast<int>(0x0);
332  }
333  KOKKOS_FORCEINLINE_FUNCTION constexpr static int lor() {
334  return static_cast<int>(0);
335  }
336  KOKKOS_FORCEINLINE_FUNCTION constexpr static int land() {
337  return static_cast<int>(1);
338  }
339 };
340 
341 template <>
342 struct reduction_identity<long> {
343  KOKKOS_FORCEINLINE_FUNCTION constexpr static long sum() {
344  return static_cast<long>(0);
345  }
346  KOKKOS_FORCEINLINE_FUNCTION constexpr static long prod() {
347  return static_cast<long>(1);
348  }
349  KOKKOS_FORCEINLINE_FUNCTION constexpr static long max() { return LONG_MIN; }
350  KOKKOS_FORCEINLINE_FUNCTION constexpr static long min() { return LONG_MAX; }
351  KOKKOS_FORCEINLINE_FUNCTION constexpr static long bor() {
352  return static_cast<long>(0x0);
353  }
354  KOKKOS_FORCEINLINE_FUNCTION constexpr static long band() {
355  return ~static_cast<long>(0x0);
356  }
357  KOKKOS_FORCEINLINE_FUNCTION constexpr static long lor() {
358  return static_cast<long>(0);
359  }
360  KOKKOS_FORCEINLINE_FUNCTION constexpr static long land() {
361  return static_cast<long>(1);
362  }
363 };
364 
365 template <>
366 struct reduction_identity<long long> {
367  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long sum() {
368  return static_cast<long long>(0);
369  }
370  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long prod() {
371  return static_cast<long long>(1);
372  }
373  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long max() {
374  return LLONG_MIN;
375  }
376  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long min() {
377  return LLONG_MAX;
378  }
379  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long bor() {
380  return static_cast<long long>(0x0);
381  }
382  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long band() {
383  return ~static_cast<long long>(0x0);
384  }
385  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long lor() {
386  return static_cast<long long>(0);
387  }
388  KOKKOS_FORCEINLINE_FUNCTION constexpr static long long land() {
389  return static_cast<long long>(1);
390  }
391 };
392 
393 template <>
394 struct reduction_identity<unsigned char> {
395  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char sum() {
396  return static_cast<unsigned char>(0);
397  }
398  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char prod() {
399  return static_cast<unsigned char>(1);
400  }
401  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char max() {
402  return static_cast<unsigned char>(0);
403  }
404  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char min() {
405  return UCHAR_MAX;
406  }
407  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char bor() {
408  return static_cast<unsigned char>(0x0);
409  }
410  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char band() {
411  return ~static_cast<unsigned char>(0x0);
412  }
413  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char lor() {
414  return static_cast<unsigned char>(0);
415  }
416  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned char land() {
417  return static_cast<unsigned char>(1);
418  }
419 };
420 
421 template <>
422 struct reduction_identity<unsigned short> {
423  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short sum() {
424  return static_cast<unsigned short>(0);
425  }
426  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short prod() {
427  return static_cast<unsigned short>(1);
428  }
429  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short max() {
430  return static_cast<unsigned short>(0);
431  }
432  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short min() {
433  return USHRT_MAX;
434  }
435  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short bor() {
436  return static_cast<unsigned short>(0x0);
437  }
438  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short band() {
439  return ~static_cast<unsigned short>(0x0);
440  }
441  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short lor() {
442  return static_cast<unsigned short>(0);
443  }
444  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned short land() {
445  return static_cast<unsigned short>(1);
446  }
447 };
448 
449 template <>
450 struct reduction_identity<unsigned int> {
451  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int sum() {
452  return static_cast<unsigned int>(0);
453  }
454  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int prod() {
455  return static_cast<unsigned int>(1);
456  }
457  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int max() {
458  return static_cast<unsigned int>(0);
459  }
460  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int min() {
461  return UINT_MAX;
462  }
463  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int bor() {
464  return static_cast<unsigned int>(0x0);
465  }
466  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int band() {
467  return ~static_cast<unsigned int>(0x0);
468  }
469  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int lor() {
470  return static_cast<unsigned int>(0);
471  }
472  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned int land() {
473  return static_cast<unsigned int>(1);
474  }
475 };
476 
477 template <>
478 struct reduction_identity<unsigned long> {
479  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long sum() {
480  return static_cast<unsigned long>(0);
481  }
482  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long prod() {
483  return static_cast<unsigned long>(1);
484  }
485  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long max() {
486  return static_cast<unsigned long>(0);
487  }
488  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long min() {
489  return ULONG_MAX;
490  }
491  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long bor() {
492  return static_cast<unsigned long>(0x0);
493  }
494  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long band() {
495  return ~static_cast<unsigned long>(0x0);
496  }
497  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long lor() {
498  return static_cast<unsigned long>(0);
499  }
500  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long land() {
501  return static_cast<unsigned long>(1);
502  }
503 };
504 
505 template <>
506 struct reduction_identity<unsigned long long> {
507  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long sum() {
508  return static_cast<unsigned long long>(0);
509  }
510  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long prod() {
511  return static_cast<unsigned long long>(1);
512  }
513  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long max() {
514  return static_cast<unsigned long long>(0);
515  }
516  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long min() {
517  return ULLONG_MAX;
518  }
519  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long bor() {
520  return static_cast<unsigned long long>(0x0);
521  }
522  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long band() {
523  return ~static_cast<unsigned long long>(0x0);
524  }
525  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long lor() {
526  return static_cast<unsigned long long>(0);
527  }
528  KOKKOS_FORCEINLINE_FUNCTION constexpr static unsigned long long land() {
529  return static_cast<unsigned long long>(1);
530  }
531 };
532 
533 template <>
534 struct reduction_identity<float> {
535  KOKKOS_FORCEINLINE_FUNCTION constexpr static float sum() {
536  return static_cast<float>(0.0f);
537  }
538  KOKKOS_FORCEINLINE_FUNCTION constexpr static float prod() {
539  return static_cast<float>(1.0f);
540  }
541  KOKKOS_FORCEINLINE_FUNCTION constexpr static float max() { return -FLT_MAX; }
542  KOKKOS_FORCEINLINE_FUNCTION constexpr static float min() { return FLT_MAX; }
543 };
544 
545 template <>
546 struct reduction_identity<double> {
547  KOKKOS_FORCEINLINE_FUNCTION constexpr static double sum() {
548  return static_cast<double>(0.0);
549  }
550  KOKKOS_FORCEINLINE_FUNCTION constexpr static double prod() {
551  return static_cast<double>(1.0);
552  }
553  KOKKOS_FORCEINLINE_FUNCTION constexpr static double max() { return -DBL_MAX; }
554  KOKKOS_FORCEINLINE_FUNCTION constexpr static double min() { return DBL_MAX; }
555 };
556 
557 #if !defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_CUDA) && \
558  !defined(KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HIP_GPU)
559 template <>
560 struct reduction_identity<long double> {
561  KOKKOS_FORCEINLINE_FUNCTION constexpr static long double sum() {
562  return static_cast<long double>(0.0);
563  }
564  KOKKOS_FORCEINLINE_FUNCTION constexpr static long double prod() {
565  return static_cast<long double>(1.0);
566  }
567  KOKKOS_FORCEINLINE_FUNCTION constexpr static long double max() {
568  return -LDBL_MAX;
569  }
570  KOKKOS_FORCEINLINE_FUNCTION constexpr static long double min() {
571  return LDBL_MAX;
572  }
573 };
574 #endif
575 
576 } // namespace Kokkos
577 
578 #endif
Definition: dummy.cpp:3