39#include "../../InternalHeaderCheck.h"
49#if defined(EIGEN_HAS_GPU_FP16) || defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC) || defined(EIGEN_HAS_BUILTIN_FLOAT16)
50#define _EIGEN_MAYBE_CONSTEXPR
52#define _EIGEN_MAYBE_CONSTEXPR constexpr
55#define F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, METHOD) \
57 EIGEN_UNUSED EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC PACKET_F16 METHOD<PACKET_F16>(const PACKET_F16& _x) { \
58 return float2half(METHOD<PACKET_F>(half2float(_x))); \
61#define EIGEN_INSTANTIATE_GENERIC_MATH_FUNCS_F16(PACKET_F, PACKET_F16) \
62 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pcos) \
63 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, psin) \
64 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, psinh) \
65 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pcosh) \
66 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pasinh) \
67 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pacosh) \
68 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pexp) \
69 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pexp2) \
70 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pexpm1) \
71 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, plog) \
72 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, plog1p) \
73 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, plog2) \
74 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, plog10) \
75 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, preciprocal) \
76 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, prsqrt) \
77 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pcbrt) \
78 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, psqrt) \
79 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, ptanh)
82#define EIGEN_INSTANTIATE_SPECIAL_FUNCS_F16(PACKET_F, PACKET_F16) \
83 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, perf) \
84 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pndtri)
86#define EIGEN_INSTANTIATE_BESSEL_FUNCS_F16(PACKET_F, PACKET_F16) \
87 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_i0) \
88 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_i0e) \
89 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_i1) \
90 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_i1e) \
91 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_j0) \
92 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_j1) \
93 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_k0) \
94 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_k0e) \
95 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_k1) \
96 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_k1e) \
97 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_y0) \
98 F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, pbessel_y1)
125#if !defined(EIGEN_GPUCC) || !defined(EIGEN_GPU_COMPILE_PHASE)
129 struct construct_from_rep_tag {};
130#if (defined(EIGEN_GPUCC) && !defined(EIGEN_GPU_COMPILE_PHASE))
136 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR __half_raw() {}
138 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR __half_raw() : x(0) {}
145#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
146 explicit EIGEN_DEVICE_FUNC __half_raw(numext::uint16_t raw) : x(numext::bit_cast<__fp16>(raw)) {}
147 EIGEN_DEVICE_FUNC
constexpr __half_raw(construct_from_rep_tag, __fp16 rep) : x{rep} {}
149#elif defined(EIGEN_HAS_BUILTIN_FLOAT16)
150 explicit EIGEN_DEVICE_FUNC __half_raw(numext::uint16_t raw) : x(numext::bit_cast<_Float16>(raw)) {}
151 EIGEN_DEVICE_FUNC
constexpr __half_raw(construct_from_rep_tag, _Float16 rep) : x{rep} {}
154 explicit EIGEN_DEVICE_FUNC
constexpr __half_raw(numext::uint16_t raw) : x(raw) {}
155 EIGEN_DEVICE_FUNC
constexpr __half_raw(construct_from_rep_tag, numext::uint16_t rep) : x{rep} {}
156#if EIGEN_HAS_ARM64_FP16
157 EIGEN_DEVICE_FUNC __half_raw(construct_from_rep_tag, __fp16 rep) : x(numext::bit_cast<numext::uint16_t>(rep)) {}
163#elif defined(EIGEN_HIPCC)
166#elif defined(EIGEN_CUDACC)
170#elif defined(EIGEN_SYCL_DEVICE_ONLY)
171using __half_raw = cl::sycl::half;
174EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR __half_raw raw_uint16_to_half(numext::uint16_t x);
175EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC numext::uint16_t raw_half_as_uint16(
const __half_raw& h);
176template <
bool AssumeArgumentIsNormalOrInfinityOrZero = false>
177EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne(
float ff);
179EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne<false>(
float ff);
181EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne<true>(
float ff);
182EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
float half_to_float(__half_raw h);
191struct narrow_to_float_path
192 : std::integral_constant<int, std::is_floating_point<T>::value ? (sizeof(T) > sizeof(float) ? 1 : 0)
193 : !std::is_integral<T>::value || std::numeric_limits<T>::digits <= 24 ? 0
194 : std::numeric_limits<T>::digits <= 32 ? 2
195 : std::numeric_limits<T>::digits <= 64 ? 3
198template <typename T, int Path = narrow_to_float_path<T>::value>
199struct narrow_to_float_impl {
200 EIGEN_DEVICE_FUNC static float run(const T& val) { return static_cast<float>(val); }
203struct narrow_to_float_impl<T, 1> {
204 EIGEN_DEVICE_FUNC static float run(const T& val) {
205 const float f = static_cast<float>(val);
206 if (static_cast<T>(f) == val || (numext::isnan)(val)) return f;
208 const bool away = numext::abs(static_cast<T>(f)) > numext::abs(val);
209 return numext::bit_cast<float>((numext::bit_cast<numext::uint32_t>(f) - (away ? 1u : 0u)) | 1u);
215struct narrow_to_float_impl<T, 2> {
216 EIGEN_DEVICE_FUNC static float run(const T& val) {
217 using U = std::make_unsigned_t<T>;
218 const U u = static_cast<U>(val);
220 const U odd = (u & ~low) | ((u & low) != 0 ? U(0x100) : U(0));
221 const U magnitude = std::is_signed<T>::value && (u >> (sizeof(U) * CHAR_BIT - 1)) ? U(0) - u : u;
222 return static_cast<float>(magnitude >= (U(1) << 24) ? numext::bit_cast<T>(odd) : val);
226struct narrow_to_float_impl<T, 3> {
227 EIGEN_DEVICE_FUNC static float run(const T& val) {
228 using U = std::make_unsigned_t<T>;
229 const U u = static_cast<U>(val);
231 const U odd = (u & ~low) | ((u & low) != 0 ? U(0x800) : U(0));
232 const U magnitude = std::is_signed<T>::value && (u >> (sizeof(U) * CHAR_BIT - 1)) ? U(0) - u : u;
233 return narrow_to_float_impl<double>::run(
234 static_cast<double>(magnitude >= (U(1) << 53) ? numext::bit_cast<T>(odd) : val));
238EIGEN_DEVICE_FUNC inline float narrow_to_float(const T& val) {
239 return narrow_to_float_impl<T>::run(val);
242struct half_base : public __half_raw {
243 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half_base() {}
244 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half_base(const __half_raw& h) : __half_raw(h) {}
246#if defined(EIGEN_GPUCC)
247#if defined(EIGEN_HIPCC)
253 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half_base(const __half& h)
254 : __half_raw(raw_uint16_to_half(numext::bit_cast<numext::uint16_t>(h))) {}
255#elif defined(EIGEN_CUDACC)
256 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half_base(const __half& h) : __half_raw(*(__half_raw*)&h) {}
264struct half : public half_impl::half_base {
267#if !defined(EIGEN_GPUCC) || !defined(EIGEN_GPU_COMPILE_PHASE)
271 using __half_raw = half_impl::__half_raw;
272#elif defined(EIGEN_HIPCC)
275#elif defined(EIGEN_CUDACC)
279 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half() {}
281 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half(const __half_raw& h) : half_impl::half_base(h) {}
283#if defined(EIGEN_GPUCC)
284#if defined(EIGEN_HIPCC)
285 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half(const __half& h) : half_impl::half_base(h) {}
286#elif defined(EIGEN_CUDACC)
287 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half(const __half& h) : half_impl::half_base(h) {}
293#if EIGEN_HAS_ARM64_FP16 && !defined(EIGEN_GPU_COMPILE_PHASE)
294 explicit EIGEN_DEVICE_FUNC half(__fp16 b) : half(__half_raw(__half_raw::construct_from_rep_tag(), b)) {}
295#elif defined(EIGEN_HAS_BUILTIN_FLOAT16) && !defined(EIGEN_GPU_COMPILE_PHASE)
296 explicit EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half(_Float16 b)
297 : half(__half_raw(__half_raw::construct_from_rep_tag(), b)) {}
300 explicit EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR half(bool b)
301 : half_impl::half_base(half_impl::raw_uint16_to_half(b ? 0x3c00 : 0)) {}
302 template <class T, std::enable_if_t<!std::is_integral<T>::value, int> = 0>
303 explicit EIGEN_DEVICE_FUNC half(T val)
304 : half_impl::half_base(half_impl::float_to_half_rtne<false>(half_impl::narrow_to_float(val))) {}
306 template <class T, std::enable_if_t<std::is_integral<T>::value, int> = 0>
307 explicit EIGEN_DEVICE_FUNC half(T val)
308 : half_impl::half_base(half_impl::float_to_half_rtne<true>(static_cast<float>(val))) {}
309 explicit EIGEN_DEVICE_FUNC half(float f) : half_impl::half_base(half_impl::float_to_half_rtne<false>(f)) {}
313 template <typename RealScalar>
314 explicit EIGEN_DEVICE_FUNC half(std::complex<RealScalar> c)
315 : half_impl::half_base(half_impl::float_to_half_rtne<false>(half_impl::narrow_to_float(c.real()))) {}
317 EIGEN_DEVICE_FUNC operator float() const {
318 return half_impl::half_to_float(*this);
321#if defined(EIGEN_HAS_GPU_FP16) && !defined(EIGEN_GPU_COMPILE_PHASE)
322 EIGEN_DEVICE_FUNC operator __half() const {
327 hr.x = half_impl::raw_half_as_uint16(*this);
336template <typename = void>
337struct numeric_limits_half_impl {
338 static constexpr const bool is_specialized = true;
339 static constexpr const bool is_signed = true;
340 static constexpr const bool is_integer = false;
341 static constexpr const bool is_exact = false;
342 static constexpr const bool has_infinity = true;
343 static constexpr const bool has_quiet_NaN = true;
344 static constexpr const bool has_signaling_NaN = true;
345 EIGEN_DIAGNOSTICS(push)
346 EIGEN_DISABLE_DEPRECATED_WARNING
347 static constexpr const std::float_denorm_style has_denorm = std::denorm_present;
348 static constexpr const bool has_denorm_loss = false;
349 EIGEN_DIAGNOSTICS(pop)
350 static constexpr const std::float_round_style round_style = std::round_to_nearest;
351 static constexpr const bool is_iec559 = true;
354 static constexpr const bool is_bounded = true;
355 static constexpr const bool is_modulo = false;
356 static constexpr const int digits = 11;
357 static constexpr const int digits10 =
359 static constexpr const int max_digits10 =
361 static constexpr const int radix = std::numeric_limits<float>::radix;
362 static constexpr const int min_exponent = -13;
363 static constexpr const int min_exponent10 = -4;
364 static constexpr const int max_exponent = 16;
365 static constexpr const int max_exponent10 = 4;
366 static constexpr const bool traps = std::numeric_limits<float>::traps;
369 static constexpr const bool tinyness_before = std::numeric_limits<float>::tinyness_before;
371 static _EIGEN_MAYBE_CONSTEXPR Eigen::half(min)() { return Eigen::half_impl::raw_uint16_to_half(0x0400); }
372 static _EIGEN_MAYBE_CONSTEXPR Eigen::half lowest() { return Eigen::half_impl::raw_uint16_to_half(0xfbff); }
373 static _EIGEN_MAYBE_CONSTEXPR Eigen::half(max)() { return Eigen::half_impl::raw_uint16_to_half(0x7bff); }
374 static _EIGEN_MAYBE_CONSTEXPR Eigen::half epsilon() { return Eigen::half_impl::raw_uint16_to_half(0x1400); }
375 static _EIGEN_MAYBE_CONSTEXPR Eigen::half round_error() { return Eigen::half_impl::raw_uint16_to_half(0x3800); }
376 static _EIGEN_MAYBE_CONSTEXPR Eigen::half infinity() { return Eigen::half_impl::raw_uint16_to_half(0x7c00); }
377 static _EIGEN_MAYBE_CONSTEXPR Eigen::half quiet_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7e00); }
378 static _EIGEN_MAYBE_CONSTEXPR Eigen::half signaling_NaN() { return Eigen::half_impl::raw_uint16_to_half(0x7d00); }
379 static _EIGEN_MAYBE_CONSTEXPR Eigen::half denorm_min() { return Eigen::half_impl::raw_uint16_to_half(0x0001); }
383#if EIGEN_COMP_CXXVER < 17
385constexpr const bool numeric_limits_half_impl<T>::is_specialized;
387constexpr const bool numeric_limits_half_impl<T>::is_signed;
389constexpr const bool numeric_limits_half_impl<T>::is_integer;
391constexpr const bool numeric_limits_half_impl<T>::is_exact;
393constexpr const bool numeric_limits_half_impl<T>::has_infinity;
395constexpr const bool numeric_limits_half_impl<T>::has_quiet_NaN;
397constexpr const bool numeric_limits_half_impl<T>::has_signaling_NaN;
398EIGEN_DIAGNOSTICS(push)
399EIGEN_DISABLE_DEPRECATED_WARNING
401constexpr const std::float_denorm_style numeric_limits_half_impl<T>::has_denorm;
403constexpr const bool numeric_limits_half_impl<T>::has_denorm_loss;
404EIGEN_DIAGNOSTICS(pop)
406constexpr const std::float_round_style numeric_limits_half_impl<T>::round_style;
408constexpr const bool numeric_limits_half_impl<T>::is_iec559;
410constexpr const bool numeric_limits_half_impl<T>::is_bounded;
412constexpr const bool numeric_limits_half_impl<T>::is_modulo;
414constexpr const int numeric_limits_half_impl<T>::digits;
416constexpr const int numeric_limits_half_impl<T>::digits10;
418constexpr const int numeric_limits_half_impl<T>::max_digits10;
420constexpr const int numeric_limits_half_impl<T>::radix;
422constexpr const int numeric_limits_half_impl<T>::min_exponent;
424constexpr const int numeric_limits_half_impl<T>::min_exponent10;
426constexpr const int numeric_limits_half_impl<T>::max_exponent;
428constexpr const int numeric_limits_half_impl<T>::max_exponent10;
430constexpr const bool numeric_limits_half_impl<T>::traps;
432constexpr const bool numeric_limits_half_impl<T>::tinyness_before;
443class numeric_limits<Eigen::half> : public Eigen::half_impl::numeric_limits_half_impl<> {};
445class numeric_limits<const Eigen::half> : public numeric_limits<Eigen::half> {};
447class numeric_limits<volatile Eigen::half> : public numeric_limits<Eigen::half> {};
449class numeric_limits<const volatile Eigen::half> : public numeric_limits<Eigen::half> {};
456#if (defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || defined(EIGEN_HIP_DEVICE_COMPILE)
459#define EIGEN_HAS_NATIVE_GPU_FP16
467#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
468EIGEN_STRONG_INLINE __device__ half operator+(const half& a, const half& b) { return __hadd(::__half(a), ::__half(b)); }
469EIGEN_STRONG_INLINE __device__ half operator*(const half& a, const half& b) { return __hmul(a, b); }
470EIGEN_STRONG_INLINE __device__ half operator-(const half& a, const half& b) { return __hsub(a, b); }
471EIGEN_STRONG_INLINE __device__ half operator/(const half& a, const half& b) { return __hdiv(a, b); }
472EIGEN_STRONG_INLINE __device__ half operator-(const half& a) { return __hneg(a); }
473EIGEN_STRONG_INLINE __device__ half& operator+=(half& a, const half& b) {
477EIGEN_STRONG_INLINE __device__ half& operator*=(half& a, const half& b) {
481EIGEN_STRONG_INLINE __device__ half& operator-=(half& a, const half& b) {
485EIGEN_STRONG_INLINE __device__ half& operator/=(half& a, const half& b) {
489EIGEN_STRONG_INLINE __device__ bool operator==(const half& a, const half& b) { return __heq(a, b); }
491EIGEN_STRONG_INLINE __device__ bool operator!=(const half& a, const half& b) { return !__heq(a, b); }
492EIGEN_STRONG_INLINE __device__ bool operator<(const half& a, const half& b) { return __hlt(a, b); }
493EIGEN_STRONG_INLINE __device__ bool operator<=(const half& a, const half& b) { return __hle(a, b); }
494EIGEN_STRONG_INLINE __device__ bool operator>(const half& a, const half& b) { return __hgt(a, b); }
495EIGEN_STRONG_INLINE __device__ bool operator>=(const half& a, const half& b) { return __hge(a, b); }
499#if (EIGEN_HAS_ARM64_FP16 || defined(EIGEN_HAS_BUILTIN_FLOAT16)) && !defined(EIGEN_GPU_COMPILE_PHASE)
500#if EIGEN_HAS_ARM64_FP16
501using native_half_t = __fp16;
503using native_half_t = _Float16;
507EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC native_half_t native_half(const __half_raw& h) {
508 return numext::bit_cast<native_half_t>(h.x);
516EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half half_from_rep(native_half_t rep) {
517 return half(__half_raw(__half_raw::construct_from_rep_tag(), rep));
521#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC) && !defined(EIGEN_GPU_COMPILE_PHASE)
522EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator+(const half& a, const half& b) {
523 return half_from_rep(vaddh_f16(a.x, b.x));
525EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator*(const half& a, const half& b) {
526 return half_from_rep(vmulh_f16(a.x, b.x));
528EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a, const half& b) {
529 return half_from_rep(vsubh_f16(a.x, b.x));
531EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator/(const half& a, const half& b) {
532 return half_from_rep(vdivh_f16(a.x, b.x));
534EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a) { return half_from_rep(vnegh_f16(a.x)); }
535EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator+=(half& a, const half& b) {
536 a = half_from_rep(vaddh_f16(a.x, b.x));
539EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator*=(half& a, const half& b) {
540 a = half_from_rep(vmulh_f16(a.x, b.x));
543EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator-=(half& a, const half& b) {
544 a = half_from_rep(vsubh_f16(a.x, b.x));
547EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator/=(half& a, const half& b) {
548 a = half_from_rep(vdivh_f16(a.x, b.x));
551EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator==(const half& a, const half& b) { return vceqh_f16(a.x, b.x); }
552EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator!=(const half& a, const half& b) { return !vceqh_f16(a.x, b.x); }
553EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<(const half& a, const half& b) { return vclth_f16(a.x, b.x); }
554EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<=(const half& a, const half& b) { return vcleh_f16(a.x, b.x); }
555EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const half& a, const half& b) { return vcgth_f16(a.x, b.x); }
556EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>=(const half& a, const half& b) { return vcgeh_f16(a.x, b.x); }
558#elif (EIGEN_HAS_ARM64_FP16 || defined(EIGEN_HAS_BUILTIN_FLOAT16)) && !defined(EIGEN_GPU_COMPILE_PHASE)
566#pragma clang diagnostic push
567#pragma clang diagnostic ignored "-Wdouble-promotion"
570EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator+(const half& a, const half& b) {
571 return half_from_rep(static_cast<native_half_t>(native_half(a) + native_half(b)));
573EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator*(const half& a, const half& b) {
574 return half_from_rep(static_cast<native_half_t>(native_half(a) * native_half(b)));
576EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a, const half& b) {
577 return half_from_rep(static_cast<native_half_t>(native_half(a) - native_half(b)));
579EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator/(const half& a, const half& b) {
580 return half_from_rep(static_cast<native_half_t>(native_half(a) / native_half(b)));
582EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a) {
583 return half_from_rep(static_cast<native_half_t>(-native_half(a)));
585EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator+=(half& a, const half& b) {
589EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator*=(half& a, const half& b) {
593EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator-=(half& a, const half& b) {
597EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator/=(half& a, const half& b) {
601EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator==(const half& a, const half& b) {
602 return native_half(a) == native_half(b);
604EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator!=(const half& a, const half& b) {
605 return native_half(a) != native_half(b);
607EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<(const half& a, const half& b) {
608 return native_half(a) < native_half(b);
610EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<=(const half& a, const half& b) {
611 return native_half(a) <= native_half(b);
613EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const half& a, const half& b) {
614 return native_half(a) > native_half(b);
616EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>=(const half& a, const half& b) {
617 return native_half(a) >= native_half(b);
621#pragma clang diagnostic pop
627#elif !defined(EIGEN_HAS_NATIVE_GPU_FP16) || (EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
629#if EIGEN_COMP_CLANG && defined(EIGEN_GPUCC)
631#pragma push_macro("EIGEN_DEVICE_FUNC")
632#undef EIGEN_DEVICE_FUNC
633#if defined(EIGEN_GPUCC) && defined(EIGEN_HAS_NATIVE_GPU_FP16)
634#define EIGEN_DEVICE_FUNC __host__
636#define EIGEN_DEVICE_FUNC __host__ __device__
642EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator+(const half& a, const half& b) { return half(float(a) + float(b)); }
643EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator*(const half& a, const half& b) { return half(float(a) * float(b)); }
644EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a, const half& b) { return half(float(a) - float(b)); }
645EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator/(const half& a, const half& b) { return half(float(a) / float(b)); }
646EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator-(const half& a) {
647 return raw_uint16_to_half(static_cast<numext::uint16_t>(raw_half_as_uint16(a) ^ 0x8000));
649EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator+=(half& a, const half& b) {
650 a = half(float(a) + float(b));
653EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator*=(half& a, const half& b) {
654 a = half(float(a) * float(b));
657EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator-=(half& a, const half& b) {
658 a = half(float(a) - float(b));
661EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator/=(half& a, const half& b) {
662 a = half(float(a) / float(b));
679EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC int16_t mapToSigned(uint16_t a) {
682 EIGEN_OPTIMIZATION_BARRIER(a)
684 constexpr uint16_t kAbsMask = (1 << 15) - 1;
686 return (a >> 15) ? -(a & kAbsMask) : a;
688EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool isOrdered(const half& a, const half& b) {
689 constexpr uint16_t kInf = ((1 << 5) - 1) << 10;
690 constexpr uint16_t kAbsMask = (1 << 15) - 1;
691 return numext::maxi(a.x & kAbsMask, b.x & kAbsMask) <= kInf;
693EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator==(const half& a, const half& b) {
694 bool result = mapToSigned(a.x) == mapToSigned(b.x);
695 result &= isOrdered(a, b);
698EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator!=(const half& a, const half& b) { return !(a == b); }
699EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<(const half& a, const half& b) {
700 bool result = mapToSigned(a.x) < mapToSigned(b.x);
701 result &= isOrdered(a, b);
704EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<=(const half& a, const half& b) {
705 bool result = mapToSigned(a.x) <= mapToSigned(b.x);
706 result &= isOrdered(a, b);
709EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const half& a, const half& b) {
710 bool result = mapToSigned(a.x) > mapToSigned(b.x);
711 result &= isOrdered(a, b);
714EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>=(const half& a, const half& b) {
715 bool result = mapToSigned(a.x) >= mapToSigned(b.x);
716 result &= isOrdered(a, b);
720#if EIGEN_COMP_CLANG && defined(EIGEN_GPUCC)
721#pragma pop_macro("EIGEN_DEVICE_FUNC")
728EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator/(const half& a, Index b) {
729 return half(static_cast<float>(a) / static_cast<float>(b));
732EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator++(half& a) {
737EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator--(half& a) {
742EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator++(half& a, int) {
743 half original_value = a;
745 return original_value;
748EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator--(half& a, int) {
749 half original_value = a;
751 return original_value;
759EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR __half_raw raw_uint16_to_half(numext::uint16_t x) {
770#if defined(EIGEN_GPUCC) && defined(EIGEN_GPU_COMPILE_PHASE)
775 return __half_raw(x);
779EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC numext::uint16_t raw_half_as_uint16(const __half_raw& h) {
783#if EIGEN_HAS_ARM64_FP16
784 return numext::bit_cast<numext::uint16_t>(h.x);
785#elif defined(EIGEN_HAS_BUILTIN_FLOAT16)
786 return numext::bit_cast<numext::uint16_t>(h.x);
787#elif defined(EIGEN_SYCL_DEVICE_ONLY)
788 return numext::bit_cast<numext::uint16_t>(h);
795EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne<false>(float ff) {
796#if defined(EIGEN_GPU_COMPILE_PHASE)
797 __half tmp_ff = __float2half(ff);
798 return *(__half_raw*)&tmp_ff;
800#elif EIGEN_HAS_ARM64_FP16
801 return __half_raw(__half_raw::construct_from_rep_tag(), static_cast<__fp16>(ff));
803#elif defined(EIGEN_HAS_BUILTIN_FLOAT16)
805 h.x = static_cast<_Float16>(ff);
808#elif defined(EIGEN_HAS_FP16_C)
811 h.x = static_cast<numext::uint16_t>(_mm_extract_epi16(_mm_cvtps_ph(_mm_set_ss(ff), 0), 0));
815 uint32_t f_bits = Eigen::numext::bit_cast<uint32_t>(ff);
816 const uint32_t f32infty_bits = {255 << 23};
817 const uint32_t f16max_bits = {(127 + 16) << 23};
818 const uint32_t denorm_magic_bits = {((127 - 15) + (23 - 10) + 1) << 23};
819 const uint32_t sign_mask = 0x80000000u;
821 o.x = static_cast<uint16_t>(0x0u);
823 const uint32_t sign = f_bits & sign_mask;
831 if (f_bits >= f16max_bits) {
832 o.x = (f_bits > f32infty_bits) ? 0x7e00 : 0x7c00;
834 if (f_bits < (113 << 23)) {
838 f_bits = Eigen::numext::bit_cast<uint32_t>(Eigen::numext::bit_cast<float>(f_bits) +
839 Eigen::numext::bit_cast<float>(denorm_magic_bits));
842 o.x = static_cast<numext::uint16_t>(f_bits - denorm_magic_bits);
844 const uint32_t mant_odd = (f_bits >> 13) & 1;
849 f_bits += 0xc8000fffU;
853 o.x = static_cast<numext::uint16_t>(f_bits >> 13);
857 o.x |= static_cast<numext::uint16_t>(sign >> 16);
867EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __half_raw float_to_half_rtne<true>(float ff) {
868#if defined(EIGEN_GPU_COMPILE_PHASE)
869 __half tmp_ff = __float2half(ff);
870 return *(__half_raw*)&tmp_ff;
872#elif EIGEN_HAS_ARM64_FP16
873 return __half_raw(__half_raw::construct_from_rep_tag(), static_cast<__fp16>(ff));
875#elif defined(EIGEN_HAS_BUILTIN_FLOAT16)
877 h.x = static_cast<_Float16>(ff);
881 uint32_t f_bits = Eigen::numext::bit_cast<uint32_t>(ff);
882 const uint32_t f16max_bits = {(127 + 16) << 23};
883 const uint32_t sign = f_bits & 0x80000000u;
886 numext::uint16_t raw = 0x0000u;
887 if (f_bits >= f16max_bits) {
889 } else if (f_bits != 0) {
890 const uint32_t mant_odd = (f_bits >> 13) & 1u;
891 f_bits += 0xc8000fffU + mant_odd;
892 raw = static_cast<numext::uint16_t>(f_bits >> 13);
894 return raw_uint16_to_half(raw | static_cast<numext::uint16_t>(sign >> 16));
898EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float half_to_float(__half_raw h) {
899#if defined(EIGEN_GPU_COMPILE_PHASE)
900 return __half2float(h);
901#elif EIGEN_HAS_ARM64_FP16 || defined(EIGEN_HAS_BUILTIN_FLOAT16)
902 return static_cast<float>(native_half(h));
903#elif defined(EIGEN_HAS_FP16_C)
906 return _mm_cvtss_f32(_mm_cvtph_ps(_mm_set1_epi16(h.x)));
908 return _cvtsh_ss(h.x);
911 const float magic = Eigen::numext::bit_cast<float>(static_cast<uint32_t>(113 << 23));
912 const uint32_t shifted_exp = 0x7c00 << 13;
913 uint32_t o_bits = (h.x & 0x7fff) << 13;
914 const uint32_t exp = shifted_exp & o_bits;
915 o_bits += (127 - 15) << 23;
918 if (exp == shifted_exp) {
919 o_bits += (128 - 16) << 23;
920 } else if (exp == 0) {
923 o_bits = Eigen::numext::bit_cast<uint32_t>(Eigen::numext::bit_cast<float>(o_bits) - magic);
926 o_bits |= (h.x & 0x8000u) << 16;
927 return Eigen::numext::bit_cast<float>(o_bits);
933EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool(isinf)(const half& a) { return (raw_half_as_uint16(a) & 0x7fff) == 0x7c00; }
934EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool(isnan)(const half& a) {
935#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
938 return (raw_half_as_uint16(a) & 0x7fff) > 0x7c00;
941EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool(isfinite)(const half& a) {
942 return (raw_half_as_uint16(a) & 0x7fff) < 0x7c00;
945EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half abs(const half& a) {
946#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
947 return half_from_rep(vabsh_f16(a.x));
949 return raw_uint16_to_half(static_cast<numext::uint16_t>(raw_half_as_uint16(a) & 0x7FFF));
952EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half exp(const half& a) {
953#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
954 return half(hexp(::__half(a)));
956 return half(numext::exp(float(a)));
959EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half exp2(const half& a) {
960#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
961 return half(hexp2(::__half(a)));
963 return half(numext::exp2(float(a)));
966EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half expm1(const half& a) { return half(numext::expm1(float(a))); }
968EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half ldexp(const half& a, int exponent) {
969 return half(numext::ldexp(float(a), exponent));
971EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log(const half& a) {
972#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
973 return half(hlog(::__half(a)));
975 return half(numext::log(float(a)));
978EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log1p(const half& a) { return half(numext::log1p(float(a))); }
979EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(const half& a) { return half(numext::log10(float(a))); }
980EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log2(const half& a) { return half(numext::log2(float(a))); }
982EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(const half& a) {
983#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
984 return half(hsqrt(::__half(a)));
986 return half(numext::sqrt(float(a)));
989EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(const half& a, const half& b) {
990 return half(numext::pow(float(a), float(b)));
992EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atan2(const half& a, const half& b) {
993 return half(numext::atan2(float(a), float(b)));
995EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sin(const half& a) { return half(numext::sin(float(a))); }
996EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half cos(const half& a) { return half(numext::cos(float(a))); }
997EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tan(const half& a) { return half(numext::tan(float(a))); }
998EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tanh(const half& a) {
1000 return half(numext::tanh<float>(float(a)));
1002EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half asin(const half& a) { return half(numext::asin(float(a))); }
1003EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half acos(const half& a) { return half(numext::acos(float(a))); }
1004EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atan(const half& a) { return half(numext::atan(float(a))); }
1005EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half atanh(const half& a) { return half(numext::atanh(float(a))); }
1006EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half floor(const half& a) {
1007#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
1008 return half(hfloor(::__half(a)));
1010 return half(numext::floor(float(a)));
1013EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half ceil(const half& a) {
1014#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
1015 return half(hceil(::__half(a)));
1017 return half(numext::ceil(float(a)));
1020EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half rint(const half& a) { return half(numext::rint(float(a))); }
1021EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half round(const half& a) { return half(numext::round(float(a))); }
1022EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half trunc(const half& a) { return half(numext::trunc(float(a))); }
1023EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half fmod(const half& a, const half& b) {
1024 return half(numext::fmod(float(a), float(b)));
1027EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half(min)(const half& a, const half& b) { return b < a ? b : a; }
1029EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half(max)(const half& a, const half& b) { return a < b ? b : a; }
1036EIGEN_DEVICE_FUNC inline double fma_round_to_odd(float a, float b, float c) {
1037 const double p = static_cast<double>(a) * static_cast<double>(b);
1038 const double c_wide = static_cast<double>(c);
1039 const double s = p + c_wide;
1041 if (!(numext::isfinite)(s)) return s;
1042 const double p_part = s - c_wide;
1043 const double e = (p - p_part) + (c_wide - (s - p_part));
1044 if (e == 0) return s;
1046 const bool away = (s > 0) != (e > 0);
1047 return numext::bit_cast<double>((numext::bit_cast<numext::uint64_t>(s) - (away ? 1u : 0u)) | 1u);
1050EIGEN_DEVICE_FUNC inline half fma(const half& a, const half& b, const half& c) {
1051#if defined(EIGEN_HAS_NATIVE_GPU_FP16)
1053 return __hfma(::__half(a), ::__half(b), ::__half(c));
1054#elif defined(EIGEN_GPU_COMPILE_PHASE) || defined(__SYCL_DEVICE_ONLY__)
1056 return half(numext::fma(static_cast<float>(a), static_cast<float>(b), static_cast<float>(c)));
1057#elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
1058 return half_from_rep(vfmah_f16(c.x, a.x, b.x));
1059#elif defined(EIGEN_VECTORIZE_AVX512FP16)
1061 return half(_mm_cvtsh_h(_mm_fmadd_ph(_mm_set_sh(a.x), _mm_set_sh(b.x), _mm_set_sh(c.x))));
1063 return half(fma_round_to_odd(static_cast<float>(a), static_cast<float>(b), static_cast<float>(c)));
1068EIGEN_ALWAYS_INLINE std::ostream& operator<<(std::ostream& os, const half& v) {
1069 os << static_cast<float>(v);
1082struct is_arithmetic<half> : std::true_type {};
1085struct random_impl<half> {
1086 enum : int { MantissaBits = 10 };
1087 using Impl = random_impl<float>;
1088 static EIGEN_DEVICE_FUNC inline half run(const half& x, const half& y) {
1089 float result = Impl::run(x, y, MantissaBits);
1090 return half(result);
1092 static EIGEN_DEVICE_FUNC inline half run() {
1093 float result = Impl::run(MantissaBits);
1094 return half(result);
1101struct NumTraits<Eigen::half> : GenericNumTraits<Eigen::half> {
1102 enum { IsSigned = true, IsInteger = false, IsComplex = false, RequireInitialization = false };
1104 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half epsilon() {
1106 return half_impl::raw_uint16_to_half(0x1400);
1108 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half dummy_precision() {
1109 return half_impl::raw_uint16_to_half(0x211f);
1111 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half highest() {
1112 return half_impl::raw_uint16_to_half(0x7bff);
1114 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half lowest() {
1115 return half_impl::raw_uint16_to_half(0xfbff);
1117 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half infinity() {
1118 return half_impl::raw_uint16_to_half(0x7c00);
1120 EIGEN_DEVICE_FUNC _EIGEN_MAYBE_CONSTEXPR static EIGEN_STRONG_INLINE Eigen::half quiet_NaN() {
1121 return half_impl::raw_uint16_to_half(0x7e00);
1127#undef _EIGEN_MAYBE_CONSTEXPR
1132#if defined(EIGEN_GPU_COMPILE_PHASE)
1135EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isnan)(const Eigen::half& h) {
1136 return (half_impl::isnan)(h);
1140EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isinf)(const Eigen::half& h) {
1141 return (half_impl::isinf)(h);
1145EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isfinite)(const Eigen::half& h) {
1146 return (half_impl::isfinite)(h);
1152EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half bit_cast<Eigen::half, uint16_t>(const uint16_t& src) {
1153 return Eigen::half(Eigen::half_impl::raw_uint16_to_half(src));
1157EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC uint16_t bit_cast<uint16_t, Eigen::half>(const Eigen::half& src) {
1158 return Eigen::half_impl::raw_half_as_uint16(src);
1161EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half nextafter(const Eigen::half& from, const Eigen::half& to) {
1162 if (numext::isnan EIGEN_NOT_A_MACRO(from)) {
1165 if (numext::isnan EIGEN_NOT_A_MACRO(to)) {
1171 uint16_t from_bits = numext::bit_cast<uint16_t>(from);
1172 bool from_sign = from_bits >> 15;
1173 if ((from_bits & 0x7fff) == 0) {
1176 from_bits = (to > from) ? uint16_t(0x0001) : uint16_t(0x8001);
1177 } else if ((to > from) != from_sign) {
1183 return numext::bit_cast<Eigen::half>(from_bits);
1188EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half madd<Eigen::half>(const Eigen::half& x, const Eigen::half& y,
1189 const Eigen::half& z) {
1190 return Eigen::half(static_cast<float>(x) * static_cast<float>(y) + static_cast<float>(z));
1199#if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
1201#if defined(EIGEN_CUDACC)
1203__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_sync(unsigned mask, Eigen::half var, int srcLane,
1204 int width = warpSize) {
1205 const __half h = var;
1206 return static_cast<Eigen::half>(__shfl_sync(mask, h, srcLane, width));
1209__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_up_sync(unsigned mask, Eigen::half var, unsigned int delta,
1210 int width = warpSize) {
1211 const __half h = var;
1212 return static_cast<Eigen::half>(__shfl_up_sync(mask, h, delta, width));
1215__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_down_sync(unsigned mask, Eigen::half var, unsigned int delta,
1216 int width = warpSize) {
1217 const __half h = var;
1218 return static_cast<Eigen::half>(__shfl_down_sync(mask, h, delta, width));
1221__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_xor_sync(unsigned mask, Eigen::half var, int laneMask,
1222 int width = warpSize) {
1223 const __half h = var;
1224 return static_cast<Eigen::half>(__shfl_xor_sync(mask, h, laneMask, width));
1229__device__ EIGEN_STRONG_INLINE Eigen::half __shfl(Eigen::half var, int srcLane, int width = warpSize) {
1230 const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
1231 return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl(ivar, srcLane, width)));
1234__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_up(Eigen::half var, unsigned int delta, int width = warpSize) {
1235 const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
1236 return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_up(ivar, delta, width)));
1239__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_down(Eigen::half var, unsigned int delta, int width = warpSize) {
1240 const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
1241 return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_down(ivar, delta, width)));
1244__device__ EIGEN_STRONG_INLINE Eigen::half __shfl_xor(Eigen::half var, int laneMask, int width = warpSize) {
1245 const int ivar = static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
1246 return Eigen::numext::bit_cast<Eigen::half>(static_cast<Eigen::numext::uint16_t>(__shfl_xor(ivar, laneMask, width)));
1253#if defined(EIGEN_CUDACC) || defined(EIGEN_HIPCC)
1254EIGEN_STRONG_INLINE __device__ Eigen::half __ldg(const Eigen::half* ptr) {
1255 return Eigen::half_impl::raw_uint16_to_half(__ldg(reinterpret_cast<const Eigen::numext::uint16_t*>(ptr)));
1259#if EIGEN_HAS_STD_HASH
1262struct hash<Eigen::half> {
1263 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t operator()(const Eigen::half& a) const {
1265 const Eigen::numext::uint16_t bits = Eigen::numext::bit_cast<Eigen::numext::uint16_t>(a);
1266 return static_cast<std::size_t>((bits & 0x7fff) == 0 ? 0 : bits);
1276struct cast_impl<float, half> {
1277 EIGEN_DEVICE_FUNC static inline half run(const float& a) {
1278#if defined(EIGEN_GPU_COMPILE_PHASE)
1279 return __float2half(a);
1287struct cast_impl<int, half> {
1288 EIGEN_DEVICE_FUNC static inline half run(const int& a) {
1289#if defined(EIGEN_GPU_COMPILE_PHASE)
1290 return __float2half(static_cast<float>(a));
1292 return half(static_cast<float>(a));
1298struct cast_impl<half, float> {
1299 EIGEN_DEVICE_FUNC static inline float run(const half& a) {
1300#if defined(EIGEN_GPU_COMPILE_PHASE)
1301 return __half2float(a);
1303 return static_cast<float>(a);