3#ifndef poplar_HalfFloat_hpp_
4#define poplar_HalfFloat_hpp_
12#include <poplar/IeeeHalf.hpp>
17template <
typename T>
class HalfFloatType {
22 HalfFloatType(
float val) : data(val) {
23 static_assert(std::is_standard_layout<HalfFloatType>::value,
24 "Invalid HalfFloatType class layout");
27 HalfFloatType(
double val) : HalfFloatType((float)val) {}
29 HalfFloatType(
int val) : HalfFloatType((float)val) {}
30 HalfFloatType(
unsigned val) : HalfFloatType((float)val) {}
32 HalfFloatType(int64_t val) : HalfFloatType((float)val) {}
33 HalfFloatType(uint64_t val) : HalfFloatType((float)val) {}
35 HalfFloatType() =
default;
37 HalfFloatType &operator=(
const float &other) {
42 operator float()
const {
return this->data; }
44 HalfFloatType &operator+=(
const float &other) {
49 HalfFloatType &operator-=(
const float &other) {
54 HalfFloatType &operator*=(
const float &other) {
59 HalfFloatType &operator/=(
const float &other) {
65typedef HalfFloatType<IeeeHalf> AccurateHalf;
66typedef HalfFloatType<float> FastHalf;
68static_assert(std::is_standard_layout<AccurateHalf>::value,
"");
69static_assert(std::is_standard_layout<FastHalf>::value,
"");
75template <
typename T>
struct is_poplar_half {
76 static const bool value =
false;
79template <>
struct is_poplar_half<AccurateHalf> {
80 static const bool value =
true;
83template <>
struct is_poplar_half<const AccurateHalf> {
84 static const bool value =
true;
87template <>
struct is_poplar_half<FastHalf> {
static const bool value =
true; };
89template <>
struct is_poplar_half<const FastHalf> {
90 static const bool value =
true;
93template <>
struct is_poplar_half<IeeeHalf> {
static const bool value =
true; };
95template <>
struct is_poplar_half<const IeeeHalf> {
96 static const bool value =
true;
101#ifdef POPLAR_ACCURATE_HALF
102typedef poplar::AccurateHalf half;
104typedef poplar::FastHalf half;
118template <>
class numeric_limits<half> {
122 static constexpr bool is_specialized =
true;
124 static constexpr const bool is_signed =
true;
125 static constexpr const int digits = 11;
126 static constexpr const int digits10 = 3;
127 static constexpr const int max_digits10 = 5;
129 static type
min() noexcept {
return type(0.0f); }
130 static type
max() noexcept {
return type(65504.0f); }
131 static type lowest() noexcept {
return type(-
max()); }
133 static constexpr const bool is_integer =
false;
134 static constexpr const bool is_exact =
false;
135 static constexpr const int radix = 2;
137 static type epsilon() noexcept {
139 return type(0.0009765625f);
141 static type round_error() noexcept {
147 static constexpr const int min_exponent = -13;
148 static constexpr const int min_exponent10 = -4;
149 static constexpr const int max_exponent = 16;
150 static constexpr const int max_exponent10 = 4;
154 static constexpr const bool has_infinity =
false;
155 static constexpr const bool has_quiet_NaN =
true;
156 static constexpr const bool has_signaling_NaN =
false;
157 static constexpr const float_denorm_style has_denorm = denorm_present;
158 static constexpr const bool has_denorm_loss =
false;
170 static type infinity() noexcept {
171 return type(std::numeric_limits<float>::infinity());
174 static type quiet_NaN() noexcept {
175 return type(std::numeric_limits<float>::quiet_NaN());
179 static type signaling_NaN() noexcept {
180 return type(std::numeric_limits<float>::quiet_NaN());
183 static type denorm_min() noexcept {
185 return type(0.00000005960464477539f);
189 static constexpr const bool is_iec559 =
false;
190 static constexpr const bool is_bounded =
true;
191 static constexpr const bool is_modulo =
false;
193 static constexpr const bool traps =
false;
194 static constexpr const bool tinyness_before =
false;
198 static constexpr const float_round_style round_style = round_indeterminate;
half2 max(half2 src0, half2 src1)
Targets the f16v2max instruction.
Definition: ipu_intrinsics:333
half2 min(half2 src0, half2 src1)
Targets the f16v2min instruction.
Definition: ipu_intrinsics:384
Poplar classes and functions.
Definition: ArrayRef.hpp:14