17 #ifndef KOKKOS_HALF_HPP_ 18 #define KOKKOS_HALF_HPP_ 19 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE 20 #define KOKKOS_IMPL_PUBLIC_INCLUDE 21 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_HALF 24 #include <type_traits> 25 #include <Kokkos_Macros.hpp> 29 #ifdef KOKKOS_IMPL_HALF_TYPE_DEFINED 35 #if defined(__CUDA_ARCH__) || defined(KOKKOS_ENABLE_SYCL) 36 #define KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 43 template <
class FloatType>
44 class floating_point_wrapper;
48 using half_t = Kokkos::Experimental::Impl::floating_point_wrapper<
49 Kokkos::Impl::half_impl_t ::type>;
50 KOKKOS_INLINE_FUNCTION
51 half_t cast_to_half(
float val);
52 KOKKOS_INLINE_FUNCTION
53 half_t cast_to_half(
bool val);
54 KOKKOS_INLINE_FUNCTION
55 half_t cast_to_half(
double val);
56 KOKKOS_INLINE_FUNCTION
57 half_t cast_to_half(
short val);
58 KOKKOS_INLINE_FUNCTION
59 half_t cast_to_half(
int val);
60 KOKKOS_INLINE_FUNCTION
61 half_t cast_to_half(
long val);
62 KOKKOS_INLINE_FUNCTION
63 half_t cast_to_half(
long long val);
64 KOKKOS_INLINE_FUNCTION
65 half_t cast_to_half(
unsigned short val);
66 KOKKOS_INLINE_FUNCTION
67 half_t cast_to_half(
unsigned int val);
68 KOKKOS_INLINE_FUNCTION
69 half_t cast_to_half(
unsigned long val);
70 KOKKOS_INLINE_FUNCTION
71 half_t cast_to_half(
unsigned long long val);
72 KOKKOS_INLINE_FUNCTION
73 half_t cast_to_half(half_t);
76 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, float>::value, T>
77 cast_from_half(half_t);
79 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, bool>::value, T>
80 cast_from_half(half_t);
82 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, double>::value, T>
83 cast_from_half(half_t);
85 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, short>::value, T>
86 cast_from_half(half_t);
88 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, int>::value, T>
89 cast_from_half(half_t);
91 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long>::value, T>
92 cast_from_half(half_t);
94 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long long>::value, T>
95 cast_from_half(half_t);
97 KOKKOS_INLINE_FUNCTION
98 std::enable_if_t<std::is_same<T, unsigned short>::value, T>
99 cast_from_half(half_t);
101 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, unsigned int>::value, T>
102 cast_from_half(half_t);
104 KOKKOS_INLINE_FUNCTION
105 std::enable_if_t<std::is_same<T, unsigned long>::value, T>
106 cast_from_half(half_t);
108 KOKKOS_INLINE_FUNCTION
109 std::enable_if_t<std::is_same<T, unsigned long long>::value, T>
110 cast_from_half(half_t);
113 #ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED 114 using bhalf_t = Kokkos::Experimental::Impl::floating_point_wrapper<
115 Kokkos::Impl ::bhalf_impl_t ::type>;
117 KOKKOS_INLINE_FUNCTION
118 bhalf_t cast_to_bhalf(
float val);
119 KOKKOS_INLINE_FUNCTION
120 bhalf_t cast_to_bhalf(
bool val);
121 KOKKOS_INLINE_FUNCTION
122 bhalf_t cast_to_bhalf(
double val);
123 KOKKOS_INLINE_FUNCTION
124 bhalf_t cast_to_bhalf(
short val);
125 KOKKOS_INLINE_FUNCTION
126 bhalf_t cast_to_bhalf(
int val);
127 KOKKOS_INLINE_FUNCTION
128 bhalf_t cast_to_bhalf(
long val);
129 KOKKOS_INLINE_FUNCTION
130 bhalf_t cast_to_bhalf(
long long val);
131 KOKKOS_INLINE_FUNCTION
132 bhalf_t cast_to_bhalf(
unsigned short val);
133 KOKKOS_INLINE_FUNCTION
134 bhalf_t cast_to_bhalf(
unsigned int val);
135 KOKKOS_INLINE_FUNCTION
136 bhalf_t cast_to_bhalf(
unsigned long val);
137 KOKKOS_INLINE_FUNCTION
138 bhalf_t cast_to_bhalf(
unsigned long long val);
139 KOKKOS_INLINE_FUNCTION
140 bhalf_t cast_to_bhalf(bhalf_t val);
143 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, float>::value, T>
144 cast_from_bhalf(bhalf_t);
146 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, bool>::value, T>
147 cast_from_bhalf(bhalf_t);
149 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, double>::value, T>
150 cast_from_bhalf(bhalf_t);
152 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, short>::value, T>
153 cast_from_bhalf(bhalf_t);
155 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, int>::value, T>
156 cast_from_bhalf(bhalf_t);
158 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long>::value, T>
159 cast_from_bhalf(bhalf_t);
161 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long long>::value, T>
162 cast_from_bhalf(bhalf_t);
164 KOKKOS_INLINE_FUNCTION
165 std::enable_if_t<std::is_same<T, unsigned short>::value, T>
166 cast_from_bhalf(bhalf_t);
168 KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, unsigned int>::value, T>
169 cast_from_bhalf(bhalf_t);
171 KOKKOS_INLINE_FUNCTION
172 std::enable_if_t<std::is_same<T, unsigned long>::value, T>
173 cast_from_bhalf(bhalf_t);
175 KOKKOS_INLINE_FUNCTION
176 std::enable_if_t<std::is_same<T, unsigned long long>::value, T>
177 cast_from_bhalf(bhalf_t);
178 #endif // KOKKOS_IMPL_BHALF_TYPE_DEFINED 181 static KOKKOS_INLINE_FUNCTION Kokkos::Experimental::half_t cast_to_wrapper(
182 T x,
const volatile Kokkos::Impl::half_impl_t::type&);
184 #ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED 186 static KOKKOS_INLINE_FUNCTION Kokkos::Experimental::bhalf_t cast_to_wrapper(
187 T x,
const volatile Kokkos::Impl::bhalf_impl_t::type&);
188 #endif // KOKKOS_IMPL_BHALF_TYPE_DEFINED 191 static KOKKOS_INLINE_FUNCTION T
192 cast_from_wrapper(
const Kokkos::Experimental::half_t& x);
194 #ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED 196 static KOKKOS_INLINE_FUNCTION T
197 cast_from_wrapper(
const Kokkos::Experimental::bhalf_t& x);
198 #endif // KOKKOS_IMPL_BHALF_TYPE_DEFINED 202 template <
class FloatType>
203 class alignas(FloatType) floating_point_wrapper {
205 using impl_type = FloatType;
209 using fixed_width_integer_type = std::conditional_t<
210 sizeof(impl_type) == 2, uint16_t,
212 sizeof(impl_type) == 4, uint32_t,
213 std::conditional_t<sizeof(impl_type) == 8, uint64_t, void>>>;
214 static_assert(!std::is_void<fixed_width_integer_type>::value,
215 "Invalid impl_type");
221 floating_point_wrapper() : val(0.0F) {}
226 #if defined(_WIN32) && defined(KOKKOS_ENABLE_CUDA) 228 floating_point_wrapper(
const floating_point_wrapper& rhs) : val(rhs.val) {}
230 KOKKOS_DEFAULTED_FUNCTION
231 floating_point_wrapper(
const floating_point_wrapper&) noexcept =
default;
234 KOKKOS_INLINE_FUNCTION
235 floating_point_wrapper(
const volatile floating_point_wrapper& rhs) {
236 #if defined(KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH) && !defined(KOKKOS_ENABLE_SYCL) 239 const volatile fixed_width_integer_type* rv_ptr =
240 reinterpret_cast<const volatile fixed_width_integer_type*
>(&rhs.val);
241 const fixed_width_integer_type rv_val = *rv_ptr;
242 val =
reinterpret_cast<const impl_type&
>(rv_val);
243 #endif // KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 249 explicit operator impl_type()
const {
return val; }
251 explicit operator float()
const {
return cast_from_wrapper<float>(*this); }
253 explicit operator bool()
const {
return cast_from_wrapper<bool>(*this); }
255 explicit operator double()
const {
return cast_from_wrapper<double>(*this); }
257 explicit operator short()
const {
return cast_from_wrapper<short>(*this); }
259 explicit operator int()
const {
return cast_from_wrapper<int>(*this); }
261 explicit operator long()
const {
return cast_from_wrapper<long>(*this); }
263 explicit operator long long()
const {
264 return cast_from_wrapper<long long>(*this);
267 explicit operator unsigned short()
const {
268 return cast_from_wrapper<unsigned short>(*this);
271 explicit operator unsigned int()
const {
272 return cast_from_wrapper<unsigned int>(*this);
275 explicit operator unsigned long()
const {
276 return cast_from_wrapper<unsigned long>(*this);
279 explicit operator unsigned long long()
const {
280 return cast_from_wrapper<unsigned long long>(*this);
298 constexpr floating_point_wrapper(impl_type rhs) : val(rhs) {}
300 floating_point_wrapper(
float rhs) : val(cast_to_wrapper(rhs, val).val) {}
302 floating_point_wrapper(
double rhs) : val(cast_to_wrapper(rhs, val).val) {}
304 explicit floating_point_wrapper(
bool rhs)
305 : val(cast_to_wrapper(rhs, val).val) {}
307 floating_point_wrapper(
short rhs) : val(cast_to_wrapper(rhs, val).val) {}
309 floating_point_wrapper(
int rhs) : val(cast_to_wrapper(rhs, val).val) {}
311 floating_point_wrapper(
long rhs) : val(cast_to_wrapper(rhs, val).val) {}
313 floating_point_wrapper(
long long rhs) : val(cast_to_wrapper(rhs, val).val) {}
315 floating_point_wrapper(
unsigned short rhs)
316 : val(cast_to_wrapper(rhs, val).val) {}
318 floating_point_wrapper(
unsigned int rhs)
319 : val(cast_to_wrapper(rhs, val).val) {}
321 floating_point_wrapper(
unsigned long rhs)
322 : val(cast_to_wrapper(rhs, val).val) {}
324 floating_point_wrapper(
unsigned long long rhs)
325 : val(cast_to_wrapper(rhs, val).val) {}
329 floating_point_wrapper operator+()
const {
330 floating_point_wrapper tmp = *
this;
331 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 334 tmp.val = cast_to_wrapper(+cast_from_wrapper<float>(tmp), val).val;
340 floating_point_wrapper operator-()
const {
341 floating_point_wrapper tmp = *
this;
342 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 345 tmp.val = cast_to_wrapper(-cast_from_wrapper<float>(tmp), val).val;
352 floating_point_wrapper& operator++() {
353 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 354 val = val + impl_type(1.0F);
356 float tmp = cast_from_wrapper<float>(*this);
358 val = cast_to_wrapper(tmp, val).val;
364 floating_point_wrapper& operator--() {
365 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 366 val = val - impl_type(1.0F);
368 float tmp = cast_from_wrapper<float>(*this);
370 val = cast_to_wrapper(tmp, val).val;
377 floating_point_wrapper operator++(
int) {
378 floating_point_wrapper tmp = *
this;
384 floating_point_wrapper operator--(
int) {
385 floating_point_wrapper tmp = *
this;
392 floating_point_wrapper& operator=(impl_type rhs) {
398 KOKKOS_FUNCTION floating_point_wrapper& operator=(T rhs) {
399 val = cast_to_wrapper(rhs, val).val;
404 KOKKOS_FUNCTION
void operator=(T rhs)
volatile {
405 impl_type new_val = cast_to_wrapper(rhs, val).val;
406 volatile fixed_width_integer_type* val_ptr =
407 reinterpret_cast<volatile fixed_width_integer_type*
>(
408 const_cast<impl_type*
>(&val));
409 *val_ptr =
reinterpret_cast<fixed_width_integer_type&
>(new_val);
414 floating_point_wrapper& operator+=(floating_point_wrapper rhs) {
415 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 418 val = cast_to_wrapper(
419 cast_from_wrapper<float>(*
this) + cast_from_wrapper<float>(rhs),
427 void operator+=(
const volatile floating_point_wrapper& rhs)
volatile {
428 floating_point_wrapper tmp_rhs = rhs;
429 floating_point_wrapper tmp_lhs = *
this;
437 KOKKOS_FUNCTION
friend std::enable_if_t<
438 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
439 operator+=(T& lhs, floating_point_wrapper rhs) {
440 lhs +=
static_cast<T
>(rhs);
445 floating_point_wrapper& operator+=(
float rhs) {
446 float result =
static_cast<float>(val) + rhs;
447 val =
static_cast<impl_type
>(result);
452 floating_point_wrapper& operator+=(
double rhs) {
453 double result =
static_cast<double>(val) + rhs;
454 val =
static_cast<impl_type
>(result);
459 floating_point_wrapper& operator-=(floating_point_wrapper rhs) {
460 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 463 val = cast_to_wrapper(
464 cast_from_wrapper<float>(*
this) - cast_from_wrapper<float>(rhs),
472 void operator-=(
const volatile floating_point_wrapper& rhs)
volatile {
473 floating_point_wrapper tmp_rhs = rhs;
474 floating_point_wrapper tmp_lhs = *
this;
482 KOKKOS_FUNCTION
friend std::enable_if_t<
483 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
484 operator-=(T& lhs, floating_point_wrapper rhs) {
485 lhs -=
static_cast<T
>(rhs);
490 floating_point_wrapper& operator-=(
float rhs) {
491 float result =
static_cast<float>(val) - rhs;
492 val =
static_cast<impl_type
>(result);
497 floating_point_wrapper& operator-=(
double rhs) {
498 double result =
static_cast<double>(val) - rhs;
499 val =
static_cast<impl_type
>(result);
504 floating_point_wrapper& operator*=(floating_point_wrapper rhs) {
505 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 508 val = cast_to_wrapper(
509 cast_from_wrapper<float>(*
this) * cast_from_wrapper<float>(rhs),
517 void operator*=(
const volatile floating_point_wrapper& rhs)
volatile {
518 floating_point_wrapper tmp_rhs = rhs;
519 floating_point_wrapper tmp_lhs = *
this;
527 KOKKOS_FUNCTION
friend std::enable_if_t<
528 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
529 operator*=(T& lhs, floating_point_wrapper rhs) {
530 lhs *=
static_cast<T
>(rhs);
535 floating_point_wrapper& operator*=(
float rhs) {
536 float result =
static_cast<float>(val) * rhs;
537 val =
static_cast<impl_type
>(result);
542 floating_point_wrapper& operator*=(
double rhs) {
543 double result =
static_cast<double>(val) * rhs;
544 val =
static_cast<impl_type
>(result);
549 floating_point_wrapper& operator/=(floating_point_wrapper rhs) {
550 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 553 val = cast_to_wrapper(
554 cast_from_wrapper<float>(*
this) / cast_from_wrapper<float>(rhs),
562 void operator/=(
const volatile floating_point_wrapper& rhs)
volatile {
563 floating_point_wrapper tmp_rhs = rhs;
564 floating_point_wrapper tmp_lhs = *
this;
572 KOKKOS_FUNCTION
friend std::enable_if_t<
573 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
574 operator/=(T& lhs, floating_point_wrapper rhs) {
575 lhs /=
static_cast<T
>(rhs);
580 floating_point_wrapper& operator/=(
float rhs) {
581 float result =
static_cast<float>(val) / rhs;
582 val =
static_cast<impl_type
>(result);
587 floating_point_wrapper& operator/=(
double rhs) {
588 double result =
static_cast<double>(val) / rhs;
589 val =
static_cast<impl_type
>(result);
595 friend floating_point_wrapper operator+(floating_point_wrapper lhs,
596 floating_point_wrapper rhs) {
597 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 600 lhs.val = cast_to_wrapper(
601 cast_from_wrapper<float>(lhs) + cast_from_wrapper<float>(rhs),
610 KOKKOS_FUNCTION
friend std::enable_if_t<
611 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
612 operator+(floating_point_wrapper lhs, T rhs) {
617 KOKKOS_FUNCTION
friend std::enable_if_t<
618 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
619 operator+(T lhs, floating_point_wrapper rhs) {
624 friend floating_point_wrapper operator-(floating_point_wrapper lhs,
625 floating_point_wrapper rhs) {
626 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 629 lhs.val = cast_to_wrapper(
630 cast_from_wrapper<float>(lhs) - cast_from_wrapper<float>(rhs),
639 KOKKOS_FUNCTION
friend std::enable_if_t<
640 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
641 operator-(floating_point_wrapper lhs, T rhs) {
646 KOKKOS_FUNCTION
friend std::enable_if_t<
647 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
648 operator-(T lhs, floating_point_wrapper rhs) {
653 friend floating_point_wrapper operator*(floating_point_wrapper lhs,
654 floating_point_wrapper rhs) {
655 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 658 lhs.val = cast_to_wrapper(
659 cast_from_wrapper<float>(lhs) * cast_from_wrapper<float>(rhs),
668 KOKKOS_FUNCTION
friend std::enable_if_t<
669 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
670 operator*(floating_point_wrapper lhs, T rhs) {
675 KOKKOS_FUNCTION
friend std::enable_if_t<
676 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
677 operator*(T lhs, floating_point_wrapper rhs) {
682 friend floating_point_wrapper operator/(floating_point_wrapper lhs,
683 floating_point_wrapper rhs) {
684 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 687 lhs.val = cast_to_wrapper(
688 cast_from_wrapper<float>(lhs) / cast_from_wrapper<float>(rhs),
697 KOKKOS_FUNCTION
friend std::enable_if_t<
698 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
699 operator/(floating_point_wrapper lhs, T rhs) {
704 KOKKOS_FUNCTION
friend std::enable_if_t<
705 std::is_same<T, float>::value || std::is_same<T, double>::value, T>
706 operator/(T lhs, floating_point_wrapper rhs) {
712 bool operator!()
const {
713 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 714 return static_cast<bool>(!val);
716 return !cast_from_wrapper<float>(*this);
722 bool operator&&(floating_point_wrapper rhs)
const {
723 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 724 return static_cast<bool>(val && rhs.val);
726 return cast_from_wrapper<float>(*this) && cast_from_wrapper<float>(rhs);
732 bool operator||(floating_point_wrapper rhs)
const {
733 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 734 return static_cast<bool>(val || rhs.val);
736 return cast_from_wrapper<float>(*this) || cast_from_wrapper<float>(rhs);
742 bool operator==(floating_point_wrapper rhs)
const {
743 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 744 return static_cast<bool>(val == rhs.val);
746 return cast_from_wrapper<float>(*this) == cast_from_wrapper<float>(rhs);
751 bool operator!=(floating_point_wrapper rhs)
const {
752 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 753 return static_cast<bool>(val != rhs.val);
755 return cast_from_wrapper<float>(*this) != cast_from_wrapper<float>(rhs);
760 bool operator<(floating_point_wrapper rhs)
const {
761 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 762 return static_cast<bool>(val < rhs.val);
764 return cast_from_wrapper<float>(*this) < cast_from_wrapper<float>(rhs);
769 bool operator>(floating_point_wrapper rhs)
const {
770 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 771 return static_cast<bool>(val > rhs.val);
773 return cast_from_wrapper<float>(*this) > cast_from_wrapper<float>(rhs);
778 bool operator<=(floating_point_wrapper rhs)
const {
779 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 780 return static_cast<bool>(val <= rhs.val);
782 return cast_from_wrapper<float>(*this) <= cast_from_wrapper<float>(rhs);
787 bool operator>=(floating_point_wrapper rhs)
const {
788 #ifdef KOKKOS_HALF_IS_FULL_TYPE_ON_ARCH 789 return static_cast<bool>(val >= rhs.val);
791 return cast_from_wrapper<float>(*this) >= cast_from_wrapper<float>(rhs);
796 friend bool operator==(
const volatile floating_point_wrapper& lhs,
797 const volatile floating_point_wrapper& rhs) {
798 floating_point_wrapper tmp_lhs = lhs, tmp_rhs = rhs;
799 return tmp_lhs == tmp_rhs;
803 friend bool operator!=(
const volatile floating_point_wrapper& lhs,
804 const volatile floating_point_wrapper& rhs) {
805 floating_point_wrapper tmp_lhs = lhs, tmp_rhs = rhs;
806 return tmp_lhs != tmp_rhs;
810 friend bool operator<(
const volatile floating_point_wrapper& lhs,
811 const volatile floating_point_wrapper& rhs) {
812 floating_point_wrapper tmp_lhs = lhs, tmp_rhs = rhs;
813 return tmp_lhs < tmp_rhs;
817 friend bool operator>(
const volatile floating_point_wrapper& lhs,
818 const volatile floating_point_wrapper& rhs) {
819 floating_point_wrapper tmp_lhs = lhs, tmp_rhs = rhs;
820 return tmp_lhs > tmp_rhs;
824 friend bool operator<=(
const volatile floating_point_wrapper& lhs,
825 const volatile floating_point_wrapper& rhs) {
826 floating_point_wrapper tmp_lhs = lhs, tmp_rhs = rhs;
827 return tmp_lhs <= tmp_rhs;
831 friend bool operator>=(
const volatile floating_point_wrapper& lhs,
832 const volatile floating_point_wrapper& rhs) {
833 floating_point_wrapper tmp_lhs = lhs, tmp_rhs = rhs;
834 return tmp_lhs >= tmp_rhs;
838 friend std::ostream& operator<<(std::ostream& os,
839 const floating_point_wrapper& x) {
840 const std::string out = std::to_string(static_cast<double>(x));
845 friend std::istream& operator>>(std::istream& is, floating_point_wrapper& x) {
856 static KOKKOS_INLINE_FUNCTION Kokkos::Experimental::half_t cast_to_wrapper(
857 T x,
const volatile Kokkos::Impl::half_impl_t::type&) {
858 return Kokkos::Experimental::cast_to_half(x);
861 #ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED 863 static KOKKOS_INLINE_FUNCTION Kokkos::Experimental::bhalf_t cast_to_wrapper(
864 T x,
const volatile Kokkos::Impl::bhalf_impl_t::type&) {
865 return Kokkos::Experimental::cast_to_bhalf(x);
867 #endif // KOKKOS_IMPL_BHALF_TYPE_DEFINED 870 static KOKKOS_INLINE_FUNCTION T
871 cast_from_wrapper(
const Kokkos::Experimental::half_t& x) {
872 return Kokkos::Experimental::cast_from_half<T>(x);
875 #ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED 877 static KOKKOS_INLINE_FUNCTION T
878 cast_from_wrapper(
const Kokkos::Experimental::bhalf_t& x) {
879 return Kokkos::Experimental::cast_from_bhalf<T>(x);
881 #endif // KOKKOS_IMPL_BHALF_TYPE_DEFINED 886 #endif // KOKKOS_IMPL_HALF_TYPE_DEFINED 890 #ifndef KOKKOS_IMPL_HALF_TYPE_DEFINED 891 #define KOKKOS_IMPL_HALF_TYPE_DEFINED 892 #define KOKKOS_HALF_T_IS_FLOAT true 901 using half_t = Kokkos::Impl::half_impl_t::type;
904 KOKKOS_INLINE_FUNCTION
905 half_t cast_to_half(
float val) {
return half_t(val); }
906 KOKKOS_INLINE_FUNCTION
907 half_t cast_to_half(
bool val) {
return half_t(val); }
908 KOKKOS_INLINE_FUNCTION
909 half_t cast_to_half(
double val) {
return half_t(val); }
910 KOKKOS_INLINE_FUNCTION
911 half_t cast_to_half(
short val) {
return half_t(val); }
912 KOKKOS_INLINE_FUNCTION
913 half_t cast_to_half(
unsigned short val) {
return half_t(val); }
914 KOKKOS_INLINE_FUNCTION
915 half_t cast_to_half(
int val) {
return half_t(val); }
916 KOKKOS_INLINE_FUNCTION
917 half_t cast_to_half(
unsigned int val) {
return half_t(val); }
918 KOKKOS_INLINE_FUNCTION
919 half_t cast_to_half(
long val) {
return half_t(val); }
920 KOKKOS_INLINE_FUNCTION
921 half_t cast_to_half(
unsigned long val) {
return half_t(val); }
922 KOKKOS_INLINE_FUNCTION
923 half_t cast_to_half(
long long val) {
return half_t(val); }
924 KOKKOS_INLINE_FUNCTION
925 half_t cast_to_half(
unsigned long long val) {
return half_t(val); }
931 KOKKOS_INLINE_FUNCTION std::enable_if_t<
932 std::is_same<T, float>::value || std::is_same<T, bool>::value ||
933 std::is_same<T, double>::value || std::is_same<T, short>::value ||
934 std::is_same<T, unsigned short>::value || std::is_same<T, int>::value ||
935 std::is_same<T, unsigned int>::value || std::is_same<T, long>::value ||
936 std::is_same<T, unsigned long>::value ||
937 std::is_same<T, long long>::value ||
938 std::is_same<T, unsigned long long>::value,
940 cast_from_half(half_t val) {
948 #define KOKKOS_HALF_T_IS_FLOAT false 949 #endif // KOKKOS_IMPL_HALF_TYPE_DEFINED 951 #ifndef KOKKOS_IMPL_BHALF_TYPE_DEFINED 952 #define KOKKOS_IMPL_BHALF_TYPE_DEFINED 953 #define KOKKOS_BHALF_T_IS_FLOAT true 956 struct bhalf_impl_t {
963 using bhalf_t = Kokkos::Impl::bhalf_impl_t::type;
966 KOKKOS_INLINE_FUNCTION
967 bhalf_t cast_to_bhalf(
float val) {
return bhalf_t(val); }
968 KOKKOS_INLINE_FUNCTION
969 bhalf_t cast_to_bhalf(
bool val) {
return bhalf_t(val); }
970 KOKKOS_INLINE_FUNCTION
971 bhalf_t cast_to_bhalf(
double val) {
return bhalf_t(val); }
972 KOKKOS_INLINE_FUNCTION
973 bhalf_t cast_to_bhalf(
short val) {
return bhalf_t(val); }
974 KOKKOS_INLINE_FUNCTION
975 bhalf_t cast_to_bhalf(
unsigned short val) {
return bhalf_t(val); }
976 KOKKOS_INLINE_FUNCTION
977 bhalf_t cast_to_bhalf(
int val) {
return bhalf_t(val); }
978 KOKKOS_INLINE_FUNCTION
979 bhalf_t cast_to_bhalf(
unsigned int val) {
return bhalf_t(val); }
980 KOKKOS_INLINE_FUNCTION
981 bhalf_t cast_to_bhalf(
long val) {
return bhalf_t(val); }
982 KOKKOS_INLINE_FUNCTION
983 bhalf_t cast_to_bhalf(
unsigned long val) {
return bhalf_t(val); }
984 KOKKOS_INLINE_FUNCTION
985 bhalf_t cast_to_bhalf(
long long val) {
return bhalf_t(val); }
986 KOKKOS_INLINE_FUNCTION
987 bhalf_t cast_to_bhalf(
unsigned long long val) {
return bhalf_t(val); }
991 KOKKOS_INLINE_FUNCTION std::enable_if_t<
992 std::is_same<T, float>::value || std::is_same<T, bool>::value ||
993 std::is_same<T, double>::value || std::is_same<T, short>::value ||
994 std::is_same<T, unsigned short>::value || std::is_same<T, int>::value ||
995 std::is_same<T, unsigned int>::value || std::is_same<T, long>::value ||
996 std::is_same<T, unsigned long>::value ||
997 std::is_same<T, long long>::value ||
998 std::is_same<T, unsigned long long>::value,
1000 cast_from_bhalf(bhalf_t val) {
1006 #define KOKKOS_BHALF_T_IS_FLOAT false 1007 #endif // KOKKOS_IMPL_BHALF_TYPE_DEFINED 1008 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_HALF 1009 #undef KOKKOS_IMPL_PUBLIC_INCLUDE 1010 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_HALF 1012 #endif // KOKKOS_HALF_HPP_
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Less-than operator for Kokkos::pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator<=(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Less-than-or-equal-to operator for Kokkos::pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>=(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Greater-than-or-equal-to operator for Kokkos::pair.
KOKKOS_FORCEINLINE_FUNCTION constexpr bool operator>(const pair< T1, T2 > &lhs, const pair< T1, T2 > &rhs)
Greater-than operator for Kokkos::pair.