7 #include <hip/hip_fp16.h>
28 #if CK_TILE_USE_CUSTOM_DATA_TYPE
44 constexpr
fp16_hip_t to_fp16()
const {
return ck_tile::bit_cast<fp16_hip_t>(data); }
47 constexpr
half_t() : data{} {}
67 explicit constexpr
half_t(
const unsigned int& x)
74 explicit constexpr
operator float()
const {
return fp16_to_float_hip(to_fp16()); }
82 explicit constexpr
operator int()
const
88 explicit constexpr
operator fp16_hip_t()
const {
return ck_tile::bit_cast<fp16_hip_t>(data); }
92 constexpr raw_type& get() {
return data; }
95 constexpr raw_type get()
const {
return data; }
104 using type = _Float16;
120 return static_cast<float>(x);
165 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x0400));
171 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0xFBFF));
177 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x7BFF));
183 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x1800));
193 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x3800));
199 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x7C00));
205 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x7FFF));
211 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x7FFF));
217 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0x0001));
222 return bit_cast<half_t>(
static_cast<fp16_raw_t>(0));
226 template <
typename T>
227 struct numeric_traits;
232 static constexpr
int exp = 5;
233 static constexpr
int mant = 10;
234 static constexpr
int bias = 15;
235 static constexpr uint16_t nan_mask = 0x7C00;
236 static constexpr uint16_t head_mask = 0xFC00;
237 static constexpr uint16_t mant_mask = 0x3FF;
238 static constexpr uint16_t exp_mask = 0x1F;
239 static constexpr uint16_t abs_mask = 0x7FFF;
240 static constexpr uint16_t Inf = 0x7C00;
241 static constexpr uint16_t NegInf = 0xFC00;
242 static constexpr uint16_t NaN = 0x7C01;
243 static constexpr uint16_t Neg0 = 0x8000;
247 #if CK_TILE_USE_CUSTOM_DATA_TYPE
251 return __heq(x.to_fp16(), y.to_fp16());
258 bool operator<(
const half_t& x,
const half_t& y) {
return __hlt(x.to_fp16(), y.to_fp16()); }
261 bool operator<=(
const half_t& x,
const half_t& y) {
return __hle(x.to_fp16(), y.to_fp16()); }
264 bool operator>(
const half_t& x,
const half_t& y) {
return __hgt(x.to_fp16(), y.to_fp16()); }
267 bool operator>=(
const half_t& x,
const half_t& y) {
return __hge(x.to_fp16(), y.to_fp16()); }
273 return half_t(__hadd(x.to_fp16(), y.to_fp16()));
282 return half_t(__hsub(x.to_fp16(), y.to_fp16()));
288 return half_t(__hmul(x.to_fp16(), y.to_fp16()));
294 return half_t(__hdiv(x.to_fp16(), y.to_fp16()));
300 x =
half_t(__hadd(x.to_fp16(), y.to_fp16()));
307 x =
half_t(__hsub(x.to_fp16(), y.to_fp16()));
314 x =
half_t(__hmul(x.to_fp16(), y.to_fp16()));
321 x =
half_t(__hdiv(x.to_fp16(), y.to_fp16()));
328 x =
half_t(__hadd(x.to_fp16(),
half_t(1.0f).to_fp16()));
335 x =
half_t(__hsub(x.to_fp16(),
half_t(1.0f).to_fp16()));
343 x =
half_t(__hadd(x.to_fp16(),
half_t(1.0f).to_fp16()));
351 x =
half_t(__hsub(x.to_fp16(),
half_t(1.0f).to_fp16()));
356 #if CK_TILE_USE_CUSTOM_DATA_TYPE
362 half_t abs(
const half_t& x) {
return bit_cast<half_t>(x.get() & 0x7fff); }
367 uint16_t xx = x.get();
368 return (xx & 0x7FFF) > 0x7C00;
374 return static_cast<half_t>(__builtin_amdgcn_sqrtf(
static_cast<float>(x)));
#define CK_TILE_DEVICE
Definition: config.hpp:40
#define CK_TILE_HOST
Definition: config.hpp:39
#define CK_TILE_HOST_DEVICE
Definition: config.hpp:41
Definition: cluster_descriptor.hpp:13
CK_TILE_DEVICE bfloat16_t log(bfloat16_t x)
Definition: bfloat16.hpp:423
constexpr CK_TILE_HOST_DEVICE float fp16_to_float_hip(const fp16_hip_t &x)
Definition: half.hpp:117
constexpr CK_TILE_HOST_DEVICE auto operator-(const multi_index< NSize > &a, const T &b)
Definition: multi_index.hpp:65
constexpr CK_TILE_HOST_DEVICE auto operator+(const multi_index< NSize > &a, const T &b)
Definition: multi_index.hpp:55
constexpr CK_TILE_HOST_DEVICE Y bit_cast(const X &x)
Definition: bit_cast.hpp:11
constexpr CK_TILE_HOST_DEVICE half_t double_to_fp16(const double &x)
Definition: half.hpp:153
_Float16 fp16_t
Definition: half.hpp:110
uint16_t fp16_raw_t
Definition: half.hpp:14
constexpr CK_TILE_HOST_DEVICE auto operator/(sequence< Xs... >, sequence< Ys... >)
Definition: sequence.hpp:728
constexpr CK_TILE_HOST_DEVICE half_t float_to_fp16(const float &x)
Definition: half.hpp:150
_Float16 fp16_hip_t
Definition: half.hpp:13
CK_TILE_DEVICE bfloat16_t sqrt(bfloat16_t x)
Definition: bfloat16.hpp:408
constexpr CK_TILE_HOST_DEVICE fp16_hip_t double_to_fp16_hip(const double &x)
Definition: half.hpp:137
CK_TILE_DEVICE bfloat16_t exp(bfloat16_t x)
Definition: bfloat16.hpp:414
constexpr CK_TILE_HOST_DEVICE auto operator-=(multi_index< NSize > &y, const X &x)
Definition: multi_index.hpp:47
constexpr CK_TILE_HOST_DEVICE double fp16_to_double_hip(const fp16_hip_t &x)
Definition: half.hpp:124
CK_TILE_HOST_DEVICE bfloat16_t abs(const bfloat16_t &x)
Definition: bfloat16.hpp:395
constexpr CK_TILE_HOST_DEVICE bool operator==(const array< T, Size > &a, const array< T, Size > &b)
Definition: array.hpp:218
constexpr CK_TILE_HOST_DEVICE auto operator+=(multi_index< NSize > &y, const X &x)
Definition: multi_index.hpp:39
constexpr CK_TILE_HOST_DEVICE float fp16_to_double(const half_t &x)
Definition: half.hpp:147
CK_TILE_HOST_DEVICE bool isnan(const bfloat16_t &x)
Definition: bfloat16.hpp:401
constexpr CK_TILE_HOST_DEVICE float fp16_to_float(const half_t &x)
Definition: half.hpp:144
constexpr CK_TILE_HOST_DEVICE auto operator*(const multi_index< NSize > &a, const T &b)
Definition: multi_index.hpp:75
constexpr CK_TILE_HOST_DEVICE fp16_hip_t float_to_fp16_hip(const float &x)
Definition: half.hpp:130
_Float16 half_t
Definition: half.hpp:111
constexpr CK_TILE_HOST_DEVICE bool operator!=(const array< T, Size > &a, const array< T, Size > &b)
Definition: array.hpp:235
CK_TILE_DEVICE bfloat16_t exp2(bfloat16_t x)
Definition: bfloat16.hpp:420
remove_cvref_t< T > type
Definition: vector_type.hpp:25
static constexpr CK_TILE_HOST_DEVICE half_t round_error()
Definition: half.hpp:191
static constexpr CK_TILE_HOST_DEVICE half_t infinity()
Definition: half.hpp:197
static constexpr CK_TILE_HOST_DEVICE half_t lowest()
Definition: half.hpp:169
static constexpr CK_TILE_HOST_DEVICE half_t epsilon()
Definition: half.hpp:181
static constexpr CK_TILE_HOST_DEVICE half_t min()
Definition: half.hpp:163
static constexpr CK_TILE_HOST_DEVICE half_t max()
Definition: half.hpp:175
static constexpr CK_TILE_HOST_DEVICE half_t signaling_NaN()
Definition: half.hpp:209
static constexpr CK_TILE_HOST_DEVICE half_t zero()
Definition: half.hpp:220
static constexpr CK_TILE_HOST_DEVICE half_t quiet_NaN()
Definition: half.hpp:203
static constexpr CK_TILE_HOST_DEVICE half_t denorm_min()
Definition: half.hpp:215
uint16_t bitwise_type
Definition: half.hpp:244
Definition: bfloat16.hpp:380
Definition: numeric.hpp:18
#define CK_TILE_ARITHMETIC_USING_FLOAT(attr_, type_)
Definition: numeric.hpp:102