Eigen::half_impl Namespace Reference

Classes

struct  __half_raw
 
union  float32_bits
 
struct  half_base
 
struct  numeric_limits_half_impl
 

Functions

half abs (const half &a)
 
half acos (const half &a)
 
half asin (const half &a)
 
half atan (const half &a)
 
half atan2 (const half &a, const half &b)
 
half atanh (const half &a)
 
half ceil (const half &a)
 
half cos (const half &a)
 
half exp (const half &a)
 
half expm1 (const half &a)
 
__half_raw float_to_half_rtne (float ff)
 
half floor (const half &a)
 
half fmod (const half &a, const half &b)
 
float half_to_float (__half_raw h)
 
bool() isfinite (const half &a)
 
bool() isinf (const half &a)
 
bool() isnan (const half &a)
 
half log (const half &a)
 
half log10 (const half &a)
 
half log1p (const half &a)
 
half log2 (const half &a)
 
half() max (const half &a, const half &b)
 
half() min (const half &a, const half &b)
 
bool operator!= (const half &a, const half &b)
 
half operator* (const half &a, const half &b)
 
halfoperator*= (half &a, const half &b)
 
half operator+ (const half &a, const half &b)
 
half operator++ (half &a)
 
half operator++ (half &a, int)
 
halfoperator+= (half &a, const half &b)
 
half operator- (const half &a)
 
half operator- (const half &a, const half &b)
 
half operator-- (half &a)
 
half operator-- (half &a, int)
 
halfoperator-= (half &a, const half &b)
 
half operator/ (const half &a, const half &b)
 
half operator/ (const half &a, Index b)
 
halfoperator/= (half &a, const half &b)
 
bool operator< (const half &a, const half &b)
 
EIGEN_ALWAYS_INLINE std::ostream & operator<< (std::ostream &os, const half &v)
 
bool operator<= (const half &a, const half &b)
 
bool operator== (const half &a, const half &b)
 
bool operator> (const half &a, const half &b)
 
bool operator>= (const half &a, const half &b)
 
half pow (const half &a, const half &b)
 
numext::uint16_t raw_half_as_uint16 (const __half_raw &h)
 
EIGEN_CONSTEXPR __half_raw raw_uint16_to_half (numext::uint16_t x)
 
half rint (const half &a)
 
half round (const half &a)
 
half sin (const half &a)
 
half sqrt (const half &a)
 
half tan (const half &a)
 
half tanh (const half &a)
 

Function Documentation

◆ abs()

half Eigen::half_impl::abs ( const half a)
inline

Definition at line 712 of file Half.h.

712  {
713 #if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
714  return half(vabsh_f16(a.x));
715 #else
716  half result;
717  result.x = a.x & 0x7FFF;
718  return result;
719 #endif
720 }

◆ acos()

half Eigen::half_impl::acos ( const half a)
inline

Definition at line 779 of file Half.h.

779  {
780  return half(::acosf(float(a)));
781 }

◆ asin()

half Eigen::half_impl::asin ( const half a)
inline

Definition at line 776 of file Half.h.

776  {
777  return half(::asinf(float(a)));
778 }

◆ atan()

half Eigen::half_impl::atan ( const half a)
inline

Definition at line 782 of file Half.h.

782  {
783  return half(::atanf(float(a)));
784 }

◆ atan2()

half Eigen::half_impl::atan2 ( const half a,
const half b 
)
inline

Definition at line 761 of file Half.h.

761  {
762  return half(::atan2f(float(a), float(b)));
763 }
Array< int, 3, 1 > b

◆ atanh()

half Eigen::half_impl::atanh ( const half a)
inline

Definition at line 785 of file Half.h.

785  {
786  return half(::atanhf(float(a)));
787 }

◆ ceil()

half Eigen::half_impl::ceil ( const half a)
inline

Definition at line 796 of file Half.h.

796  {
797 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
798  defined(EIGEN_HIP_DEVICE_COMPILE)
799  return half(hceil(a));
800 #else
801  return half(::ceilf(float(a)));
802 #endif
803 }

◆ cos()

half Eigen::half_impl::cos ( const half a)
inline

Definition at line 767 of file Half.h.

767  {
768  return half(::cosf(float(a)));
769 }

