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
55namespace Kokkos {
56namespace Experimental {
57namespace Impl {
58// clang-format off
59template <class> struct infinity_helper;
60template <> struct infinity_helper<float> { static constexpr float value = HUGE_VALF; };
61template <> struct infinity_helper<double> { static constexpr double value = HUGE_VAL; };
62template <> struct infinity_helper<long double> { static constexpr long double value = HUGE_VALL; };
63template <class> struct finite_min_helper;
64template <> struct finite_min_helper<bool> { static constexpr bool value = false; };
65template <> struct finite_min_helper<char> { static constexpr char value = CHAR_MIN; };
66template <> struct finite_min_helper<signed char> { static constexpr signed char value = SCHAR_MIN; };
67template <> struct finite_min_helper<unsigned char> { static constexpr unsigned char value = 0; };
68template <> struct finite_min_helper<short> { static constexpr short value = SHRT_MIN; };
69template <> struct finite_min_helper<unsigned short> { static constexpr unsigned short value = 0; };
70template <> struct finite_min_helper<int> { static constexpr int value = INT_MIN; };
71template <> struct finite_min_helper<unsigned int> { static constexpr unsigned int value = 0; };
72template <> struct finite_min_helper<long int> { static constexpr long int value = LONG_MIN; };
73template <> struct finite_min_helper<unsigned long int> { static constexpr unsigned long int value = 0; };
74template <> struct finite_min_helper<long long int> { static constexpr long long int value = LLONG_MIN; };
75template <> struct finite_min_helper<unsigned long long int> { static constexpr unsigned long long int value = 0; };
76template <> struct finite_min_helper<float> { static constexpr float value = -FLT_MAX; };
77template <> struct finite_min_helper<double> { static constexpr double value = -DBL_MAX; };
78template <> struct finite_min_helper<long double> { static constexpr long double value = -LDBL_MAX; };
79template <class> struct finite_max_helper;
80template <> struct finite_max_helper<bool> { static constexpr bool value = true; };
81template <> struct finite_max_helper<char> { static constexpr char value = CHAR_MAX; };
82template <> struct finite_max_helper<signed char> { static constexpr signed char value = SCHAR_MAX; };
83template <> struct finite_max_helper<unsigned char> { static constexpr unsigned char value = UCHAR_MAX; };
84template <> struct finite_max_helper<short> { static constexpr short value = SHRT_MAX; };
85template <> struct finite_max_helper<unsigned short> { static constexpr unsigned short value = USHRT_MAX; };
86template <> struct finite_max_helper<int> { static constexpr int value = INT_MAX; };
87template <> struct finite_max_helper<unsigned int> { static constexpr unsigned int value = UINT_MAX; };
88template <> struct finite_max_helper<long int> { static constexpr long int value = LONG_MAX; };
89template <> struct finite_max_helper<unsigned long int> { static constexpr unsigned long int value = ULONG_MAX; };
90template <> struct finite_max_helper<long long int> { static constexpr long long int value = LLONG_MAX; };
91template <> struct finite_max_helper<unsigned long long int> { static constexpr unsigned long long int value = ULLONG_MAX; };
92template <> struct finite_max_helper<float> { static constexpr float value = FLT_MAX; };
93template <> struct finite_max_helper<double> { static constexpr double value = DBL_MAX; };
94template <> struct finite_max_helper<long double> { static constexpr long double value = LDBL_MAX; };
95template <class> struct epsilon_helper;
96namespace{
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}
109template <> struct epsilon_helper<float> { static constexpr float value = FLT_EPSILON; };
110template <> struct epsilon_helper<double> { static constexpr double value = DBL_EPSILON; };
111template <> 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};
118template <class> struct round_error_helper;
119template <> struct round_error_helper<float> { static constexpr float value = 0.5F; };
120template <> struct round_error_helper<double> { static constexpr double value = 0.5; };
121template <> struct round_error_helper<long double> { static constexpr long double value = 0.5L; };
122template <class> struct norm_min_helper;
123template <> struct norm_min_helper<float> { static constexpr float value = FLT_MIN; };
124template <> struct norm_min_helper<double> { static constexpr double value = DBL_MIN; };
125template <> struct norm_min_helper<long double> { static constexpr long double value = LDBL_MIN; };
126template <class> struct digits_helper;
127template <> struct digits_helper<bool> { static constexpr int value = 1; };
128template <> struct digits_helper<char> { static constexpr int value = CHAR_BIT - std::is_signed<char>::value; };
129template <> struct digits_helper<signed char> { static constexpr int value = CHAR_BIT - 1; };
130template <> struct digits_helper<unsigned char> { static constexpr int value = CHAR_BIT; };
131template <> struct digits_helper<short> { static constexpr int value = CHAR_BIT*sizeof(short)-1; };
132template <> struct digits_helper<unsigned short> { static constexpr int value = CHAR_BIT*sizeof(short); };
133template <> struct digits_helper<int> { static constexpr int value = CHAR_BIT*sizeof(int)-1; };
134template <> struct digits_helper<unsigned int> { static constexpr int value = CHAR_BIT*sizeof(int); };
135template <> struct digits_helper<long int> { static constexpr int value = CHAR_BIT*sizeof(long int)-1; };
136template <> struct digits_helper<unsigned long int> { static constexpr int value = CHAR_BIT*sizeof(long int); };
137template <> struct digits_helper<long long int> { static constexpr int value = CHAR_BIT*sizeof(long long int)-1; };
138template <> struct digits_helper<unsigned long long int> { static constexpr int value = CHAR_BIT*sizeof(long long int); };
139template <> struct digits_helper<float> { static constexpr int value = FLT_MANT_DIG; };
140template <> struct digits_helper<double> { static constexpr int value = DBL_MANT_DIG; };
141template <> struct digits_helper<long double> { static constexpr int value = LDBL_MANT_DIG; };
142template <class> struct digits10_helper;
143template <> struct digits10_helper<bool> { static constexpr int value = 0; };
144constexpr double log10_2 = 2.41;
145#define DIGITS10_HELPER_INTEGRAL(TYPE) \
146template <> struct digits10_helper<TYPE> { static constexpr int value = digits_helper<TYPE>::value * log10_2; };
147DIGITS10_HELPER_INTEGRAL(char)
148DIGITS10_HELPER_INTEGRAL(signed char)
149DIGITS10_HELPER_INTEGRAL(unsigned char)
150DIGITS10_HELPER_INTEGRAL(short)
151DIGITS10_HELPER_INTEGRAL(unsigned short)
152DIGITS10_HELPER_INTEGRAL(int)
153DIGITS10_HELPER_INTEGRAL(unsigned int)
154DIGITS10_HELPER_INTEGRAL(long int)
155DIGITS10_HELPER_INTEGRAL(unsigned long int)
156DIGITS10_HELPER_INTEGRAL(long long int)
157DIGITS10_HELPER_INTEGRAL(unsigned long long int)
158#undef DIGITS10_HELPER_INTEGRAL
159template <> struct digits10_helper<float> { static constexpr int value = FLT_DIG; };
160template <> struct digits10_helper<double> { static constexpr int value = DBL_DIG; };
161template <> struct digits10_helper<long double> { static constexpr int value = LDBL_DIG; };
162template <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; };
167template <> struct max_digits10_helper<float> { static constexpr int value = 9; };
168template <> struct max_digits10_helper<double> { static constexpr int value = 17; };
169template <> struct max_digits10_helper<long double> { static constexpr int value = 21; };
170template <class> struct radix_helper;
171template <> struct radix_helper<bool> { static constexpr int value = 2; };
172template <> struct radix_helper<char> { static constexpr int value = 2; };
173template <> struct radix_helper<signed char> { static constexpr int value = 2; };
174template <> struct radix_helper<unsigned char> { static constexpr int value = 2; };
175template <> struct radix_helper<short> { static constexpr int value = 2; };
176template <> struct radix_helper<unsigned short> { static constexpr int value = 2; };
177template <> struct radix_helper<int> { static constexpr int value = 2; };
178template <> struct radix_helper<unsigned int> { static constexpr int value = 2; };
179template <> struct radix_helper<long int> { static constexpr int value = 2; };
180template <> struct radix_helper<unsigned long int> { static constexpr int value = 2; };
181template <> struct radix_helper<long long int> { static constexpr int value = 2; };
182template <> struct radix_helper<unsigned long long int> { static constexpr int value = 2; };
183template <> struct radix_helper<float> { static constexpr int value = FLT_RADIX; };
184template <> struct radix_helper<double> { static constexpr int value = FLT_RADIX; };
185template <> struct radix_helper<long double> { static constexpr int value = FLT_RADIX; };
186template <class> struct min_exponent_helper;
187template <> struct min_exponent_helper<float> { static constexpr int value = FLT_MIN_EXP; };
188template <> struct min_exponent_helper<double> { static constexpr int value = DBL_MIN_EXP; };
189template <> struct min_exponent_helper<long double> { static constexpr int value = LDBL_MIN_EXP; };
190template <class> struct min_exponent10_helper;
191template <> struct min_exponent10_helper<float> { static constexpr int value = FLT_MIN_10_EXP; };
192template <> struct min_exponent10_helper<double> { static constexpr int value = DBL_MIN_10_EXP; };
193template <> struct min_exponent10_helper<long double> { static constexpr int value = LDBL_MIN_10_EXP; };
194template <class> struct max_exponent_helper;
195template <> struct max_exponent_helper<float> { static constexpr int value = FLT_MAX_EXP; };
196template <> struct max_exponent_helper<double> { static constexpr int value = DBL_MAX_EXP; };
197template <> struct max_exponent_helper<long double> { static constexpr int value = LDBL_MAX_EXP; };
198template <class> struct max_exponent10_helper;
199template <> struct max_exponent10_helper<float> { static constexpr int value = FLT_MAX_10_EXP; };
200template <> struct max_exponent10_helper<double> { static constexpr int value = DBL_MAX_10_EXP; };
201template <> 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
218KOKKOS_IMPL_DEFINE_TRAIT(infinity)
219KOKKOS_IMPL_DEFINE_TRAIT(finite_min)
220KOKKOS_IMPL_DEFINE_TRAIT(finite_max)
221KOKKOS_IMPL_DEFINE_TRAIT(epsilon)
222KOKKOS_IMPL_DEFINE_TRAIT(round_error)
223KOKKOS_IMPL_DEFINE_TRAIT(norm_min)
224
225// Numeric characteristics traits
226KOKKOS_IMPL_DEFINE_TRAIT(digits)
227KOKKOS_IMPL_DEFINE_TRAIT(digits10)
228KOKKOS_IMPL_DEFINE_TRAIT(max_digits10)
229KOKKOS_IMPL_DEFINE_TRAIT(radix)
230KOKKOS_IMPL_DEFINE_TRAIT(min_exponent)
231KOKKOS_IMPL_DEFINE_TRAIT(min_exponent10)
232KOKKOS_IMPL_DEFINE_TRAIT(max_exponent)
233KOKKOS_IMPL_DEFINE_TRAIT(max_exponent10)
234
235#undef KOKKOS_IMPL_DEFINE_TRAIT
236
237} // namespace Experimental
238
239template <class T>
240struct 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
244Kokkos::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
247Kokkos::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
250Kokkos::reduction_identity for custom min reduction type"); return T(); }
251 KOKKOS_FORCEINLINE_FUNCTION constexpr static T bor() // 0, only for integer
252type { static_assert( false, "Missing specialization of
253Kokkos::reduction_identity for custom bor reduction type"); return T(); }
254 KOKKOS_FORCEINLINE_FUNCTION constexpr static T band() // !0, only for integer
255type { static_assert( false, "Missing specialization of
256Kokkos::reduction_identity for custom band reduction type"); return T(); }
257 KOKKOS_FORCEINLINE_FUNCTION constexpr static T lor() // 0, only for integer
258type { static_assert( false, "Missing specialization of
259Kokkos::reduction_identity for custom lor reduction type"); return T(); }
260 KOKKOS_FORCEINLINE_FUNCTION constexpr static T land() // !0, only for integer
261type { static_assert( false, "Missing specialization of
262Kokkos::reduction_identity for custom land reduction type"); return T(); }
263};*/
264
265template <>
266struct 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
293template <>
294struct 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
317template <>
318struct 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
341template <>
342struct 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
365template <>
366struct 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
393template <>
394struct 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
421template <>
422struct 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
449template <>
450struct 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
477template <>
478struct 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
505template <>
506struct 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
533template <>
534struct 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
545template <>
546struct 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)
559template <>
560struct 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