e8m0.hpp Source File

e8m0.hpp Source File#

Composable Kernel: e8m0.hpp Source File
tile/core/numeric/e8m0.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved.
3
4#pragma once
5
8
9namespace ck_tile {
10
25
27{
29 using type = raw_type;
30
32
33 CK_TILE_HOST_DEVICE constexpr e8m0_bexp_t() : data{type{0b11111111}} {}
34 CK_TILE_HOST_DEVICE explicit constexpr e8m0_bexp_t(type init) : data{init} {}
35 CK_TILE_HOST_DEVICE explicit constexpr e8m0_bexp_t(float scale)
36 : e8m0_bexp_t(static_cast<type>(numeric_utils<float>::get_exponent(scale)))
37 {
38 }
39 CK_TILE_HOST_DEVICE constexpr operator type() const { return data; }
40 CK_TILE_HOST_DEVICE constexpr raw_type& get() { return data; }
41 CK_TILE_HOST_DEVICE constexpr raw_type get() const { return data; }
42 CK_TILE_HOST_DEVICE constexpr operator float() const;
43
44 constexpr bool operator==(const e8m0_bexp_t& other) const { return data == other.data; }
45
46 constexpr bool operator!=(const e8m0_bexp_t& other) const { return data != other.data; }
47};
48
51
52template <>
54{
56
57 static constexpr int exp = 8;
58 static constexpr int mant = 0;
59 static constexpr int bias = 127;
60 static constexpr int PackedSize = 1;
61};
62
63// limits
64template <class T>
65struct numeric;
66
67template <>
69{
70 static constexpr e8m0_raw_t binary_min = 0b00000000; // 2^-127
71 static constexpr e8m0_raw_t binary_max = 0b11111110; // 2^127
72 static constexpr e8m0_raw_t binary_nan = 0b11111111;
73 CK_TILE_HOST_DEVICE static constexpr e8m0_t min() { return e8m0_t{binary_min}; }
74 CK_TILE_HOST_DEVICE static constexpr e8m0_t max() { return e8m0_t{binary_max}; }
75 CK_TILE_HOST_DEVICE static constexpr e8m0_t quiet_NaN() { return e8m0_t{binary_nan}; }
77 CK_TILE_HOST_DEVICE static constexpr bool has_inf() { return false; }
78
79 CK_TILE_HOST_DEVICE static constexpr e8m0_t epsilon() { return signaling_NaN(); }
80 CK_TILE_HOST_DEVICE static constexpr e8m0_t round_error() { return signaling_NaN(); }
81 CK_TILE_HOST_DEVICE static constexpr e8m0_t zero() { return signaling_NaN(); }
82 CK_TILE_HOST_DEVICE static constexpr e8m0_t infinity() { return signaling_NaN(); }
83};
84
85CK_TILE_HOST_DEVICE constexpr e8m0_bexp_t::operator float() const
86{
87 using traits = numeric_traits<float>;
89 {
90 return std::numeric_limits<float>::signaling_NaN();
91 }
92 else if(data == 0)
93 {
94 return std::numeric_limits<float>::min();
95 }
96 else
97 {
98 return bit_cast<float>(static_cast<traits::bitwise_type>(data) << traits::mant);
99 }
100}
101
102} // namespace ck_tile
#define CK_TILE_HOST_DEVICE
Definition config.hpp:42
Definition tile/core/algorithm/cluster_descriptor.hpp:13
CK_TILE_HOST_DEVICE constexpr Y bit_cast(const X &x)
Definition bit_cast.hpp:11
typename e8m0_t::raw_type e8m0_raw_t
Definition tile/core/numeric/e8m0.hpp:50
e8m0_bexp_t e8m0_t
Definition tile/core/numeric/e8m0.hpp:49
unsigned char uint8_t
Definition stdint.h:124
Unsigned representation of a conventional biased Float32 exponent.
Definition tile/core/numeric/e8m0.hpp:27
CK_TILE_HOST_DEVICE constexpr e8m0_bexp_t(float scale)
Definition tile/core/numeric/e8m0.hpp:35
CK_TILE_HOST_DEVICE constexpr e8m0_bexp_t(type init)
Definition tile/core/numeric/e8m0.hpp:34
constexpr bool operator!=(const e8m0_bexp_t &other) const
Definition tile/core/numeric/e8m0.hpp:46
constexpr bool operator==(const e8m0_bexp_t &other) const
Definition tile/core/numeric/e8m0.hpp:44
raw_type type
Definition tile/core/numeric/e8m0.hpp:29
CK_TILE_HOST_DEVICE constexpr raw_type get() const
Definition tile/core/numeric/e8m0.hpp:41
CK_TILE_HOST_DEVICE constexpr raw_type & get()
Definition tile/core/numeric/e8m0.hpp:40
CK_TILE_HOST_DEVICE constexpr e8m0_bexp_t()
Definition tile/core/numeric/e8m0.hpp:33
raw_type data
Definition tile/core/numeric/e8m0.hpp:31
uint8_t raw_type
Definition tile/core/numeric/e8m0.hpp:28
static CK_TILE_HOST_DEVICE constexpr e8m0_t infinity()
Definition tile/core/numeric/e8m0.hpp:82
static CK_TILE_HOST_DEVICE constexpr e8m0_t round_error()
Definition tile/core/numeric/e8m0.hpp:80
static constexpr e8m0_raw_t binary_min
Definition tile/core/numeric/e8m0.hpp:70
static constexpr e8m0_raw_t binary_max
Definition tile/core/numeric/e8m0.hpp:71
static CK_TILE_HOST_DEVICE constexpr e8m0_t signaling_NaN()
Definition tile/core/numeric/e8m0.hpp:76
static CK_TILE_HOST_DEVICE constexpr e8m0_t quiet_NaN()
Definition tile/core/numeric/e8m0.hpp:75
static CK_TILE_HOST_DEVICE constexpr bool has_inf()
Definition tile/core/numeric/e8m0.hpp:77
static CK_TILE_HOST_DEVICE constexpr e8m0_t zero()
Definition tile/core/numeric/e8m0.hpp:81
static CK_TILE_HOST_DEVICE constexpr e8m0_t max()
Definition tile/core/numeric/e8m0.hpp:74
static CK_TILE_HOST_DEVICE constexpr e8m0_t min()
Definition tile/core/numeric/e8m0.hpp:73
static constexpr e8m0_raw_t binary_nan
Definition tile/core/numeric/e8m0.hpp:72
static CK_TILE_HOST_DEVICE constexpr e8m0_t epsilon()
Definition tile/core/numeric/e8m0.hpp:79
static constexpr int mant
Definition tile/core/numeric/e8m0.hpp:58
e8m0_raw_t bitwise_type
Definition tile/core/numeric/e8m0.hpp:55
static constexpr int bias
Definition tile/core/numeric/e8m0.hpp:59
static constexpr int exp
Definition tile/core/numeric/e8m0.hpp:57
static constexpr int PackedSize
Definition tile/core/numeric/e8m0.hpp:60
Definition tile/core/numeric/numeric.hpp:81
Definition mxfp_convert.hpp:11
Definition tile/core/numeric/numeric.hpp:18
static CK_TILE_HOST_DEVICE constexpr T signaling_NaN()
Definition tile/core/numeric/numeric.hpp:47