◆ exp()

half Eigen::half_impl::exp ( const half a)
inline

Definition at line 721 of file Half.h.

721  {
722 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
723  defined(EIGEN_HIP_DEVICE_COMPILE)
724  return half(hexp(a));
725 #else
726  return half(::expf(float(a)));
727 #endif
728 }

◆ expm1()

half Eigen::half_impl::expm1 ( const half a)
inline

Definition at line 729 of file Half.h.

729  {
730  return half(numext::expm1(float(a)));
731 }
const Expm1ReturnType expm1() const

◆ float_to_half_rtne()

__half_raw Eigen::half_impl::float_to_half_rtne ( float  ff)
inline

Definition at line 585 of file Half.h.

585  {
586 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
587  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
588  __half tmp_ff = __float2half(ff);
589  return *(__half_raw*)&tmp_ff;
590 
591 #elif defined(EIGEN_HAS_FP16_C)
592  __half_raw h;
593  #if EIGEN_COMP_MSVC
594  // MSVC does not have scalar instructions.
595  h.x =_mm_extract_epi16(_mm_cvtps_ph(_mm_set_ss(ff), 0), 0);
596  #else
597  h.x = _cvtss_sh(ff, 0);
598  #endif
599  return h;
600 
601 #elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
602  __half_raw h;
603  h.x = static_cast<__fp16>(ff);
604  return h;
605 
606 #else
607  float32_bits f; f.f = ff;
608 
609  const float32_bits f32infty = { 255 << 23 };
610  const float32_bits f16max = { (127 + 16) << 23 };
611  const float32_bits denorm_magic = { ((127 - 15) + (23 - 10) + 1) << 23 };
612  unsigned int sign_mask = 0x80000000u;
613  __half_raw o;
614  o.x = static_cast<numext::uint16_t>(0x0u);
615 
616  unsigned int sign = f.u & sign_mask;
617  f.u ^= sign;
618 
619  // NOTE all the integer compares in this function can be safely
620  // compiled into signed compares since all operands are below
621  // 0x80000000. Important if you want fast straight SSE2 code
622  // (since there's no unsigned PCMPGTD).
623 
624  if (f.u >= f16max.u) { // result is Inf or NaN (all exponent bits set)
625  o.x = (f.u > f32infty.u) ? 0x7e00 : 0x7c00; // NaN->qNaN and Inf->Inf
626  } else { // (De)normalized number or zero
627  if (f.u < (113 << 23)) { // resulting FP16 is subnormal or zero
628  // use a magic value to align our 10 mantissa bits at the bottom of
629  // the float. as long as FP addition is round-to-nearest-even this
630  // just works.
631  f.f += denorm_magic.f;
632 
633  // and one integer subtract of the bias later, we have our final float!
634  o.x = static_cast<numext::uint16_t>(f.u - denorm_magic.u);
635  } else {
636  unsigned int mant_odd = (f.u >> 13) & 1; // resulting mantissa is odd
637 
638  // update exponent, rounding bias part 1
639  // Equivalent to `f.u += ((unsigned int)(15 - 127) << 23) + 0xfff`, but
640  // without arithmetic overflow.
641  f.u += 0xc8000fffU;
642  // rounding bias part 2
643  f.u += mant_odd;
644  // take the bits!
645  o.x = static_cast<numext::uint16_t>(f.u >> 13);
646  }
647  }
648 
649  o.x |= static_cast<numext::uint16_t>(sign >> 16);
650  return o;
651 #endif
652 }
const SignReturnType sign() const
std::uint16_t uint16_t
Definition: Meta.h:37

◆ floor()

half Eigen::half_impl::floor ( const half a)
inline

Definition at line 788 of file Half.h.

788  {
789 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 300) || \
790  defined(EIGEN_HIP_DEVICE_COMPILE)
791  return half(hfloor(a));
792 #else
793  return half(::floorf(float(a)));
794 #endif
795 }

◆ fmod()

half Eigen::half_impl::fmod ( const half a,
const half b 
)
inline

Definition at line 810 of file Half.h.

810  {
811  return half(::fmodf(float(a), float(b)));
812 }

◆ half_to_float()

float Eigen::half_impl::half_to_float ( __half_raw  h)
inline

