Skip to main content

ClikaRT::dtype

namespace

The dtype-system helpers: classification predicates, size arithmetic, and the readable name. DataType itself stays at ClikaRT:: (the one name every signature spells); everything ABOUT a dtype lives here.

Namespaces

NameDescription
ClikaRT::dtype::packPack several sub-byte values into one storage byte.
ClikaRT::dtype::unpackExtract the i-th sub-byte value from a packed storage byte.

Classes

NameDescription
bfloat16_tTruncated fp32 (brain float): 1 sign + 8 exponent + 7 mantissa, bias 127; the top 16 bits of an fp32. Range ±3.39e38 (= fp32), eps 2^-7. 16-bit storage. Conversion from fp32 is round-to-nearest-even; from_truncated drops the low 16 bits without rounding.
dtype_ofPrimary template undefined: an unmapped type is a hard compile error.
dtype_of\<bfloat16_t\>
dtype_of\<bool\>
dtype_of\<double\>
dtype_of\<float\>
dtype_of\<float16_t\>
dtype_of\<float4_e2m1_t\>
dtype_of\<float6_e2m3_t\>
dtype_of\<float6_e3m2_t\>
dtype_of\<float8_e4m3fn_t\>
dtype_of\<float8_e4m3fnuz_t\>
dtype_of\<float8_e5m2_t\>
dtype_of\<float8_e5m2fnuz_t\>
dtype_of\<float8_e8m0_t\>
dtype_of\<int2_t\>
dtype_of\<int4_t\>
dtype_of\<std::int16_t\>
dtype_of\<std::int32_t\>
dtype_of\<std::int64_t\>
dtype_of\<std::int8_t\>
dtype_of\<std::uint16_t\>
dtype_of\<std::uint32_t\>
dtype_of\<std::uint64_t\>
dtype_of\<std::uint8_t\>
dtype_of\<uint1_t\>
dtype_of\<uint2_t\>
dtype_of\<uint4_t\>
dtype_traitsPrimary template undefined; specializations carry scalar (byte-aligned only) and/or host (all storage dtypes).
float16_tIEEE 754 binary16: 1 sign + 5 exponent + 10 mantissa, bias 15. Range ±65504, smallest normal 2^-14, eps 2^-10. 16-bit storage.
float4_e2m1_tFP4 E2M1: 1 sign + 2 exponent + 1 mantissa, bias 1. The 16 values are {0, ±0.5, ±1, ±1.5, ±2, ±3, ±4, ±6}; eps 0.5. Low 4 bits of a byte.
float6_e2m3_tFP6 E2M3: 1 sign + 2 exponent + 3 mantissa, bias 1. Range ±7.5, smallest normal 1.0, eps 0.125. Low 6 bits of a byte.
float6_e3m2_tFP6 E3M2: 1 sign + 3 exponent + 2 mantissa, bias 3. Range ±28, smallest normal 2^-2, eps 2^-2. Low 6 bits of a byte.
float8_e4m3fn_tFP8 E4M3 (FN: finite, NaN-only): 1 sign + 4 exponent + 3 mantissa, bias 7. Range ±448, smallest normal 2^-6, eps 2^-3. NaN at exp+mantissa all-ones; no infinity. Conversion from fp32 saturates on overflow. 8-bit storage.
float8_e4m3fnuz_tFP8 E4M3 FNUZ: 1 sign + 4 exponent + 3 mantissa, bias 8 (rebased). FNUZ = finite, NaN, unsigned-zero: one NaN at 0x80, no infinity, no -0. Range ±240, smallest normal 2^-7, eps 2^-3. 8-bit storage.
float8_e5m2_tFP8 E5M2: 1 sign + 5 exponent + 2 mantissa, bias 15. Range ±57344, smallest normal 2^-14, eps 2^-2. IEEE-style: includes ±Inf and NaN. 8-bit storage.
float8_e5m2fnuz_tFP8 E5M2 FNUZ: 1 sign + 5 exponent + 2 mantissa, bias 16 (rebased). FNUZ = finite, NaN, unsigned-zero: one NaN at 0x80, no infinity, no -0. Range ±57344, smallest normal 2^-15, eps 2^-2. 8-bit storage.
float8_e8m0_tFP8 E8M0 block-scale: 8 exponent bits, 0 mantissa, no sign. Bias 127; pure powers of two from 2^-127 to 2^127, one NaN at 0xFF. Used as the per-block scale in MX block formats. Conversion from fp32 takes the biased exponent of `
FloatInfoNumeric properties of a floating-point DataType.
int2_tSigned 2-bit integer, range [-2, 1]. Low 2 bits of a byte.
int4_tSigned 4-bit integer, range [-8, 7]. Low nibble of a byte.
IntInfoNumeric properties of an integer DataType. bits counts VALUE bits, so a sub-byte type reports its packed width (Int4 -> 4).
nf4_tnf4_t: a 4-bit index into a 16-entry table of standard-normal quantiles scaled to [-1, +1]. No exponent/mantissa structure; purely a lookup quantizer. Callers normalize their data to roughly [-1, +1] (e.g. per-block max-abs scaling) before quantizing; out-of-range inputs saturate to ±1. The table is monotonic, so the stored index orders the same as the dequantized value. Low 4 bits of a byte.
tfloat32_tTensorFloat-32: 1 sign + 8 exponent + 10 effective mantissa, bias 127, stored in a 32-bit container with the low 13 mantissa bits zeroed. Range = fp32, precision ≈ fp16. Conversion from fp32 round-to-nearest-even-narrows the low 13 bits; conversion to fp32 is identity. from_truncated drops the bits without rounding.
uint1_tUnsigned 1-bit integer, range {0, 1}. Low bit of a byte.
uint2_tUnsigned 2-bit integer, range [0, 3]. Low 2 bits of a byte.
uint4_tUnsigned 4-bit integer, range [0, 15]. Low nibble of a byte.

Type aliases

using scalar_type_t

using scalar_type_t = typename dtype_traits<DT>::scalar

Storage C++ type of a dtype (byte-aligned only; a sub-byte dtype is a hard error).

Declared in ClikaRT/compute/dtype_traits.h, line 118

using host_type_t

using host_type_t = typename dtype_traits<DT>::host

Widened compute host type of a dtype (float for narrow floats, native integer otherwise, double for Float64).

Declared in ClikaRT/compute/dtype_traits.h, line 122

Variables

dtype_of_v

DataType dtype_of_v = dtype_of<T>::value

DataType a host C++ type stores as (dtype_of_v<float> == DataType::Float32).

Declared in ClikaRT/compute/dtype_traits.h, line 66

has_scalar_type_v

bool has_scalar_type_v = detail::has_scalar_type<DT>::value

True iff DT has a byte-aligned storage scalar (false for the sub-byte dtypes).

Declared in ClikaRT/compute/dtype_traits.h, line 131

Functions

data_type_name()

const char* data_type_name(DataType dt) noexcept

A short, human-readable name for dt (e.g. "Float32"). Never null; an unrecognized value yields "Undefined".

Declared in ClikaRT/compute/data_type.h, line 73

is_floating_point()

bool is_floating_point(DataType dt) noexcept

True for the IEEE-style and narrow floating formats (Float16/BFloat16/ Float32/Float64 and the FP8/FP6/FP4 families).

Declared in ClikaRT/compute/data_type.h, line 108

bits_per_element()

constexpr int bits_per_element(DataType dt) noexcept

Bits per stored element. Sub-byte types return their packed-bit width (Int4 -> 4, Float6_E2M3 -> 6). Undefined -> 0.

Declared in ClikaRT/compute/data_type.h, line 130

bytes_per_element()

constexpr int bytes_per_element(DataType dt) noexcept

Bytes per element when storage is byte-aligned (>= 1 byte). Returns 0 for the sub-byte types (Int2/4, UInt1/2/4, FP4, FP6); use packed_bytes for those.

Declared in ClikaRT/compute/data_type.h, line 154

packed_bytes()

constexpr std::int64_t packed_bytes(std::int64_t num_elements, DataType dt) noexcept

Storage bytes for num_elements of dt in dense packed form (bit-packs the sub-byte types). 0 for an empty count or an unsized dtype.

Declared in ClikaRT/compute/data_type.h, line 173

is_sub_byte()

constexpr bool is_sub_byte(DataType dt) noexcept

True for the bit-packed sub-byte types: Int2/4, UInt1/2/4, FP4, and FP6.

Declared in ClikaRT/compute/data_type.h, line 180

is_signed_integer()

constexpr bool is_signed_integer(DataType dt) noexcept

Signed integers, sub-byte included: Int2/4, Int8/16/32/64.

Declared in ClikaRT/compute/data_type.h, line 193

is_unsigned_integer()

constexpr bool is_unsigned_integer(DataType dt) noexcept

Unsigned integers, sub-byte included: UInt1/2/4, UInt8/16/32/64.

Declared in ClikaRT/compute/data_type.h, line 204

is_integer()

constexpr bool is_integer(DataType dt) noexcept

Any integer (signed or unsigned), sub-byte included.

Declared in ClikaRT/compute/data_type.h, line 215

is_byte_aligned_integer()

constexpr bool is_byte_aligned_integer(DataType dt) noexcept

Byte-aligned integers only: Int8/16/32/64 + UInt8/16/32/64 (excludes sub-byte). Use when a kernel addresses elements at byte granularity.

Declared in ClikaRT/compute/data_type.h, line 221

is_standard_float()

constexpr bool is_standard_float(DataType dt) noexcept

The standard IEEE / brain-float family: Float16, Float32, Float64, BFloat16 (excludes the FP8 / FP6 / FP4 narrow formats).

Declared in ClikaRT/compute/data_type.h, line 234

is_reduced_float()

constexpr bool is_reduced_float(DataType dt) noexcept

Reduced-precision floats with no native arithmetic: Float16 and BFloat16 (arithmetic runs in a widened float accumulator).

Declared in ClikaRT/compute/data_type.h, line 245

is_fp8()

constexpr bool is_fp8(DataType dt) noexcept

The FP8 family: Float8_E4M3 / E5M2 / E4M3FNUZ / E5M2FNUZ / E8M0.

Declared in ClikaRT/compute/data_type.h, line 250

is_fp6()

constexpr bool is_fp6(DataType dt) noexcept

The FP6 family: Float6_E2M3 and Float6_E3M2 (bit-packed sub-byte floats).

Declared in ClikaRT/compute/data_type.h, line 261

is_sub_byte_float()

constexpr bool is_sub_byte_float(DataType dt) noexcept

The bit-packed sub-byte floats: Float4_E2M1, Float6_E2M3, Float6_E3M2.

Declared in ClikaRT/compute/data_type.h, line 266

is_byte_aligned()

constexpr bool is_byte_aligned(DataType dt) noexcept

Storage is byte-aligned (>= 1 byte per element) for every type except the bit-packed sub-byte ones.

Declared in ClikaRT/compute/data_type.h, line 272

CLIKART_DTYPE_TRAIT(Bool, bool, bool)

CLIKART_DTYPE_TRAIT(
    Bool,
    bool,
    bool
)

Declared in ClikaRT/compute/dtype_traits.h, line 80

CLIKART_DTYPE_TRAIT(Int8, int8_t, int8_t)

CLIKART_DTYPE_TRAIT(
    Int8,
    std::int8_t,
    std::int8_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 81

CLIKART_DTYPE_TRAIT(Int16, int16_t, int16_t)

CLIKART_DTYPE_TRAIT(
    Int16,
    std::int16_t,
    std::int16_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 82

CLIKART_DTYPE_TRAIT(Int32, int32_t, int32_t)

CLIKART_DTYPE_TRAIT(
    Int32,
    std::int32_t,
    std::int32_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 83

CLIKART_DTYPE_TRAIT(Int64, int64_t, int64_t)

CLIKART_DTYPE_TRAIT(
    Int64,
    std::int64_t,
    std::int64_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 84

CLIKART_DTYPE_TRAIT(UInt8, uint8_t, uint8_t)

CLIKART_DTYPE_TRAIT(
    UInt8,
    std::uint8_t,
    std::uint8_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 85

CLIKART_DTYPE_TRAIT(UInt16, uint16_t, uint16_t)

CLIKART_DTYPE_TRAIT(
    UInt16,
    std::uint16_t,
    std::uint16_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 86

CLIKART_DTYPE_TRAIT(UInt32, uint32_t, uint32_t)

CLIKART_DTYPE_TRAIT(
    UInt32,
    std::uint32_t,
    std::uint32_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 87

CLIKART_DTYPE_TRAIT(UInt64, uint64_t, uint64_t)

CLIKART_DTYPE_TRAIT(
    UInt64,
    std::uint64_t,
    std::uint64_t
)

Declared in ClikaRT/compute/dtype_traits.h, line 88

CLIKART_DTYPE_TRAIT(Float16, float16_t, float)

CLIKART_DTYPE_TRAIT(
    Float16,
    float16_t,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 89

CLIKART_DTYPE_TRAIT(BFloat16, bfloat16_t, float)

CLIKART_DTYPE_TRAIT(
    BFloat16,
    bfloat16_t,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 90

CLIKART_DTYPE_TRAIT(Float32, float, float)

CLIKART_DTYPE_TRAIT(
    Float32,
    float,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 91

CLIKART_DTYPE_TRAIT(Float64, double, double)

CLIKART_DTYPE_TRAIT(
    Float64,
    double,
    double
)

Declared in ClikaRT/compute/dtype_traits.h, line 92

CLIKART_DTYPE_TRAIT(Float8_E4M3, float8_e4m3fn_t, float)

CLIKART_DTYPE_TRAIT(
    Float8_E4M3,
    float8_e4m3fn_t,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 93

CLIKART_DTYPE_TRAIT(Float8_E5M2, float8_e5m2_t, float)

CLIKART_DTYPE_TRAIT(
    Float8_E5M2,
    float8_e5m2_t,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 94

CLIKART_DTYPE_TRAIT(Float8_E4M3FNUZ, float8_e4m3fnuz_t, float)

CLIKART_DTYPE_TRAIT(
    Float8_E4M3FNUZ,
    float8_e4m3fnuz_t,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 95

CLIKART_DTYPE_TRAIT(Float8_E5M2FNUZ, float8_e5m2fnuz_t, float)

CLIKART_DTYPE_TRAIT(
    Float8_E5M2FNUZ,
    float8_e5m2fnuz_t,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 96

CLIKART_DTYPE_TRAIT(Float8_E8M0, float8_e8m0_t, float)

CLIKART_DTYPE_TRAIT(
    Float8_E8M0,
    float8_e8m0_t,
    float
)

Declared in ClikaRT/compute/dtype_traits.h, line 97

CLIKART_DTYPE_HOST_ONLY(UInt1, uint8_t)

CLIKART_DTYPE_HOST_ONLY(UInt1, std::uint8_t)

Declared in ClikaRT/compute/dtype_traits.h, line 106

CLIKART_DTYPE_HOST_ONLY(UInt2, uint8_t)

CLIKART_DTYPE_HOST_ONLY(UInt2, std::uint8_t)

Declared in ClikaRT/compute/dtype_traits.h, line 107

CLIKART_DTYPE_HOST_ONLY(Int2, int8_t)

CLIKART_DTYPE_HOST_ONLY(Int2, std::int8_t)

Declared in ClikaRT/compute/dtype_traits.h, line 108

CLIKART_DTYPE_HOST_ONLY(UInt4, uint8_t)

CLIKART_DTYPE_HOST_ONLY(UInt4, std::uint8_t)

Declared in ClikaRT/compute/dtype_traits.h, line 109

CLIKART_DTYPE_HOST_ONLY(Int4, int8_t)

CLIKART_DTYPE_HOST_ONLY(Int4, std::int8_t)

Declared in ClikaRT/compute/dtype_traits.h, line 110

CLIKART_DTYPE_HOST_ONLY(Float4_E2M1, float)

CLIKART_DTYPE_HOST_ONLY(Float4_E2M1, float)

Declared in ClikaRT/compute/dtype_traits.h, line 111

CLIKART_DTYPE_HOST_ONLY(Float6_E2M3, float)

CLIKART_DTYPE_HOST_ONLY(Float6_E2M3, float)

Declared in ClikaRT/compute/dtype_traits.h, line 112

CLIKART_DTYPE_HOST_ONLY(Float6_E3M2, float)

CLIKART_DTYPE_HOST_ONLY(Float6_E3M2, float)

Declared in ClikaRT/compute/dtype_traits.h, line 113

finfo()

FloatInfo finfo(DataType dt)

Declared in ClikaRT/compute/finfo.h, line 54

iinfo()

IntInfo iinfo(DataType dt)

Declared in ClikaRT/compute/finfo.h, line 60

promote_types()

DataType promote_types(DataType a, DataType b) noexcept

The dtype a and b promote to, per the standard type-promotion lattice, extended to the sub-byte and narrow-float formats. Total over the storage dtypes; returns DataType::Undefined for a sentinel input.

Declared in ClikaRT/compute/promotion.h, line 16

dominant_dtype()

template <``class... Rest``>
DataType dominant_dtype(
    DataType a,
    DataType b,
    Rest... rest
) noexcept

Folds a, b, and rest... pairwise to one dominant dtype.

The common dtype of N operands, a fold of promote_types (>= 2 args). Handy for a variadic / ternary op: dominant_dtype(cond, a, b).

Declared in ClikaRT/compute/promotion.h, line 22

ClikaRT/compute/data_type.h

#include <ClikaRT/compute/data_type.h>

Element data type of a tensor.

ClikaRT/compute/dtype_traits.h

#include <ClikaRT/compute/dtype_traits.h>

Compile-time mapping between a host C++ scalar type and the DataType enum, in both directions.

  • dtype_of_v<T> / dtype_of<T>::value: the DataType a host C++ type stores as (dtype_of_v<bfloat16_t> -> DataType::BFloat16). Covers the native scalars and every scalar_types.h struct that has a storage slot; an unmapped type is a hard compile error.
  • scalar_type_t<DataType>: the storage C++ type for a dtype (scalar_type_t<DataType::BFloat16> -> bfloat16_t). Byte-aligned only; instantiating it for a sub-byte dtype is a hard error (sub-byte storage goes through the packed-bit path). has_scalar_type_v<DataType> is the predicate.
  • host_type_t<DataType>: the widened compute "host" type a value decodes to for arithmetic: float for every narrow / sub-byte float, the native integer for the integer family, double for Float64. Defined for all storage dtypes.

tfloat32_t and nf4_t have no dtype_of; they are compute / quantization types, not tensor storage dtypes (so no DataType slot).

Macros

#define CLIKART_DTYPE_TRAIT

#define CLIKART_DTYPE_TRAIT(ENUM, SCALAR, HOST) template <> struct dtype_traits<DataType::ENUM> { \ using scalar = SCALAR; \ using host = HOST; \ }

Declared in ClikaRT/compute/dtype_traits.h, line 74

#define CLIKART_DTYPE_HOST_ONLY

#define CLIKART_DTYPE_HOST_ONLY(ENUM, HOST) template <> struct dtype_traits<DataType::ENUM> { using host = HOST; }

Declared in ClikaRT/compute/dtype_traits.h, line 103

ClikaRT/compute/finfo.h

#include <ClikaRT/compute/finfo.h>

Numeric limits of a DataType: finfo describes a floating-point format (bit layout, eps, smallest-normal, min/max, NaN/Inf), iinfo an integer format (bit width, signedness, min/max). Runtime queries keyed on a DataType; for a dtype of the wrong category (e.g. finfo of an integer) the call fails.

ClikaRT/compute/promotion.h

#include <ClikaRT/compute/promotion.h>

Type promotion over DataType: the dtype two (or more) operands combine to.