16#ifndef EIGEN_BFLOAT16_H
17#define EIGEN_BFLOAT16_H
19#define BF16_PACKET_FUNCTION(PACKET_F, PACKET_BF16, METHOD) \
21 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED \
22 PACKET_BF16 METHOD<PACKET_BF16>(const PACKET_BF16& _x) { \
23 return F32ToBf16(METHOD<PACKET_F>(Bf16ToF32(_x))); \
30namespace bfloat16_impl {
40template <
bool AssumeArgumentIsNormalOrInfinityOrZero>
78 template<
typename RealScalar>
90struct numeric_limits<
Eigen::bfloat16> {
91 static const bool is_specialized =
true;
94 static const bool is_exact =
false;
95 static const bool has_infinity =
true;
96 static const bool has_quiet_NaN =
true;
97 static const bool has_signaling_NaN =
true;
98 static const float_denorm_style has_denorm = std::denorm_absent;
99 static const bool has_denorm_loss =
false;
100 static const std::float_round_style round_style = numeric_limits<float>::round_style;
101 static const bool is_iec559 =
false;
102 static const bool is_bounded =
true;
103 static const bool is_modulo =
false;
106 static const int max_digits10 = 4;
107 static const int radix = 2;
108 static const int min_exponent = numeric_limits<float>::min_exponent;
109 static const int min_exponent10 = numeric_limits<float>::min_exponent10;
110 static const int max_exponent = numeric_limits<float>::max_exponent;
111 static const int max_exponent10 = numeric_limits<float>::max_exponent10;
112 static const bool traps = numeric_limits<float>::traps;
113 static const bool tinyness_before = numeric_limits<float>::tinyness_before;
131struct numeric_limits<const
Eigen::bfloat16> : numeric_limits<Eigen::bfloat16> {};
133struct numeric_limits<volatile
Eigen::bfloat16> : numeric_limits<Eigen::bfloat16> {};
135struct numeric_limits<const volatile
Eigen::bfloat16> : numeric_limits<Eigen::bfloat16> {};
140namespace bfloat16_impl {
145#if !defined(EIGEN_HAS_NATIVE_BF16) || (EIGEN_COMP_CLANG && !EIGEN_COMP_NVCC)
147#if EIGEN_COMP_CLANG && defined(EIGEN_CUDACC)
149#pragma push_macro("EIGEN_DEVICE_FUNC")
150#undef EIGEN_DEVICE_FUNC
151#if defined(EIGEN_HAS_CUDA_BF16) && defined(EIGEN_HAS_NATIVE_BF16)
152#define EIGEN_DEVICE_FUNC __host__
154#define EIGEN_DEVICE_FUNC __host__ __device__
165 return bfloat16(
float(a) +
static_cast<float>(
b));
168 return bfloat16(
static_cast<float>(a) +
float(
b));
211 return original_value;
216 return original_value;
225 return float(a) < float(
b);
228 return float(a) <= float(
b);
231 return float(a) > float(
b);
234 return float(a) >= float(
b);
237#if EIGEN_COMP_CLANG && defined(EIGEN_CUDACC)
238#pragma pop_macro("EIGEN_DEVICE_FUNC")
245 return bfloat16(
static_cast<float>(a) /
static_cast<float>(
b));
255#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
275#if (defined(EIGEN_HAS_CUDA_BF16) && defined(EIGEN_HAS_HIP_BF16))
449#if (defined(EIGEN_HAS_CUDA_BF16) && defined(EIGEN_HAS_HIP_BF16))
458 input += rounding_bias;
466 unsigned short* q =
reinterpret_cast<unsigned short*
>(&
result);
467#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
478 return (
isinf)(float(a));
482 return (
isnan)(float(a));
506 return bfloat16(::log10f(
float(a)));
515 return bfloat16(::powf(
float(a),
float(
b)));
544#if EIGEN_HAS_CXX11_MATH
546 return bfloat16(::asinhf(
float(a)));
549 return bfloat16(::acoshf(
float(a)));
552 return bfloat16(::atanhf(
float(a)));
556 return bfloat16(::floorf(
float(a)));
565 return bfloat16(::roundf(
float(a)));
568 return bfloat16(::fmodf(
float(a),
float(
b)));
572 const float f1 =
static_cast<float>(a);
573 const float f2 =
static_cast<float>(
b);
574 return f2 < f1 ?
b : a;
577 const float f1 =
static_cast<float>(a);
578 const float f2 =
static_cast<float>(
b);
579 return f1 < f2 ?
b : a;
583 const float f1 =
static_cast<float>(a);
584 const float f2 =
static_cast<float>(
b);
588 const float f1 =
static_cast<float>(a);
589 const float f2 =
static_cast<float>(
b);
595 os << static_cast<float>(v);
609 return x + (
y-x) *
bfloat16(
float(std::rand()) / float(RAND_MAX));
688#if EIGEN_HAS_STD_HASH
691struct hash<
Eigen::bfloat16> {
693 return static_cast<std::size_t
>(Eigen::numext::bit_cast<Eigen::numext::uint16_t>(a));
EIGEN_DEVICE_FUNC RealReturnType real() const
Definition: CommonCwiseUnaryOps.h:100
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typenameEIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
Definition: IndexedViewMethods.h:73
#define EIGEN_ALWAYS_INLINE
Definition: Macros.h:942
#define EIGEN_USING_STD(FUNC)
Definition: Macros.h:1195
#define EIGEN_CONSTEXPR
Definition: Macros.h:797
#define EIGEN_DEVICE_FUNC
Definition: Macros.h:986
#define EIGEN_NOT_A_MACRO
Definition: Macros.h:906
#define EIGEN_STRONG_INLINE
Definition: Macros.h:927
#define EIGEN_LOG2E
Definition: MathFunctions.h:17
constexpr return_t< T > acosh(const T x) noexcept
Compile-time inverse hyperbolic cosine function.
Definition: acosh.hpp:62
constexpr return_t< T > asinh(const T x) noexcept
Compile-time inverse hyperbolic sine function.
Definition: asinh.hpp:59
constexpr return_t< T > atanh(const T x) noexcept
Compile-time inverse hyperbolic tangent function.
Definition: atanh.hpp:73
constexpr common_t< T1, T2 > max(const T1 x, const T2 y) noexcept
Compile-time pairwise maximum function.
Definition: max.hpp:35
constexpr common_t< T1, T2 > min(const T1 x, const T2 y) noexcept
Compile-time pairwise minimum function.
Definition: min.hpp:35
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne(float ff)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16() max(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:576
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator/(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:176
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 tanh(const bfloat16 &a)
Definition: BFloat16.h:541
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:224
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 & operator*=(bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:188
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 floor(const bfloat16 &a)
Definition: BFloat16.h:555
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>=(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:233
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator+(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:161
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 cosh(const bfloat16 &a)
Definition: BFloat16.h:538
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16() min(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:571
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 ceil(const bfloat16 &a)
Definition: BFloat16.h:558
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 acos(const bfloat16 &a)
Definition: BFloat16.h:529
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log2(const bfloat16 &a)
Definition: BFloat16.h:508
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw raw_uint16_to_bfloat16(numext::uint16_t value)
Definition: BFloat16.h:263
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 rint(const bfloat16 &a)
Definition: BFloat16.h:561
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 & operator/=(bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:196
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator-(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:173
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw truncate_to_bfloat16(const float v)
Definition: BFloat16.h:248
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator--(bfloat16 &a)
Definition: BFloat16.h:204
EIGEN_ALWAYS_INLINE std::ostream & operator<<(std::ostream &os, const bfloat16 &v)
Definition: BFloat16.h:594
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 & operator-=(bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:192
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 asin(const bfloat16 &a)
Definition: BFloat16.h:526
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isfinite(const bfloat16 &a)
Definition: BFloat16.h:484
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmod(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:567
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log10(const bfloat16 &a)
Definition: BFloat16.h:505
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw raw_uint16_to_bfloat16(unsigned short value)
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmin(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:582
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 atan(const bfloat16 &a)
Definition: BFloat16.h:532
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmax(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:587
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 cos(const bfloat16 &a)
Definition: BFloat16.h:520
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:493
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 pow(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:514
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR numext::uint16_t raw_bfloat16_as_uint16(const __bfloat16_raw &bf)
Definition: BFloat16.h:267
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 expm1(const bfloat16 &a)
Definition: BFloat16.h:496
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sqrt(const bfloat16 &a)
Definition: BFloat16.h:511
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator==(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:218
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne< false >(float ff)
Definition: BFloat16.h:274
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 round(const bfloat16 &a)
Definition: BFloat16.h:564
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:499
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator!=(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:221
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator>(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:230
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 abs(const bfloat16 &a)
Definition: BFloat16.h:488
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sinh(const bfloat16 &a)
Definition: BFloat16.h:535
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isnan(const bfloat16 &a)
Definition: BFloat16.h:480
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC __bfloat16_raw float_to_bfloat16_rtne< true >(float ff)
Definition: BFloat16.h:448
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 tan(const bfloat16 &a)
Definition: BFloat16.h:523
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator*(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:170
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool operator<=(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:227
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sin(const bfloat16 &a)
Definition: BFloat16.h:517
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 & operator+=(bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:184
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool() isinf(const bfloat16 &a)
Definition: BFloat16.h:476
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log1p(const bfloat16 &a)
Definition: BFloat16.h:502
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC float bfloat16_to_float(__bfloat16_raw h)
Definition: BFloat16.h:464
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 operator++(bfloat16 &a)
Definition: BFloat16.h:200
const Scalar & y
Definition: MathFunctions.h:821
::uint16_t uint16_t
Definition: Meta.h:54
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isinf(const Eigen::bfloat16 &h)
Definition: BFloat16.h:665
::uint32_t uint32_t
Definition: Meta.h:56
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool equal_strict(const X &x, const Y &y)
Definition: Meta.h:787
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isfinite(const Eigen::bfloat16 &h)
Definition: BFloat16.h:671
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE bool() isnan(const Eigen::bfloat16 &h)
Definition: BFloat16.h:659
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bool not_equal_strict(const X &x, const Y &y)
Definition: Meta.h:798
Namespace containing all symbols from the Eigen library.
Definition: Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
Definition: format.h:2563
result
Definition: format.h:2564
Definition: Eigen_Colamd.h:50
Definition: BFloat16.h:88
static constexpr const unit_t< compound_unit< energy::joule, time::seconds > > h(6.626070040e-34)
Planck constant.
constexpr bool signbit(const T x) noexcept
Compile-time sign bit detection function.
Definition: signbit.hpp:34
Definition: NumTraits.h:153
@ RequireInitialization
Definition: NumTraits.h:158
@ IsSigned
Definition: NumTraits.h:156
@ IsInteger
Definition: NumTraits.h:155
@ IsComplex
Definition: NumTraits.h:157
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::bfloat16 highest()
Definition: BFloat16.h:638
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::bfloat16 lowest()
Definition: BFloat16.h:641
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::bfloat16 infinity()
Definition: BFloat16.h:644
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::bfloat16 quiet_NaN()
Definition: BFloat16.h:647
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::bfloat16 dummy_precision()
Definition: BFloat16.h:634
EIGEN_DEVICE_FUNC static EIGEN_CONSTEXPR EIGEN_STRONG_INLINE Eigen::bfloat16 epsilon()
Definition: BFloat16.h:631
Holds information about the various numeric (i.e.
Definition: NumTraits.h:233
Definition: BFloat16.h:33
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw()
Definition: BFloat16.h:34
unsigned short value
Definition: BFloat16.h:36
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR __bfloat16_raw(unsigned short raw)
Definition: BFloat16.h:35
Definition: BFloat16.h:50
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16_base()
Definition: BFloat16.h:51
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16_base(const __bfloat16_raw &h)
Definition: BFloat16.h:52
Definition: BFloat16.h:58
bfloat16_impl::__bfloat16_raw __bfloat16_raw
Definition: BFloat16.h:60
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(const __bfloat16_raw &h)
Definition: BFloat16.h:64
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(const std::complex< RealScalar > &val)
Definition: BFloat16.h:79
EIGEN_DEVICE_FUNC bfloat16(float f)
Definition: BFloat16.h:73
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(T val)
Definition: BFloat16.h:70
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16()
Definition: BFloat16.h:62
EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR bfloat16(bool b)
Definition: BFloat16.h:66
static bfloat16 run()
Definition: BFloat16.h:611
static bfloat16 run(const bfloat16 &x, const bfloat16 &y)
Definition: BFloat16.h:607
Definition: MathFunctions.h:810
static Eigen::bfloat16 signaling_NaN()
Definition: BFloat16.h:122
static Eigen::bfloat16 epsilon()
Definition: BFloat16.h:118
static Eigen::bfloat16 lowest()
Definition: BFloat16.h:116
static Eigen::bfloat16 denorm_min()
Definition: BFloat16.h:123
static Eigen::bfloat16 round_error()
Definition: BFloat16.h:119
static Eigen::bfloat16 quiet_NaN()
Definition: BFloat16.h:121
static Eigen::bfloat16 infinity()
Definition: BFloat16.h:120