Definition at line 654 of file Half.h.

654  {
655 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 300) || \
656  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
657  return __half2float(h);
658 #elif defined(EIGEN_HAS_FP16_C)
659  #if EIGEN_COMP_MSVC
660  // MSVC does not have scalar instructions.
661  return _mm_cvtss_f32(_mm_cvtph_ps(_mm_set1_epi16(h.x)));
662  #else
663  return _cvtsh_ss(h.x);
664  #endif
665 #elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
666  return static_cast<float>(h.x);
667 #else
668  const float32_bits magic = { 113 << 23 };
669  const unsigned int shifted_exp = 0x7c00 << 13; // exponent mask after shift
670  float32_bits o;
671 
672  o.u = (h.x & 0x7fff) << 13; // exponent/mantissa bits
673  unsigned int exp = shifted_exp & o.u; // just the exponent
674  o.u += (127 - 15) << 23; // exponent adjust
675 
676  // handle exponent special cases
677  if (exp == shifted_exp) { // Inf/NaN?
678  o.u += (128 - 16) << 23; // extra exp adjust
679  } else if (exp == 0) { // Zero/Denormal?
680  o.u += 1 << 23; // extra exp adjust
681  o.f -= magic.f; // renormalize
682  }
683 
684  o.u |= (h.x & 0x8000) << 16; // sign bit
685  return o.f;
686 #endif
687 }
const ExpReturnType exp() const

◆ isfinite()

bool() Eigen::half_impl::isfinite ( const half a)
inline

Definition at line 708 of file Half.h.

708  {
709  return !(isinf EIGEN_NOT_A_MACRO (a)) && !(isnan EIGEN_NOT_A_MACRO (a));
710 }
#define EIGEN_NOT_A_MACRO
Definition: Macros.h:804
bool() isnan(const half &a)
Definition: Half.h:698
bool() isinf(const half &a)
Definition: Half.h:691

◆ isinf()

bool() Eigen::half_impl::isinf ( const half a)
inline

Definition at line 691 of file Half.h.

691  {
692 #ifdef EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC
693  return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) == 0x7c00;
694 #else
695  return (a.x & 0x7fff) == 0x7c00;
696 #endif
697 }

◆ isnan()

bool() Eigen::half_impl::isnan ( const half a)
inline

Definition at line 698 of file Half.h.

698  {
699 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
700  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
701  return __hisnan(a);
702 #elif defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
703  return (numext::bit_cast<numext::uint16_t>(a.x) & 0x7fff) > 0x7c00;
704 #else
705  return (a.x & 0x7fff) > 0x7c00;
706 #endif
707 }

◆ log()

half Eigen::half_impl::log ( const half a)
inline

Definition at line 732 of file Half.h.

732  {
733 #if (defined(EIGEN_HAS_CUDA_FP16) && EIGEN_CUDA_SDK_VER >= 80000 && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
734  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
735  return half(::hlog(a));
736 #else
737  return half(::logf(float(a)));
738 #endif
739 }

◆ log10()

half Eigen::half_impl::log10 ( const half a)
inline

Definition at line 743 of file Half.h.

743  {
744  return half(::log10f(float(a)));
745 }

◆ log1p()

half Eigen::half_impl::log1p ( const half a)
inline

Definition at line 740 of file Half.h.

740  {
741  return half(numext::log1p(float(a)));
742 }
const Log1pReturnType log1p() const

◆ log2()

half Eigen::half_impl::log2 ( const half a)
inline

Definition at line 746 of file Half.h.

746  {
747  return half(static_cast<float>(EIGEN_LOG2E) * ::logf(float(a)));
748 }
#define EIGEN_LOG2E
Definition: MathFunctions.h:17

◆ max()

half() Eigen::half_impl::max ( const half a,
const half b 
)
inline

Definition at line 824 of file Half.h.

824  {
825 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
826  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
827  return __hlt(a, b) ? b : a;
828 #else
829  const float f1 = static_cast<float>(a);
830  const float f2 = static_cast<float>(b);
831  return f1 < f2 ? b : a;
832 #endif
833 }

◆ min()

half() Eigen::half_impl::min ( const half a,
const half b 
)
inline

Definition at line 814 of file Half.h.

