39#if defined(EIGEN_HAS_GPU_FP16) || defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
46 #pragma push_macro("EIGEN_CONSTEXPR")
47 #undef EIGEN_CONSTEXPR
48 #define EIGEN_CONSTEXPR
51#define F16_PACKET_FUNCTION(PACKET_F, PACKET_F16, METHOD) \
53 EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_UNUSED \
54 PACKET_F16 METHOD<PACKET_F16>(const PACKET_F16& _x) { \
55 return float2half(METHOD<PACKET_F>(half2float(_x))); \
83#if !defined(EIGEN_HAS_GPU_FP16) || !defined(EIGEN_GPU_COMPILE_PHASE)
86#if (defined(EIGEN_HAS_GPU_FP16) && !defined(EIGEN_GPU_COMPILE_PHASE))
94 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
__half_raw() : x(0) {}
96#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
97 explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
__half_raw(numext::uint16_t
raw) : x(numext::bit_cast<__fp16>(
raw)) {
101 explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
__half_raw(numext::uint16_t
raw) : x(
raw) {}
106#elif defined(EIGEN_HAS_HIP_FP16)
109#elif defined(EIGEN_HAS_CUDA_FP16)
110 #if EIGEN_CUDA_SDK_VER < 90000
114#elif defined(SYCL_DEVICE_ONLY)
118EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
__half_raw raw_uint16_to_half(numext::uint16_t x);
119EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
__half_raw float_to_half_rtne(
float ff);
120EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
float half_to_float(
__half_raw h);
123 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
half_base() {}
126#if defined(EIGEN_HAS_GPU_FP16)
127 #if defined(EIGEN_HAS_HIP_FP16)
129 #elif defined(EIGEN_HAS_CUDA_FP16)
130 #if EIGEN_CUDA_SDK_VER >= 90000
144#if !defined(EIGEN_HAS_GPU_FP16) || !defined(EIGEN_GPU_COMPILE_PHASE)
149#elif defined(EIGEN_HAS_HIP_FP16)
152#elif defined(EIGEN_HAS_CUDA_FP16)
156 #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER < 90000
161 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
half() {}
165#if defined(EIGEN_HAS_GPU_FP16)
166 #if defined(EIGEN_HAS_HIP_FP16)
168 #elif defined(EIGEN_HAS_CUDA_FP16)
169 #if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
176 explicit EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
half(
bool b)
179 explicit EIGEN_DEVICE_FUNC
half(T val)
181 explicit EIGEN_DEVICE_FUNC
half(
float f)
186 template<
typename RealScalar>
187 explicit EIGEN_DEVICE_FUNC
half(std::complex<RealScalar> c)
190 EIGEN_DEVICE_FUNC
operator float()
const {
191 return half_impl::half_to_float(*
this);
194#if defined(EIGEN_HAS_GPU_FP16) && !defined(EIGEN_GPU_COMPILE_PHASE)
195 EIGEN_DEVICE_FUNC
operator __half()
const {
208 static const bool is_specialized =
true;
209 static const bool is_signed =
true;
210 static const bool is_integer =
false;
211 static const bool is_exact =
false;
212 static const bool has_infinity =
true;
213 static const bool has_quiet_NaN =
true;
214 static const bool has_signaling_NaN =
true;
215 static const float_denorm_style has_denorm = denorm_present;
216 static const bool has_denorm_loss =
false;
217 static const std::float_round_style round_style = std::round_to_nearest;
218 static const bool is_iec559 =
false;
219 static const bool is_bounded =
false;
220 static const bool is_modulo =
false;
221 static const int digits = 11;
222 static const int digits10 = 3;
223 static const int max_digits10 = 5;
224 static const int radix = 2;
225 static const int min_exponent = -13;
226 static const int min_exponent10 = -4;
227 static const int max_exponent = 16;
228 static const int max_exponent10 = 4;
229 static const bool traps =
true;
230 static const bool tinyness_before =
false;
232 static Eigen::half (min)() {
return Eigen::half_impl::raw_uint16_to_half(0x400); }
233 static Eigen::half lowest() {
return Eigen::half_impl::raw_uint16_to_half(0xfbff); }
234 static Eigen::half (max)() {
return Eigen::half_impl::raw_uint16_to_half(0x7bff); }
235 static Eigen::half epsilon() {
return Eigen::half_impl::raw_uint16_to_half(0x0800); }
237 static Eigen::half infinity() {
return Eigen::half_impl::raw_uint16_to_half(0x7c00); }
238 static Eigen::half quiet_NaN() {
return Eigen::half_impl::raw_uint16_to_half(0x7e00); }
239 static Eigen::half signaling_NaN() {
return Eigen::half_impl::raw_uint16_to_half(0x7d00); }
240 static Eigen::half denorm_min() {
return Eigen::half_impl::raw_uint16_to_half(0x1); }
248struct numeric_limits<const
Eigen::half> : numeric_limits<Eigen::half> {};
250struct numeric_limits<volatile
Eigen::half> : numeric_limits<Eigen::half> {};
252struct numeric_limits<const volatile
Eigen::half> : numeric_limits<Eigen::half> {};
259#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && \
260 EIGEN_CUDA_ARCH >= 530) || \
261 (defined(EIGEN_HAS_HIP_FP16) && defined(HIP_DEVICE_COMPILE))
265#define EIGEN_HAS_NATIVE_FP16
273#if defined(EIGEN_HAS_NATIVE_FP16)
274EIGEN_STRONG_INLINE __device__ half operator + (
const half& a,
const half& b) {
275#if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
276 return __hadd(::__half(a), ::__half(b));
281EIGEN_STRONG_INLINE __device__ half operator * (
const half& a,
const half& b) {
284EIGEN_STRONG_INLINE __device__ half operator - (
const half& a,
const half& b) {
287EIGEN_STRONG_INLINE __device__ half operator / (
const half& a,
const half& b) {
288#if defined(EIGEN_CUDA_SDK_VER) && EIGEN_CUDA_SDK_VER >= 90000
291 float num = __half2float(a);
292 float denom = __half2float(b);
293 return __float2half(num / denom);
296EIGEN_STRONG_INLINE __device__ half operator - (
const half& a) {
299EIGEN_STRONG_INLINE __device__ half& operator += (half& a,
const half& b) {
303EIGEN_STRONG_INLINE __device__ half& operator *= (half& a,
const half& b) {
307EIGEN_STRONG_INLINE __device__ half& operator -= (half& a,
const half& b) {
311EIGEN_STRONG_INLINE __device__ half& operator /= (half& a,
const half& b) {
315EIGEN_STRONG_INLINE __device__
bool operator == (
const half& a,
const half& b) {
318EIGEN_STRONG_INLINE __device__
bool operator != (
const half& a,
const half& b) {
321EIGEN_STRONG_INLINE __device__
bool operator < (
const half& a,
const half& b) {
324EIGEN_STRONG_INLINE __device__
bool operator <= (
const half& a,
const half& b) {
327EIGEN_STRONG_INLINE __device__
bool operator > (
const half& a,
const half& b) {
330EIGEN_STRONG_INLINE __device__
bool operator >= (
const half& a,
const half& b) {
335#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC) && !defined(EIGEN_GPU_COMPILE_PHASE)
336EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator + (
const half& a,
const half& b) {
337 return half(vaddh_f16(a.x, b.x));
339EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator * (
const half& a,
const half& b) {
340 return half(vmulh_f16(a.x, b.x));
342EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (
const half& a,
const half& b) {
343 return half(vsubh_f16(a.x, b.x));
345EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (
const half& a,
const half& b) {
346 return half(vdivh_f16(a.x, b.x));
348EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (
const half& a) {
349 return half(vnegh_f16(a.x));
351EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator += (half& a,
const half& b) {
352 a = half(vaddh_f16(a.x, b.x));
355EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator *= (half& a,
const half& b) {
356 a = half(vmulh_f16(a.x, b.x));
359EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator -= (half& a,
const half& b) {
360 a = half(vsubh_f16(a.x, b.x));
363EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator /= (half& a,
const half& b) {
364 a = half(vdivh_f16(a.x, b.x));
367EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator == (
const half& a,
const half& b) {
368 return vceqh_f16(a.x, b.x);
370EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator != (
const half& a,
const half& b) {
371 return !vceqh_f16(a.x, b.x);
373EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator < (
const half& a,
const half& b) {
374 return vclth_f16(a.x, b.x);
376EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator <= (
const half& a,
const half& b) {
377 return vcleh_f16(a.x, b.x);
379EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator > (
const half& a,
const half& b) {
380 return vcgth_f16(a.x, b.x);
382EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator >= (
const half& a,
const half& b) {
383 return vcgeh_f16(a.x, b.x);
388#elif !defined(EIGEN_HAS_NATIVE_FP16) || (EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
390#if EIGEN_COMP_CLANG && defined(EIGEN_CUDACC)
392#pragma push_macro("EIGEN_DEVICE_FUNC")
393#undef EIGEN_DEVICE_FUNC
394#if defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_HAS_NATIVE_FP16)
395#define EIGEN_DEVICE_FUNC __host__
397#define EIGEN_DEVICE_FUNC __host__ __device__
403EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator + (
const half& a,
const half& b) {
404 return half(
float(a) +
float(b));
406EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator * (
const half& a,
const half& b) {
407 return half(
float(a) *
float(b));
409EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (
const half& a,
const half& b) {
410 return half(
float(a) -
float(b));
412EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (
const half& a,
const half& b) {
413 return half(
float(a) /
float(b));
415EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator - (
const half& a) {
417 result.x = a.x ^ 0x8000;
420EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator += (half& a,
const half& b) {
421 a = half(
float(a) +
float(b));
424EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator *= (half& a,
const half& b) {
425 a = half(
float(a) *
float(b));
428EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator -= (half& a,
const half& b) {
429 a = half(
float(a) -
float(b));
432EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half& operator /= (half& a,
const half& b) {
433 a = half(
float(a) /
float(b));
436EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator == (
const half& a,
const half& b) {
437 return numext::equal_strict(
float(a),
float(b));
439EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator != (
const half& a,
const half& b) {
440 return numext::not_equal_strict(
float(a),
float(b));
442EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator < (
const half& a,
const half& b) {
443 return float(a) < float(b);
445EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator <= (
const half& a,
const half& b) {
446 return float(a) <= float(b);
448EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator > (
const half& a,
const half& b) {
449 return float(a) > float(b);
451EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
bool operator >= (
const half& a,
const half& b) {
452 return float(a) >= float(b);
455#if defined(__clang__) && defined(__CUDA__)
456#pragma pop_macro("EIGEN_DEVICE_FUNC")
462EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator / (
const half& a,
Index b) {
463 return half(
static_cast<float>(a) /
static_cast<float>(b));
466EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator++(half& a) {
471EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator--(half& a) {
476EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator++(half& a,
int) {
477 half original_value = a;
479 return original_value;
482EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half operator--(half& a,
int) {
483 half original_value = a;
485 return original_value;
493EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __half_raw raw_uint16_to_half(numext::uint16_t x) {
500#if defined(EIGEN_HAS_GPU_FP16)
505 return __half_raw(x);
509EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC numext::uint16_t raw_half_as_uint16(
const __half_raw& h) {
513#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
514 return numext::bit_cast<numext::uint16_t>(h.x);
515#elif defined(SYCL_DEVICE_ONLY)
516 return numext::bit_cast<numext::uint16_t>(h);
527EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
__half_raw float_to_half_rtne(
float ff) {
528#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
529 (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
533#elif defined(EIGEN_HAS_FP16_C)
543#elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
552 const float32_bits
f16max = { (127 + 16) << 23 };
553 const float32_bits denorm_magic = { ((127 - 15) + (23 - 10) + 1) << 23 };
554 unsigned int sign_mask = 0x80000000u;
556 o.x =
static_cast<numext::uint16_t
>(0x0u);
558 unsigned int sign = f.u & sign_mask;
566 if (f.u >= f16max.u) {
567 o.x = (f.u > f32infty.u) ? 0x7e00 : 0x7c00;
569 if (f.u < (113 << 23)) {
573 f.f += denorm_magic.f;
576 o.x =
static_cast<numext::uint16_t
>(f.u - denorm_magic.u);
578 unsigned int mant_odd = (f.u >> 13) & 1;
587 o.x =
static_cast<numext::uint16_t
>(f.u >> 13);
591 o.x |=
static_cast<numext::uint16_t
>(sign >> 16);
596EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
float half_to_float(__half_raw h) {
597#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
598 (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
599 return __half2float(h);
600#elif defined(EIGEN_HAS_FP16_C)
603 return _mm_cvtss_f32(_mm_cvtph_ps(_mm_set1_epi16(h.x)));
605 return _cvtsh_ss(h.x);
607#elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
608 return static_cast<float>(h.x);
610 const float32_bits magic = { 113 << 23 };
611 const unsigned int shifted_exp = 0x7c00 << 13;
614 o.u = (h.x & 0x7fff) << 13;
615 unsigned int exp = shifted_exp & o.u;
616 o.u += (127 - 15) << 23;
619 if (exp == shifted_exp) {
620 o.u += (128 - 16) << 23;
621 }
else if (exp == 0) {
626 o.u |= (h.x & 0x8000) << 16;
633EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isinf)(
const half& a) {
634#ifdef EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC
635 return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) == 0x7c00;
637 return (a.x & 0x7fff) == 0x7c00;
640EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isnan)(
const half& a) {
641#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
642 (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
644#elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
645 return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) > 0x7c00;
647 return (a.x & 0x7fff) > 0x7c00;
650EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool (isfinite)(
const half& a) {
651 return !(isinf EIGEN_NOT_A_MACRO (a)) && !(isnan EIGEN_NOT_A_MACRO (a));
654EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half abs(
const half& a) {
655#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
656 return half(vabsh_f16(a.x));
659 result.x = a.x & 0x7FFF;
663EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half exp(
const half& a) {
664#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
665 defined(EIGEN_HIP_DEVICE_COMPILE)
666 return half(hexp(a));
668 return half(::expf(
float(a)));
671EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half expm1(
const half& a) {
672 return half(numext::expm1(
float(a)));
674EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log(
const half& a) {
675#if (defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
676 (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
677 return half(::hlog(a));
679 return half(::logf(
float(a)));
682EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log1p(
const half& a) {
683 return half(numext::log1p(
float(a)));
685EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log10(
const half& a) {
686 return half(::log10f(
float(a)));
688EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half log2(
const half& a) {
689 return half(
static_cast<float>(EIGEN_LOG2E) * ::logf(
float(a)));
692EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sqrt(
const half& a) {
693#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
694 defined(EIGEN_HIP_DEVICE_COMPILE)
695 return half(hsqrt(a));
697 return half(::sqrtf(
float(a)));
700EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half pow(
const half& a,
const half& b) {
701 return half(::powf(
float(a),
float(b)));
703EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half sin(
const half& a) {
704 return half(::sinf(
float(a)));
706EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half cos(
const half& a) {
707 return half(::cosf(
float(a)));
709EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tan(
const half& a) {
710 return half(::tanf(
float(a)));
712EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half tanh(
const half& a) {
713 return half(::tanhf(
float(a)));
715EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half asin(
const half& a) {
716 return half(::asinf(
float(a)));
718EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half acos(
const half& a) {
719 return half(::acosf(
float(a)));
721EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half floor(
const half& a) {
722#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
723 defined(EIGEN_HIP_DEVICE_COMPILE)
724 return half(hfloor(a));
726 return half(::floorf(
float(a)));
729EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half ceil(
const half& a) {
730#if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
731 defined(EIGEN_HIP_DEVICE_COMPILE)
732 return half(hceil(a));
734 return half(::ceilf(
float(a)));
737EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half rint(
const half& a) {
738 return half(::rintf(
float(a)));
740EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half round(
const half& a) {
741 return half(::roundf(
float(a)));
743EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half fmod(
const half& a,
const half& b) {
744 return half(::fmodf(
float(a),
float(b)));
747EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half (min)(
const half& a,
const half& b) {
748#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
749 (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
750 return __hlt(b, a) ? b : a;
752 const float f1 =
static_cast<float>(a);
753 const float f2 =
static_cast<float>(b);
754 return f2 < f1 ? b : a;
757EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half (max)(
const half& a,
const half& b) {
758#if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
759 (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
760 return __hlt(a, b) ? b : a;
762 const float f1 =
static_cast<float>(a);
763 const float f2 =
static_cast<float>(b);
764 return f1 < f2 ? b : a;
769EIGEN_ALWAYS_INLINE std::ostream& operator << (std::ostream& os,
const half& v) {
770 os << static_cast<float>(v);
787 return x + (y-x) *
half(
float(std::rand()) / float(
RAND_MAX));
789 static inline half run()
806 RequireInitialization =
false
809 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static EIGEN_STRONG_INLINE
Eigen::half epsilon() {
810 return half_impl::raw_uint16_to_half(0x0800);
812 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static EIGEN_STRONG_INLINE
Eigen::half dummy_precision() {
813 return half_impl::raw_uint16_to_half(0x211f);
815 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static EIGEN_STRONG_INLINE
Eigen::half highest() {
816 return half_impl::raw_uint16_to_half(0x7bff);
818 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static EIGEN_STRONG_INLINE
Eigen::half lowest() {
819 return half_impl::raw_uint16_to_half(0xfbff);
821 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static EIGEN_STRONG_INLINE
Eigen::half infinity() {
822 return half_impl::raw_uint16_to_half(0x7c00);
824 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
static EIGEN_STRONG_INLINE
Eigen::half quiet_NaN() {
825 return half_impl::raw_uint16_to_half(0x7e00);
831#if defined(EIGEN_HAS_GPU_FP16) || defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
832 #pragma pop_macro("EIGEN_CONSTEXPR")
838#if defined(EIGEN_GPU_COMPILE_PHASE)
841EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isnan)(
const Eigen::half& h) {
842 return (half_impl::isnan)(h);
846EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isinf)(
const Eigen::half& h) {
847 return (half_impl::isinf)(h);
851EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool(isfinite)(
const Eigen::half& h) {
852 return (half_impl::isfinite)(h);
858EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC
Eigen::half bit_cast<Eigen::half, uint16_t>(
const uint16_t& src) {
859 return Eigen::half(Eigen::half_impl::raw_uint16_to_half(src));
863EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC uint16_t bit_cast<uint16_t, Eigen::half>(
const Eigen::half& src) {
864 return Eigen::half_impl::raw_half_as_uint16(src);
881#if (defined(EIGEN_CUDACC) && (!defined(EIGEN_CUDA_ARCH) || EIGEN_CUDA_ARCH >= 300)) \
882 || defined(EIGEN_HIPCC)
884#if defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 90000
886__device__ EIGEN_STRONG_INLINE
Eigen::half __shfl_sync(
unsigned mask,
Eigen::half var,
int srcLane,
int width=warpSize) {
887 const __half h = var;
888 return static_cast<Eigen::half>(__shfl_sync(mask, h, srcLane, width));
891__device__ EIGEN_STRONG_INLINE
Eigen::half __shfl_up_sync(
unsigned mask,
Eigen::half var,
unsigned int delta,
int width=warpSize) {
892 const __half h = var;
893 return static_cast<Eigen::half>(__shfl_up_sync(mask, h, delta, width));
896__device__ EIGEN_STRONG_INLINE
Eigen::half __shfl_down_sync(
unsigned mask,
Eigen::half var,
unsigned int delta,
int width=warpSize) {
897 const __half h = var;
898 return static_cast<Eigen::half>(__shfl_down_sync(mask, h, delta, width));
901__device__ EIGEN_STRONG_INLINE
Eigen::half __shfl_xor_sync(
unsigned mask,
Eigen::half var,
int laneMask,
int width=warpSize) {
902 const __half h = var;
903 return static_cast<Eigen::half>(__shfl_xor_sync(mask, h, laneMask, width));
909 const int ivar =
static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
910 return Eigen::numext::bit_cast<Eigen::half>(
static_cast<Eigen::numext::uint16_t
>(__shfl(ivar, srcLane, width)));
913__device__ EIGEN_STRONG_INLINE
Eigen::half __shfl_up(
Eigen::half var,
unsigned int delta,
int width=warpSize) {
914 const int ivar =
static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
915 return Eigen::numext::bit_cast<Eigen::half>(
static_cast<Eigen::numext::uint16_t
>(__shfl_up(ivar, delta, width)));
918__device__ EIGEN_STRONG_INLINE
Eigen::half __shfl_down(
Eigen::half var,
unsigned int delta,
int width=warpSize) {
919 const int ivar =
static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
920 return Eigen::numext::bit_cast<Eigen::half>(
static_cast<Eigen::numext::uint16_t
>(__shfl_down(ivar, delta, width)));
924 const int ivar =
static_cast<int>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(var));
925 return Eigen::numext::bit_cast<Eigen::half>(
static_cast<Eigen::numext::uint16_t
>(__shfl_xor(ivar, laneMask, width)));
932#if (defined(EIGEN_CUDACC) && (!defined(EIGEN_CUDA_ARCH) || EIGEN_CUDA_ARCH >= 350)) \
933 || defined(EIGEN_HIPCC)
935 return Eigen::half_impl::raw_uint16_to_half(__ldg(
reinterpret_cast<const Eigen::numext::uint16_t*
>(ptr)));
939#if EIGEN_HAS_STD_HASH
942struct hash<
Eigen::half> {
943 EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::size_t operator()(
const Eigen::half& a)
const {
944 return static_cast<std::size_t
>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(a));
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:50
Namespace containing all symbols from the Eigen library.
Definition LDLT.h:16
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
Definition NumTraits.h:156
Holds information about the various numeric (i.e.
Definition NumTraits.h:236
Definition MathFunctions.h:806