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
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
43template <
class FloatType>
44class floating_point_wrapper;
48using half_t = Kokkos::Experimental::Impl::floating_point_wrapper<
49 Kokkos::Impl::half_impl_t ::type>;
51half_t cast_to_half(
float val);
53half_t cast_to_half(
bool val);
55half_t cast_to_half(
double val);
57half_t cast_to_half(
short val);
59half_t cast_to_half(
int val);
61half_t cast_to_half(
long val);
63half_t cast_to_half(
long long val);
65half_t cast_to_half(
unsigned short val);
67half_t cast_to_half(
unsigned int val);
69half_t cast_to_half(
unsigned long val);
71half_t cast_to_half(
unsigned long long val);
73half_t cast_to_half(half_t);
76KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, float>::value, T>
77 cast_from_half(half_t);
79KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, bool>::value, T>
80 cast_from_half(half_t);
82KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, double>::value, T>
83 cast_from_half(half_t);
85KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, short>::value, T>
86 cast_from_half(half_t);
88KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, int>::value, T>
89 cast_from_half(half_t);
91KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long>::value, T>
92 cast_from_half(half_t);
94KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long long>::value, T>
95 cast_from_half(half_t);
98 std::enable_if_t<std::is_same<T, unsigned short>::value, T>
99 cast_from_half(half_t);
101KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, unsigned int>::value, T>
102 cast_from_half(half_t);
104KOKKOS_INLINE_FUNCTION
105 std::enable_if_t<std::is_same<T, unsigned long>::value, T>
106 cast_from_half(half_t);
108KOKKOS_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
114using bhalf_t = Kokkos::Experimental::Impl::floating_point_wrapper<
115 Kokkos::Impl ::bhalf_impl_t ::type>;
117KOKKOS_INLINE_FUNCTION
118bhalf_t cast_to_bhalf(
float val);
119KOKKOS_INLINE_FUNCTION
120bhalf_t cast_to_bhalf(
bool val);
121KOKKOS_INLINE_FUNCTION
122bhalf_t cast_to_bhalf(
double val);
123KOKKOS_INLINE_FUNCTION
124bhalf_t cast_to_bhalf(
short val);
125KOKKOS_INLINE_FUNCTION
126bhalf_t cast_to_bhalf(
int val);
127KOKKOS_INLINE_FUNCTION
128bhalf_t cast_to_bhalf(
long val);
129KOKKOS_INLINE_FUNCTION
130bhalf_t cast_to_bhalf(
long long val);
131KOKKOS_INLINE_FUNCTION
132bhalf_t cast_to_bhalf(
unsigned short val);
133KOKKOS_INLINE_FUNCTION
134bhalf_t cast_to_bhalf(
unsigned int val);
135KOKKOS_INLINE_FUNCTION
136bhalf_t cast_to_bhalf(
unsigned long val);
137KOKKOS_INLINE_FUNCTION
138bhalf_t cast_to_bhalf(
unsigned long long val);
139KOKKOS_INLINE_FUNCTION
140bhalf_t cast_to_bhalf(bhalf_t val);
143KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, float>::value, T>
144 cast_from_bhalf(bhalf_t);
146KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, bool>::value, T>
147 cast_from_bhalf(bhalf_t);
149KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, double>::value, T>
150 cast_from_bhalf(bhalf_t);
152KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, short>::value, T>
153 cast_from_bhalf(bhalf_t);
155KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, int>::value, T>
156 cast_from_bhalf(bhalf_t);
158KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long>::value, T>
159 cast_from_bhalf(bhalf_t);
161KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, long long>::value, T>
162 cast_from_bhalf(bhalf_t);
164KOKKOS_INLINE_FUNCTION
165 std::enable_if_t<std::is_same<T, unsigned short>::value, T>
166 cast_from_bhalf(bhalf_t);
168KOKKOS_INLINE_FUNCTION std::enable_if_t<std::is_same<T, unsigned int>::value, T>
169 cast_from_bhalf(bhalf_t);
171KOKKOS_INLINE_FUNCTION
172 std::enable_if_t<std::is_same<T, unsigned long>::value, T>
173 cast_from_bhalf(bhalf_t);
175KOKKOS_INLINE_FUNCTION
176 std::enable_if_t<std::is_same<T, unsigned long long>::value, T>
177 cast_from_bhalf(bhalf_t);
181static 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
186static KOKKOS_INLINE_FUNCTION Kokkos::Experimental::bhalf_t cast_to_wrapper(
187 T x,
const volatile Kokkos::Impl::bhalf_impl_t::type&);
191static KOKKOS_INLINE_FUNCTION T
192cast_from_wrapper(
const Kokkos::Experimental::half_t& x);
194#ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED
196static KOKKOS_INLINE_FUNCTION T
197cast_from_wrapper(
const Kokkos::Experimental::bhalf_t& x);
202template <
class FloatType>
203class 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);
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) {
856static 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
863static 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);
870static KOKKOS_INLINE_FUNCTION T
871cast_from_wrapper(
const Kokkos::Experimental::half_t& x) {
872 return Kokkos::Experimental::cast_from_half<T>(x);
875#ifdef KOKKOS_IMPL_BHALF_TYPE_DEFINED
877static KOKKOS_INLINE_FUNCTION T
878cast_from_wrapper(
const Kokkos::Experimental::bhalf_t& x) {
879 return Kokkos::Experimental::cast_from_bhalf<T>(x);
890#ifndef KOKKOS_IMPL_HALF_TYPE_DEFINED
891#define KOKKOS_IMPL_HALF_TYPE_DEFINED
892#define KOKKOS_HALF_T_IS_FLOAT true
901using half_t = Kokkos::Impl::half_impl_t::type;
904KOKKOS_INLINE_FUNCTION
905half_t cast_to_half(
float val) {
return half_t(val); }
906KOKKOS_INLINE_FUNCTION
907half_t cast_to_half(
bool val) {
return half_t(val); }
908KOKKOS_INLINE_FUNCTION
909half_t cast_to_half(
double val) {
return half_t(val); }
910KOKKOS_INLINE_FUNCTION
911half_t cast_to_half(
short val) {
return half_t(val); }
912KOKKOS_INLINE_FUNCTION
913half_t cast_to_half(
unsigned short val) {
return half_t(val); }
914KOKKOS_INLINE_FUNCTION
915half_t cast_to_half(
int val) {
return half_t(val); }
916KOKKOS_INLINE_FUNCTION
917half_t cast_to_half(
unsigned int val) {
return half_t(val); }
918KOKKOS_INLINE_FUNCTION
919half_t cast_to_half(
long val) {
return half_t(val); }
920KOKKOS_INLINE_FUNCTION
921half_t cast_to_half(
unsigned long val) {
return half_t(val); }
922KOKKOS_INLINE_FUNCTION
923half_t cast_to_half(
long long val) {
return half_t(val); }
924KOKKOS_INLINE_FUNCTION
925half_t cast_to_half(
unsigned long long val) {
return half_t(val); }
931KOKKOS_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,
940cast_from_half(half_t val) {
948#define KOKKOS_HALF_T_IS_FLOAT false
951#ifndef KOKKOS_IMPL_BHALF_TYPE_DEFINED
952#define KOKKOS_IMPL_BHALF_TYPE_DEFINED
953#define KOKKOS_BHALF_T_IS_FLOAT true
963using bhalf_t = Kokkos::Impl::bhalf_impl_t::type;
966KOKKOS_INLINE_FUNCTION
967bhalf_t cast_to_bhalf(
float val) {
return bhalf_t(val); }
968KOKKOS_INLINE_FUNCTION
969bhalf_t cast_to_bhalf(
bool val) {
return bhalf_t(val); }
970KOKKOS_INLINE_FUNCTION
971bhalf_t cast_to_bhalf(
double val) {
return bhalf_t(val); }
972KOKKOS_INLINE_FUNCTION
973bhalf_t cast_to_bhalf(
short val) {
return bhalf_t(val); }
974KOKKOS_INLINE_FUNCTION
975bhalf_t cast_to_bhalf(
unsigned short val) {
return bhalf_t(val); }
976KOKKOS_INLINE_FUNCTION
977bhalf_t cast_to_bhalf(
int val) {
return bhalf_t(val); }
978KOKKOS_INLINE_FUNCTION
979bhalf_t cast_to_bhalf(
unsigned int val) {
return bhalf_t(val); }
980KOKKOS_INLINE_FUNCTION
981bhalf_t cast_to_bhalf(
long val) {
return bhalf_t(val); }
982KOKKOS_INLINE_FUNCTION
983bhalf_t cast_to_bhalf(
unsigned long val) {
return bhalf_t(val); }
984KOKKOS_INLINE_FUNCTION
985bhalf_t cast_to_bhalf(
long long val) {
return bhalf_t(val); }
986KOKKOS_INLINE_FUNCTION
987bhalf_t cast_to_bhalf(
unsigned long long val) {
return bhalf_t(val); }
991KOKKOS_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,
1000cast_from_bhalf(bhalf_t val) {
1006#define KOKKOS_BHALF_T_IS_FLOAT false
1008#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_HALF
1009#undef KOKKOS_IMPL_PUBLIC_INCLUDE
1010#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_HALF
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.