814  {
815 #if (defined(EIGEN_HAS_CUDA_FP16) && defined(EIGEN_CUDA_ARCH) && EIGEN_CUDA_ARCH >= 530) || \
816  (defined(EIGEN_HAS_HIP_FP16) && defined(EIGEN_HIP_DEVICE_COMPILE))
817  return __hlt(b, a) ? b : a;
818 #else
819  const float f1 = static_cast<float>(a);
820  const float f2 = static_cast<float>(b);
821  return f2 < f1 ? b : a;
822 #endif
823 }

◆ operator!=()

bool Eigen::half_impl::operator!= ( const half a,
const half b 
)
inline

Definition at line 497 of file Half.h.

497  {
498  return numext::not_equal_strict(float(a), float(b));
499 }
bool not_equal_strict(const X &x, const Y &y)
Definition: Meta.h:485

◆ operator*()

half Eigen::half_impl::operator* ( const half a,
const half b 
)
inline

Definition at line 464 of file Half.h.

464  {
465  return half(float(a) * float(b));
466 }

◆ operator*=()

half& Eigen::half_impl::operator*= ( half a,
const half b 
)
inline

Definition at line 482 of file Half.h.

482  {
483  a = half(float(a) * float(b));
484  return a;
485 }

◆ operator+()

half Eigen::half_impl::operator+ ( const half a,
const half b 
)
inline

Definition at line 461 of file Half.h.

461  {
462  return half(float(a) + float(b));
463 }

◆ operator++() [1/2]

half Eigen::half_impl::operator++ ( half a)
inline

Definition at line 524 of file Half.h.

524  {
525  a += half(1);
526  return a;
527 }

◆ operator++() [2/2]

half Eigen::half_impl::operator++ ( half a,
int   
)
inline

Definition at line 534 of file Half.h.

534  {
535  half original_value = a;
536  ++a;
537  return original_value;
538 }

◆ operator+=()

half& Eigen::half_impl::operator+= ( half a,
const half b 
)
inline

Definition at line 478 of file Half.h.

478  {
479  a = half(float(a) + float(b));
480  return a;
481 }

◆ operator-() [1/2]

half Eigen::half_impl::operator- ( const half a)
inline

Definition at line 473 of file Half.h.

473  {
474  half result;
475  result.x = a.x ^ 0x8000;
476  return result;
477 }

◆ operator-() [2/2]

half Eigen::half_impl::operator- ( const half a,
const half b 
)
inline

Definition at line 467 of file Half.h.

467  {
468  return half(float(a) - float(b));
469 }

◆ operator--() [1/2]

half Eigen::half_impl::operator-- ( half a)
inline

Definition at line 529 of file Half.h.

529  {
530  a -= half(1);
531  return a;
532 }

◆ operator--() [2/2]

half Eigen::half_impl::operator-- ( half a,
int   
)
inline

Definition at line 540 of file Half.h.

540  {
541  half original_value = a;
542  --a;
543  return original_value;
544 }

◆ operator-=()

half& Eigen::half_impl::operator-= ( half a,
const half b 
)
inline

Definition at line 486 of file Half.h.

486  {
487  a = half(float(a) - float(b));
488  return a;
489 }

◆ operator/() [1/2]

half Eigen::half_impl::operator/ ( const half a,
const half b 
)
inline

Definition at line 470 of file Half.h.

470  {
471  return half(float(a) / float(b));
472 }

◆ operator/() [2/2]

half Eigen::half_impl::operator/ ( const half a,
Index  b 
)
inline

Definition at line 520 of file Half.h.

520  {
521  return half(static_cast<float>(a) / static_cast<float>(b));
522 }

◆ operator/=()

half& Eigen::half_impl::operator/= ( half a,
const half b 
)
inline

Definition at line 490 of file Half.h.

490  {
491  a = half(float(a) / float(b));
492  return a;
493 }

◆ operator<()

bool Eigen::half_impl::operator< ( const half a,
const half b 
)
inline

Definition at line 500 of file Half.h.

500  {
501  return float(a) < float(b);
502 }

◆ operator<<()

EIGEN_ALWAYS_INLINE std::ostream& Eigen::half_impl::operator<< ( std::ostream &  os,
const half v 
)

Definition at line 836 of file Half.h.

836  {
837  os << static_cast<float>(v);
838  return os;
839 }
Array< int, Dynamic, 1 > v

◆ operator<=()

bool Eigen::half_impl::operator<= ( const half a,
const half b 
)
inline

Definition at line 503 of file Half.h.

503  {
504  return float(a) <= float(b);
505 }

◆ operator==()

bool Eigen::half_impl::operator== ( const half a,
const half b 
)
inline

Definition at line 494 of file Half.h.

494  {
495  return numext::equal_strict(float(a),float(b));
496 }
bool equal_strict(const X &x, const Y &y)
Definition: Meta.h:460

◆ operator>()

bool Eigen::half_impl::operator> ( const half a,
const half b 
)
inline

Definition at line 506 of file Half.h.

506  {
507  return float(a) > float(b);
508 }

◆ operator>=()

bool Eigen::half_impl::operator>= ( const half a,
const half b 
)
inline

Definition at line 509 of file Half.h.

509  {
510  return float(a) >= float(b);
511 }

◆ pow()

half Eigen::half_impl::pow ( const half a,
const half b 
)
inline

Definition at line 758 of file Half.h.

758  {
759  return half(::powf(float(a), float(b)));
760 }

◆ raw_half_as_uint16()

numext::uint16_t Eigen::half_impl::raw_half_as_uint16 ( const __half_raw h)
inline

Definition at line 567 of file Half.h.

567  {
568  // HIP/CUDA/Default have a member 'x' of type uint16_t.
569  // For ARM64 native half, the member 'x' is of type __fp16, so we need to bit-cast.
570  // For SYCL, cl::sycl::half is _Float16, so cast directly.
571 #if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
572  return numext::bit_cast<numext::uint16_t>(h.x);
573 #elif defined(SYCL_DEVICE_ONLY)
574  return numext::bit_cast<numext::uint16_t>(h);
575 #else
576  return h.x;
577 #endif
578 }

◆ raw_uint16_to_half()

EIGEN_CONSTEXPR __half_raw Eigen::half_impl::raw_uint16_to_half ( numext::uint16_t  x)
inline

Definition at line 551 of file Half.h.

551  {
552  // We cannot simply do a "return __half_raw(x)" here, because __half_raw is union type
553  // in the hip_fp16 header file, and that will trigger a compile error
554  // On the other hand, having anything but a return statement also triggers a compile error
555  // because this is constexpr function.
556  // Fortunately, since we need to disable EIGEN_CONSTEXPR for GPU anyway, we can get out
557  // of this catch22 by having separate bodies for GPU / non GPU
558 #if defined(EIGEN_HAS_GPU_FP16)
559  __half_raw h;
560  h.x = x;
561  return h;
562 #else
563  return __half_raw(x);
564 #endif
565 }

◆ rint()

half Eigen::half_impl::rint ( const half a)
inline

Definition at line 804 of file Half.h.

804  {
805  return half(::rintf(float(a)));
806 }

◆ round()

half Eigen::half_impl::round ( const half a)
inline

Definition at line 807 of file Half.h.

807  {
808  return half(::roundf(float(a)));
809 }

◆ sin()

half Eigen::half_impl::sin ( const half a)
inline

Definition at line 764 of file Half.h.

764  {
765  return half(::sinf(float(a)));
766 }

◆ sqrt()

half Eigen::half_impl::sqrt ( const half a)
inline

Definition at line 750 of file Half.h.

750  {
751 #if (EIGEN_CUDA_SDK_VER >= 80000 && defined EIGEN_CUDA_ARCH && EIGEN_CUDA_ARCH >= 530) || \
752  defined(EIGEN_HIP_DEVICE_COMPILE)
753  return half(hsqrt(a));
754 #else
755  return half(::sqrtf(float(a)));
756 #endif
757 }

◆ tan()

half Eigen::half_impl::tan ( const half a)
inline

Definition at line 770 of file Half.h.

770  {
771  return half(::tanf(float(a)));
772 }

◆ tanh()

half Eigen::half_impl::tanh ( const half a)
inline

Definition at line 773 of file Half.h.

773  {
774  return half(::tanhf(float(a)));
775 }