C · Scalar Types

Scalar Types

#include <numkong/scalar.h>#include <numkong/cast.h>#include <numkong/types.h> 8.0.0-rc.1 · b1f866ab

The scalar wrappers in include/numkong/types.hpp are storage-first types. They encode raw layout, default output types, and the kernel function pointer signatures for each family.

TypeLayoutBytesRangeInfNaN
nk_f16_t1+5+102±65504yesyes
nk_bf16_t1+8+72±3.4×10³⁸yesyes
nk_e4m3_t1+4+31±448noyes
nk_e5m2_t1+5+21±57344yesyes
nk_e2m3_t1+2+31±7.5nono
nk_e3m2_t1+3+21±28nono
nk_e2m1x2_t2 × (1+2+1)1±6 per nibblenono
nk_u1x8_t8 packed bits10 or 1 per bitn/an/a
nk_u4x2_t2 × 4-bit10…15 per nibblen/an/a
nk_i4x2_t2 × 4-bit signed1−8…7 per nibblen/an/a

The layout column shows sign, exponent, and mantissa bit counts for floating-point types. For nk_f16_t, 1+5+10 means one sign bit, five exponent bits, and ten mantissa bits, totaling 16 bits stored in 2 bytes. For nk_bf16_t, the wider exponent field (8 bits) gives the same dynamic range as IEEE 754 single precision but with reduced mantissa precision. The Float8 types nk_e4m3_t and nk_e5m2_t follow the OFP8 specification. The narrower nk_e2m3_t and nk_e3m2_t types are MX-compatible micro-floats, and nk_e2m1x2_t packs two FP4 values of the MXFP4 and NVFP4 formats. Sub-byte types nk_e2m1x2_t, nk_u1x8_t, nk_u4x2_t, and nk_i4x2_t pack multiple logical values into a single byte. Element 0 sits in the high nibble or the most significant bit, and every dimension count must be a multiple of the values per byte.

Default promotions are encoded on the type. For example, f32_t::dot_result_t is wider than f32_t. i8_t::dot_result_t is i32_t. u1x8_t::dot_result_t is u32_t.

The higher-level templates use result_type_ = typename in_type_::dot_result_t and similar defaults. The fast typed overloads are constrained so that overriding the result type away from the native policy can disable the specialized path and fall back to the more generic one.

When __cpp_lib_format >= 202110L for the C++23 <format> header support, all NumKong scalar types provide std::formatter specializations with similar format specs to the traditional float. For the Float16 type, the output for nk::f16_t::from_f32(3.14f) will look like:

Format specOutput exampleDescription
{}3.140625Clean float value
{:#}3.140625 [0x4248]Annotated with hex bits
{:.2f}3.14Precision forwarded to float formatter
{:x}4248Raw hex bits
{:#x}0x4248Hex with prefix
{:X}4248Uppercase hex
{:b}0100001001001000Binary bits
{:#b}0b0100001001001000Binary with prefix

API

Types

nk_f32_unary_punned_tScalar kernels of one shape, cast back from nk_kernel_punned_t by their dispatch points.
scalar.h:32 ↗
typedef nk_f32_t(*) nk_f32_unary_punned_t(nk_f32_t);
nk_f16_to_f32_punned_tScalar conversion kernels of one shape, cast back from nk_kernel_punned_t by their dispatch points; the FP8 and FP6 codes share the byte shape.
cast.h:49 ↗
typedef void(*) nk_f16_to_f32_punned_t(nk_f16_t const *, nk_f32_t *);
nk_u1x8_tPacked 8-bit bit-vector (8 booleans in one byte), MSB = dimension 0.
types.h:1098 ↗
typedef unsigned char nk_u1x8_t;

Used for Hamming distance and Jaccard similarity via popcount. Dimension count must be a multiple of 8, the values per byte.

nk_i4x2_tPacked 4-bit signed integer pair (2 × i4 in one byte), [high nibble : low nibble].
types.h:1103 ↗
typedef unsigned char nk_i4x2_t;

Range per element: [−8, +7]. Elements sign-extended to i8 for arithmetic. Dimension count must be a multiple of 2, the values per byte.

nk_u4x2_tPacked 4-bit unsigned integer pair (2 × u4 in one byte), [high nibble : low nibble].
types.h:1108 ↗
typedef unsigned char nk_u4x2_t;

Range per element: [0, 15]. Elements zero-extended to u8 for arithmetic. Dimension count must be a multiple of 2, the values per byte.

nk_e4m3_t8-bit E4M3 float (OCP FP8): sign(1) + exponent(4) + mantissa(3), bias=7.
types.h:1113 ↗
typedef unsigned char nk_e4m3_t;

Range: ±448, no infinities (all-ones exponent → NaN at 0x7F/0xFF). 114 of 254 finite values, or 44.9%, fall in [−1, +1].

nk_e5m2_t8-bit E5M2 float (OCP FP8): sign(1) + exponent(5) + mantissa(2), bias=15.
types.h:1117 ↗
typedef unsigned char nk_e5m2_t;

Range: ±57 344, supports infinities at 0x7C/0xFC. 122 of 248 finite values (49.2%) fall in [−1, +1].

nk_e2m3_t6-bit E2M3 micro-float (OCP MX v1.0): sign(1) + exponent(2) + mantissa(3), bias=1.
types.h:1124 ↗
typedef unsigned char nk_e2m3_t;

Stored as 0b00SEEMMM with 2 bits of padding. Range: ±7.5, no infinities or NaN. 64 total codes: 48 normal, 14 subnormal (exp=0, mant ≠ 0), 2 zeros (±0). 18 of 64 values (28.1%) fall in [−1, +1]. Subnormal values span [±0.125, ±0.875]. Losslessly promotable to E4M3 by rebiasing exponent +6 (normals) or normalizing (subnormals).

nk_e3m2_t6-bit E3M2 micro-float (OCP MX v1.0): sign(1) + exponent(3) + mantissa(2), bias=3.
types.h:1131 ↗
typedef unsigned char nk_e3m2_t;

Stored as 0b00SEEEMM with 2 bits of padding. Range: ±28, no infinities or NaN. 64 total codes: 56 normal, 6 subnormal (exp=0, mant ≠ 0), 2 zeros (±0). 26 of 64 values (40.6%) fall in [−1, +1]. Subnormal values span [±0.0625, ±0.1875]. Losslessly promotable to E5M2 by rebiasing exponent +12 (normals) or normalizing (subnormals).

nk_e2m1x2_tPacked 4-bit E2M1 micro-float pair (2 × e2m1 in one byte), [high nibble : low nibble].
types.h:1138 ↗
typedef unsigned char nk_e2m1x2_t;

OCP MX v1.0 sub-format: sign(1) + exponent(2) + mantissa(1), bias=1. Range: ±6.0, no Inf or NaN. 16 total codes: 8 magnitudes {0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0} × 2 signs (two zeros). Used as the element type of MXFP4 (block=32, UE8M0 scales) and NVFP4 (block=16, UE4M3 scales). Dimension count must be a multiple of 2, the values per byte.

nk_ue8m0_tUnsigned 8-bit power-of-two scale (OCP MX v1.0): 8-bit biased exponent, no sign or mantissa.
types.h:1143 ↗
typedef unsigned char nk_ue8m0_t;

Encodes 2^(v - 127) for v ∈ [1, 254]; v = 0 is zero; v = 255 is the NaN-block sentinel. Used as the per-block scale byte for MXFP4, MXFP6, MXFP8, MXINT8.

nk_ue4m3_tUnsigned 8-bit E4M3 scale (NVFP4): sign-bit forced to 0, otherwise identical to E4M3.
types.h:1147 ↗
typedef unsigned char nk_ue4m3_t;

Range: [0, +448]. Used as the per-block scale byte for NVFP4 (block=16) alongside an f32 "tensor scale".

nk_i8_tSigned 8-bit integer.
types.h:1150 ↗
typedef signed char nk_i8_t;

Range: [−128, +127].

nk_u8_tUnsigned 8-bit integer.
types.h:1153 ↗
typedef unsigned char nk_u8_t;

Range: [0, 255].

nk_i16_tSigned 16-bit integer.
types.h:1156 ↗
typedef signed short nk_i16_t;

Range: [−32 768, +32 767].

nk_u16_tUnsigned 16-bit integer.
types.h:1159 ↗
typedef unsigned short nk_u16_t;

Range: [0, 65 535].

nk_i32_tSigned 32-bit integer.
types.h:1162 ↗
typedef signed int nk_i32_t;

Range: [−2³¹, +2³¹−1].

nk_u32_tUnsigned 32-bit integer.
types.h:1165 ↗
typedef unsigned int nk_u32_t;

Range: [0, 2³²−1].

nk_i64_tSigned 64-bit integer.
types.h:1180 ↗
typedef signed long long nk_i64_t;

Range: [−2⁶³, +2⁶³−1].

nk_u64_tUnsigned 64-bit integer.
types.h:1183 ↗
typedef unsigned long long nk_u64_t;

Range: [0, 2⁶⁴−1].

nk_f32_tSingle-precision (32-bit) IEEE 754 float.
types.h:1187 ↗
typedef float nk_f32_t;

sign(1) + exponent(8) + mantissa(23), bias=127.

nk_f64_tDouble-precision (64-bit) IEEE 754 float.
types.h:1190 ↗
typedef double nk_f64_t;

sign(1) + exponent(11) + mantissa(52), bias=1023.

nk_dtype_tEnumeration of supported scalar data types.
types.h:1292 ↗
enum nk_dtype_t

Includes complex type descriptors which in C code would use the real counterparts, but the independent flags contain metadata to be passed between programming language interfaces.

Block-scaled formats are composites, element_dtype | scale_dtype: two bits set, so they never collide with each other or with a singleton. The scale dtype fixes the block, 16 for UE4M3 in NVFP4 and 32 for UE8M0 in the MX family.

Values

nk_dtype_unknown_k0Unknown data type.
nk_u1_k1 << 1Single-bit values packed into 8-bit words.
nk_i8_k1 << 28-bit signed integer.
nk_i16_k1 << 316-bit signed integer.
nk_i32_k1 << 432-bit signed integer.
nk_i64_k1 << 564-bit signed integer.
nk_u8_k1 << 68-bit unsigned integer.
nk_u16_k1 << 716-bit unsigned integer.
nk_u32_k1 << 832-bit unsigned integer.
nk_u64_k1 << 964-bit unsigned integer.
nk_f64_k1 << 10Double precision floating point.
nk_f32_k1 << 11Single precision floating point.
nk_f16_k1 << 12Half precision floating point.
nk_bf16_k1 << 13Brain floating point.
nk_e4m3_k1 << 14FP8 E4M3 floating point.
nk_e5m2_k1 << 15FP8 E5M2 floating point.
nk_i4_k1 << 164-bit signed integers packed into 8-bit words.
nk_u4_k1 << 174-bit unsigned integers packed into 8-bit words.
nk_e2m3_k1 << 18FP6 E2M3 floating point.
nk_e3m2_k1 << 19FP6 E3M2 floating point.
nk_f64c_k1 << 20Complex double precision floating point.
nk_f32c_k1 << 21Complex single precision floating point.
nk_f16c_k1 << 22Complex half precision floating point.
nk_bf16c_k1 << 23Complex brain floating point.
nk_e2m1_k1 << 24FP4 E2M1 floating point (element of MXFP4 and NVFP4).
nk_ue8m0_k1 << 25UE8M0 unsigned pow-2 scale byte (MX family block scale).
nk_ue4m3_k1 << 26UE4M3 unsigned E4M3 scale byte (NVFP4 block scale).
nk_nvfp4_knk_e2m1_k | nk_ue4m3_kNVIDIA NVFP4 (block=16, f32 tensor scale).
nk_mxfp4_knk_e2m1_k | nk_ue8m0_kOCP MXFP4 (block=32).
nk_mxfp6e2m3_knk_e2m3_k | nk_ue8m0_kOCP MXFP6 (E2M3 variant, block=32).
nk_mxfp6e3m2_knk_e3m2_k | nk_ue8m0_kOCP MXFP6 (E3M2 variant, block=32).
nk_mxfp8e4m3_knk_e4m3_k | nk_ue8m0_kOCP MXFP8 (E4M3 variant, block=32).
nk_mxfp8e5m2_knk_e5m2_k | nk_ue8m0_kOCP MXFP8 (E5M2 variant, block=32).
nk_mxint8_knk_i8_k | nk_ue8m0_kOCP MXINT8 (block=32).

Spellings

char const * nk_dtype_name(nk_dtype_t dtype);
nk_block_scaled_format_tDescriptor for a block-scaled tensor layout (OCP MX family + NVIDIA NVFP4).
types.h:1546 ↗
struct nk_block_scaled_format_t

Elements are grouped in fixed-size contiguous blocks; each block has its own scale_dtype scale byte stored in a separate scales buffer. An optional tensor_scale_dtype scalar multiplier applies to the whole tensor (NVFP4's per-tensor FP32 factor; absent for the MX family).

Plain (non-block-scaled) buffers are described by scale_dtype = nk_dtype_unknown_k, tensor_scale_dtype = nk_dtype_unknown_k, and block_size = 0 — use the nk_plain() factory.

Fields

element_dtypenk_dtype_tPer-element dtype: e2m1/e4m3/e5m2/e2m3/e3m2/i8 (or any for plain).
scale_dtypenk_dtype_tPer-block scale: ue8m0 (MX) or ue4m3 (NVFP4); unknown for plain.
tensor_scale_dtypenk_dtype_tPer-tensor multiplier: f32 (NVFP4) or unknown (MX, plain).
block_sizenk_size_tElements per block: 16 (NVFP4) or 32 (MX); 0 for plain.
block_bytesnk_size_tBytes of codes per block, dividing a row stride into a scale row stride; 0 for plain.
nk_nvfp4_cref_tA read-only NVFP4 scalar: its E2M1 code, its block's UE4M3 scale, and the tensor's F32 scale.
types.h:1575 ↗
struct nk_nvfp4_cref_t

Fields

elementsnk_e2m1x2_t const *
scalesnk_ue4m3_t const *
tensor_scalenk_f32_t const *
nk_nvfp4_ref_tThe writable twin of nk_nvfp4_cref_t.
types.h:1582 ↗
struct nk_nvfp4_ref_t

Fields

elementsnk_e2m1x2_t *
scalesnk_ue4m3_t *
tensor_scalenk_f32_t *
nk_mxfp4_cref_tA read-only MXFP4 scalar: its E2M1 code, its block's UE8M0 scale.
types.h:1589 ↗
struct nk_mxfp4_cref_t

Fields

elementsnk_e2m1x2_t const *
scalesnk_ue8m0_t const *
nk_mxfp4_ref_tThe writable twin of nk_mxfp4_cref_t.
types.h:1595 ↗
struct nk_mxfp4_ref_t

Fields

elementsnk_e2m1x2_t *
scalesnk_ue8m0_t *
nk_mxfp6e2m3_cref_tA read-only MXFP6 E2M3 scalar: its E2M3 code, its block's UE8M0 scale.
types.h:1601 ↗
struct nk_mxfp6e2m3_cref_t

Fields

elementsnk_e2m3_t const *
scalesnk_ue8m0_t const *
nk_mxfp6e2m3_ref_tThe writable twin of nk_mxfp6e2m3_cref_t.
types.h:1607 ↗
struct nk_mxfp6e2m3_ref_t

Fields

elementsnk_e2m3_t *
scalesnk_ue8m0_t *
nk_mxfp6e3m2_cref_tA read-only MXFP6 E3M2 scalar: its E3M2 code, its block's UE8M0 scale.
types.h:1613 ↗
struct nk_mxfp6e3m2_cref_t

Fields

elementsnk_e3m2_t const *
scalesnk_ue8m0_t const *
nk_mxfp6e3m2_ref_tThe writable twin of nk_mxfp6e3m2_cref_t.
types.h:1619 ↗
struct nk_mxfp6e3m2_ref_t

Fields

elementsnk_e3m2_t *
scalesnk_ue8m0_t *
nk_mxfp8e4m3_cref_tA read-only MXFP8 E4M3 scalar: its E4M3 code, its block's UE8M0 scale.
types.h:1625 ↗
struct nk_mxfp8e4m3_cref_t

Fields

elementsnk_e4m3_t const *
scalesnk_ue8m0_t const *
nk_mxfp8e4m3_ref_tThe writable twin of nk_mxfp8e4m3_cref_t.
types.h:1631 ↗
struct nk_mxfp8e4m3_ref_t

Fields

elementsnk_e4m3_t *
scalesnk_ue8m0_t *
nk_mxfp8e5m2_cref_tA read-only MXFP8 E5M2 scalar: its E5M2 code, its block's UE8M0 scale.
types.h:1637 ↗
struct nk_mxfp8e5m2_cref_t

Fields

elementsnk_e5m2_t const *
scalesnk_ue8m0_t const *
nk_mxfp8e5m2_ref_tThe writable twin of nk_mxfp8e5m2_cref_t.
types.h:1643 ↗
struct nk_mxfp8e5m2_ref_t

Fields

elementsnk_e5m2_t *
scalesnk_ue8m0_t *
nk_mxint8_cref_tA read-only MXINT8 scalar: its I8 code, its block's UE8M0 scale.
types.h:1649 ↗
struct nk_mxint8_cref_t

Fields

elementsnk_i8_t const *
scalesnk_ue8m0_t const *
nk_mxint8_ref_tThe writable twin of nk_mxint8_cref_t.
types.h:1655 ↗
struct nk_mxint8_ref_t

Fields

elementsnk_i8_t *
scalesnk_ue8m0_t *
nk_dtype_family_tThe kind of number a data type holds, as nk_dtype_family reports it.
types.h:1661 ↗
enum nk_dtype_family_t

Values

nk_dtype_family_unknown_k0
nk_dtype_family_float_k
nk_dtype_family_complex_float_k
nk_dtype_family_int_k
nk_dtype_family_uint_k
nk_nvfp4_tAlias for the half-precision floating-point type on Arm.
types.h:2105 ↗
struct nk_nvfp4_t

Clang and GCC bring the float16_t symbol when you compile for AArch64. MSVC lacks it, and it's vld1_f16-like intrinsics are in reality macros, that cast to 16-bit integers internally, instead of using floats. Some of those are defined as aliases, so we use #define preprocessor directives instead of typedef to avoid errors.

Block-scaled composite POD types — one value is one whole block.

Each composite combines a packed element buffer with its per-block scale byte in a single POD struct. The struct IS the value: sizeof(nk_nvfp4_t) == 9 means one NVFP4 value, not one element. Storage in containers strides by sizeof(struct); logical element count per value is reported by nk_dimensions_per_value(composite_dtype) (16 for NVFP4, 32 for MX). Dimension count must be a multiple of that block size.

The NVFP4 per-tensor f32 tensor scale multiplier is not part of the block value — it lives on the enclosing tensor and is passed explicitly to encode/decode helpers.

nk_mxfp4_tOne OCP MXFP4 block: 32 E2M1 elements sharing a UE8M0 scale.
types.h:2116 ↗
struct nk_mxfp4_t
nk_mxfp6e2m3_tOne OCP MXFP6 E2M3 block: 32 E2M3 elements sharing a UE8M0 scale.
types.h:2126 ↗
struct nk_mxfp6e2m3_t
nk_mxfp6e3m2_tOne OCP MXFP6 E3M2 block: 32 E3M2 elements sharing a UE8M0 scale.
types.h:2132 ↗
struct nk_mxfp6e3m2_t
nk_mxfp8e4m3_tOne OCP MXFP8 E4M3 block: 32 E4M3 elements sharing a UE8M0 scale.
types.h:2138 ↗
struct nk_mxfp8e4m3_t
nk_mxfp8e5m2_tOne OCP MXFP8 E5M2 block: 32 E5M2 elements sharing a UE8M0 scale.
types.h:2144 ↗
struct nk_mxfp8e5m2_t
nk_mxint8_tOne OCP MXINT8 block: 32 I8 elements sharing a UE8M0 scale.
types.h:2150 ↗
struct nk_mxint8_t
nk_fui16_t16-bit union for f16/bf16/u16/i16 bit manipulation.
types.h:2188 ↗
union nk_fui16_t

Fields

unk_u16_t
ink_i16_t
fnk_f16_t
bfnk_bf16_t
nk_fui32_t32-bit union for f32/u32/i32 bit manipulation.
types.h:2196 ↗
union nk_fui32_t

Fields

nk_fui64_t64-bit union for f64/u64/i64 bit manipulation.
types.h:2203 ↗
union nk_fui64_t

Fields

nk_f16c_tHalf-precision (32-bit) complex number — {real: f16, imag: f16}.
types.h:2211 ↗
struct nk_f16c_t

Kernel outputs widened to f32c.

Fields

realnk_f16_t
imagnk_f16_t
nk_bf16c_tBFloat16 (32-bit) complex number — {real: bf16, imag: bf16}.
types.h:2217 ↗
struct nk_bf16c_t

Kernel outputs widened to f32c.

Fields

realnk_bf16_t
imagnk_bf16_t
nk_f32c_tSingle-precision (64-bit) complex number — {real: f32, imag: f32}.
types.h:2223 ↗
struct nk_f32c_t

Fields

nk_f64c_tDouble-precision (128-bit) complex number — {real: f64, imag: f64}.
types.h:2229 ↗
struct nk_f64c_t

Fields

nk_b32_vec_tSmall 4-byte memory slice viewable as different types.
types.h:2235 ↗
union nk_b32_vec_t

Fields

nk_b64_vec_tSmall 8-byte memory slice viewable as different types.
types.h:2248 ↗
union nk_b64_vec_t

Fields

u8snk_u8_t
u16snk_u16_t
u32snk_u32_t
u64nk_u64_t
i8snk_i8_t
i16snk_i16_t
i32snk_i32_t
i64nk_i64_t
f16snk_f16_t
bf16snk_bf16_t
f32snk_f32_t
nk_b128_vec_tSmall 16-byte memory slice viewable as different types.
types.h:2273 ↗
union nk_b128_vec_t

Fields

u8snk_u8_t
u16snk_u16_t
u32snk_u32_t
u64snk_u64_t
i8snk_i8_t
i16snk_i16_t
i32snk_i32_t
i64snk_i64_t
f16snk_f16_t
bf16snk_bf16_t
e4m3snk_e4m3_t
e5m2snk_e5m2_t
e2m3snk_e2m3_t
e3m2snk_e3m2_t
f32snk_f32_t
f64snk_f64_t
nk_b256_vec_tSmall 32-byte memory slice viewable as different types.
types.h:2327 ↗
union nk_b256_vec_t

Fields

u8snk_u8_t
u16snk_u16_t
u32snk_u32_t
u64snk_u64_t
i8snk_i8_t
i16snk_i16_t
i32snk_i32_t
i64snk_i64_t
f16snk_f16_t
bf16snk_bf16_t
e4m3snk_e4m3_t
e5m2snk_e5m2_t
e2m3snk_e2m3_t
e3m2snk_e3m2_t
f32snk_f32_t
f64snk_f64_t
nk_b512_vec_tSmall 64-byte memory slice viewable as different types.
types.h:2389 ↗
union nk_b512_vec_t

TODO: On GCC and Clang we use __transparent_union__ attribute to allow implicit conversions between the different vector types when passing them as function arguments. The most important side-effect of this is that the argument of such type is passed to functions using the calling convention of the first member of the union, which in our case is a register-based calling convention for SIMD types.

Fields

u8snk_u8_t
u16snk_u16_t
u32snk_u32_t
u64snk_u64_t
i8snk_i8_t
i16snk_i16_t
i32snk_i32_t
i64snk_i64_t
f16snk_f16_t
bf16snk_bf16_t
f32snk_f32_t
f64snk_f64_t
e4m3snk_e4m3_t
e5m2snk_e5m2_t
e2m3snk_e2m3_t
e3m2snk_e3m2_t
nk_scalar_buffer_tUnion for type-punned scalar values at language binding boundaries.
types.h:2540 ↗
union nk_scalar_buffer_t

Bridges different type systems (Python, JavaScript, etc.) where scalars arrive as f64 but need to be passed to kernels as typed pointers. Callers fill the appropriate union member based on the target dtype, then pass the union address as void const *.

Fields

Functions

nk_*_sqrt_best× 3Scalar square root, √x.
scalar.h:58 ↗
nk_f32_t nk_f32_sqrt_best(nk_f32_t x, nk_capability_t capabilities);
SymbolxBackends
nk_f32_sqrt_bestnk_f32_t7
nk_f64_sqrt_bestnk_f64_t7
nk_f16_sqrt_bestnk_f16_t4

Backends

  • nk_f32_sqrtserialneonhaswellrvvv128powervsxloongsonasx
  • nk_f64_sqrtserialneonhaswellrvvv128powervsxloongsonasx
  • nk_f16_sqrtserialneonhalfhaswellsapphire

Parameters

xinThe input value.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

Returns

The square root of x.

nk_*_rsqrt_best× 3Scalar reciprocal square root, 1 / √x.
scalar.h:72 ↗
nk_f32_t nk_f32_rsqrt_best(nk_f32_t x, nk_capability_t capabilities);
SymbolxBackends
nk_f32_rsqrt_bestnk_f32_t7
nk_f64_rsqrt_bestnk_f64_t7
nk_f16_rsqrt_bestnk_f16_t4

Backends

  • nk_f32_rsqrtserialneonhaswellrvvv128powervsxloongsonasx
  • nk_f64_rsqrtserialneonhaswellrvvv128powervsxloongsonasx
  • nk_f16_rsqrtserialneonhalfhaswellsapphire

Parameters

xinThe input value.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

Returns

The reciprocal square root of x.

See also

  • C++ std::rsqrt
  • Rust f32::rsqrt
nk_*_saturating_add_best× 10Saturating addition clamped to the representable range of the type.
scalar.h:108 ↗
nk_u8_t nk_u8_saturating_add_best(
    nk_u8_t a,
    nk_u8_t b,
    nk_capability_t capabilities);
Symbola, bBackends
nk_u8_saturating_add_bestnk_u8_t4
nk_i8_saturating_add_bestnk_i8_t4
nk_u16_saturating_add_bestnk_u16_t4
nk_i16_saturating_add_bestnk_i16_t4
nk_u32_saturating_add_bestnk_u32_t3
nk_i32_saturating_add_bestnk_i32_t3
nk_u64_saturating_add_bestnk_u64_t3
nk_i64_saturating_add_bestnk_i64_t3
nk_i4x2_saturating_add_bestnk_i4x2_t1
nk_u4x2_saturating_add_bestnk_u4x2_t1

Backends

  • nk_u8_saturating_addserialneonhaswellrvv
  • nk_i8_saturating_addserialneonhaswellrvv
  • nk_u16_saturating_addserialneonhaswellrvv
  • nk_i16_saturating_addserialneonhaswellrvv
  • nk_u32_saturating_addserialneonrvv
  • nk_i32_saturating_addserialneonrvv
  • nk_u64_saturating_addserialneonrvv
  • nk_i64_saturating_addserialneonrvv
  • nk_i4x2_saturating_addserial
  • nk_u4x2_saturating_addserial

Parameters

ainFirst operand.
binSecond operand.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

Returns

clamp(a + b, MIN, MAX).

nk_*_saturating_mul_best× 10Saturating multiplication clamped to the representable range of the type.
scalar.h:137 ↗
nk_u8_t nk_u8_saturating_mul_best(
    nk_u8_t a,
    nk_u8_t b,
    nk_capability_t capabilities);
Symbola, bBackends
nk_u8_saturating_mul_bestnk_u8_t2
nk_i8_saturating_mul_bestnk_i8_t2
nk_u16_saturating_mul_bestnk_u16_t2
nk_i16_saturating_mul_bestnk_i16_t2
nk_u32_saturating_mul_bestnk_u32_t2
nk_i32_saturating_mul_bestnk_i32_t2
nk_u64_saturating_mul_bestnk_u64_t4
nk_i64_saturating_mul_bestnk_i64_t4
nk_i4x2_saturating_mul_bestnk_i4x2_t1
nk_u4x2_saturating_mul_bestnk_u4x2_t1

Backends

  • nk_u8_saturating_mulserialrvv
  • nk_i8_saturating_mulserialrvv
  • nk_u16_saturating_mulserialrvv
  • nk_i16_saturating_mulserialrvv
  • nk_u32_saturating_mulserialrvv
  • nk_i32_saturating_mulserialrvv
  • nk_u64_saturating_mulserialneonhaswellrvv
  • nk_i64_saturating_mulserialneonhaswellrvv
  • nk_i4x2_saturating_mulserial
  • nk_u4x2_saturating_mulserial

Parameters

ainFirst operand.
binSecond operand.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

Returns

clamp(a * b, MIN, MAX).

nk_*_order_best× 6Branchless sign-magnitude ordering for non-native floating-point scalars.
scalar.h:173 ↗
int nk_f16_order_best(
    nk_f16_t a,
    nk_f16_t b,
    nk_capability_t capabilities);
Symbola, bBackends
nk_f16_order_bestnk_f16_t2
nk_bf16_order_bestnk_bf16_t1
nk_e4m3_order_bestnk_e4m3_t1
nk_e5m2_order_bestnk_e5m2_t1
nk_e2m3_order_bestnk_e2m3_t1
nk_e3m2_order_bestnk_e3m2_t1

Backends

  • nk_f16_orderserialsapphire
  • nk_bf16_orderserial
  • nk_e4m3_orderserial
  • nk_e5m2_orderserial
  • nk_e2m3_orderserial
  • nk_e3m2_orderserial

Uses mask = -sign; ordered = value ^ mask — the constant offset cancels in subtraction. Returns negative if a < b, 0 if equal, positive if a > b.

Parameters

ainFirst operand.
binSecond operand.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

Returns

Negative if a < b, zero if a == b, positive if a > b.

See also

std::strong_order, Rust total_cmp

Notes

NaN values are ordered at the extremes per IEEE 754 totalOrder (negative NaN < all finite < positive NaN). Callers requiring NaN-exclusion semantics must filter NaN before calling.

nk_f32_sin_serialApproximates the sine of an angle in radians within 3-ULP error on [-2π, 2π].
scalar.h:196 ↗
nk_f32_t nk_f32_sin_serial(nk_f32_t angle_radians);

Backends

  • nk_f32_sinserial

Based on xfastsinf_u3500 in the SLEEF library.

Parameters

angle_radiansinThe input angle in radians.

Returns

The approximate sine of the input angle in [-1, 1] range.

nk_f32_cos_serialApproximates the cosine of an angle in radians within 3-ULP error on [-2π, 2π].
scalar.h:206 ↗
nk_f32_t nk_f32_cos_serial(nk_f32_t angle_radians);

Backends

  • nk_f32_cosserial

Based on xfastcosf_u3500 in the SLEEF library.

Parameters

angle_radiansinThe input angle in radians.

Returns

The approximate cosine of the input angle in [-1, 1] range.

nk_*_atan_serial× 2Computes the arc-tangent of a value with 0-ULP error bound.
scalar.h:216 ↗
nk_f32_t nk_f32_atan_serial(nk_f32_t input);
SymbolinputBackends
nk_f32_atan_serialnk_f32_t1
nk_f64_atan_serialnk_f64_t1

Backends

  • nk_f32_atanserial
  • nk_f64_atanserial

Based on xatanf in the SLEEF library.

Based on xatan in the SLEEF library.

Parameters

inputinThe input value.

Returns

The arc-tangent of the input value in [-π/2, π/2] radians range.

nk_*_atan2_serial× 2Computes the arc-tangent of (y/x) with 0-ULP error bound.
scalar.h:227 ↗
nk_f32_t nk_f32_atan2_serial(nk_f32_t y_input, nk_f32_t x_input);
Symboly_input, x_inputBackends
nk_f32_atan2_serialnk_f32_t1
nk_f64_atan2_serialnk_f64_t1

Backends

  • nk_f32_atan2serial
  • nk_f64_atan2serial

Based on xatan2f in the SLEEF library.

Based on xatan2 in the SLEEF library.

Parameters

y_inputinThe input sine value.
x_inputinThe input cosine value.

Returns

The arc-tangent of y_input / x_input in [-π, π] radians range.

nk_f64_sin_serialComputes the sine of the given angle in radians with 0-ULP error bound in [-2π, 2π].
scalar.h:237 ↗
nk_f64_t nk_f64_sin_serial(nk_f64_t angle_radians);

Backends

  • nk_f64_sinserial

Based on xsin in the SLEEF library.

Parameters

angle_radiansinThe input angle in radians.

Returns

The approximate sine of the input angle.

nk_f64_cos_serialComputes the cosine of the given angle in radians with 0-ULP error bound in [-2π, 2π].
scalar.h:247 ↗
nk_f64_t nk_f64_cos_serial(nk_f64_t angle_radians);

Backends

  • nk_f64_cosserial

Based on xcos in the SLEEF library.

Parameters

angle_radiansinThe input angle in radians.

Returns

The approximate cosine of the input angle in [-1, 1] range.

nk_*_find_kernel× 2Finds the scalar kernel of kind for dtype, from the best of capabilities.
scalar.h:544 ↗
nk_status_t nk_scalar_find_kernel(
    nk_kernel_kind_t kind,
    nk_dtype_t dtype,
    nk_capability_t capabilities,
    nk_kernel_punned_t *kernel,
    nk_capability_t *capability);
Symbol
nk_scalar_find_kernel
nk_cast_find_kernel

Parameters

kindinThe verb whose kernel to find.
dtypeinThe input type the kernel reads.
capabilitiesinThe mask to pick the best capability from.
kerneloutThe kernel, or null when no capability in capabilities has it.
capabilityoutThe capability the kernel belongs to, or zero.

Statuses

nk_cast_bestElementwise type-casting for arrays of entries, plain or block-scaled.
cast.h:85 ↗
nk_status_t nk_cast_best(
    void const *from,
    nk_dtype_t from_dtype,
    void *to,
    nk_dtype_t to_dtype,
    nk_size_t count,
    nk_capability_t capabilities,
    nk_stream_t stream);

Backends

  • nk_castserialneonhaswellskylakeicelakesapphirervvpowervsxv128relaxedcudaampereadarocmmetal

A block-scaled dtype is one of the composites, like nk_mxfp8e4m3_k or nk_nvfp4_k, whose element dtype, scale dtype and block size nk_block_scaled_format_of_dtype derives:

SourceDestinationAction
plainplainelementwise conversion
plainblock-scaledencodes: per-block amax, derived scale, quantization
block-scaledplaindecodes: reads the scale, dequantizes to the plain dtype
block-scaledblock-scaledtranscodes: decode → encode

Codes and scales are contiguous runs. A destination NVFP4 tensor_scale holding a non-zero value is applied as is; holding zero, it receives the tensor scale that the kernel derives from the source data it encodes.

Parameters

frominThe count source elements, or an nk_<format>_cref_t if block-scaled.
from_dtypeinThe type of elements in the immutable source array.
tooutThe count target elements, or an nk_<format>_ref_t if block-scaled.
to_dtypeinThe type of elements in the mutable target array.
countinLogical elements, a multiple of both block sizes if either is block-scaled.
capabilitiesinOne device's capabilities, like nk_cpu_capabilities_enabled reports.
streaminNull on the CPU, or the GPU stream of that device to queue on.

Statuses

nk_f16_to_f32_bestScalar conversion from f16 to f32, covering every IEEE 754 edge case.
cast.h:127 ↗
void nk_f16_to_f32_best(
    nk_f16_t const *src,
    nk_f32_t *dest,
    nk_capability_t capabilities);

Backends

  • nk_f16_to_f32serialneonhaswellsapphirepowervsx
InputF16 HexF32 HexDescription
+00x00000x00000000Positive zero
-00x80000x80000000Negative zero
+inf0x7C000x7F800000Positive infinity
-inf0xFC000xFF800000Negative infinity
NaN0x7E000x7FC00000Quiet NaN, payload preserved
Min normal0x04000x388000002⁻¹⁴
Max normal0x7BFF0x477FE00065504
Min denorm0x00010x338000002⁻²⁴
Max denorm0x03FF0x387FC0002⁻¹⁴ - 2⁻²⁴

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

See also

nk_bf16_to_f32_bestScalar conversion from bf16 to f32.
cast.h:139 ↗
void nk_bf16_to_f32_best(
    nk_bf16_t const *src,
    nk_f32_t *dest,
    nk_capability_t capabilities);

Backends

  • nk_bf16_to_f32serial

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

See also

nk_*_to_f32_best× 2Scalar conversion from FP8 e4m3 to f32.
cast.h:169 ↗
void nk_e4m3_to_f32_best(
    nk_e4m3_t const *src,
    nk_f32_t *dest,
    nk_capability_t capabilities);
SymbolsrcBackends
nk_e4m3_to_f32_bestnk_e4m3_t1
nk_e5m2_to_f32_bestnk_e5m2_t1

Backends

  • nk_e4m3_to_f32serial
  • nk_e5m2_to_f32serial

E4M3 has 1 sign bit, 4 exponent bits biased by 7, and 3 mantissa bits. It spans [-448, +448] with no infinities and only two NaN encodings, 0x7F and 0xFF. Subnormals decode to the value (-1)ˢ × mantissa × 2⁻⁹, which is mantissa / 512.

InputE4M3 HexF32 HexDescription
+00x000x00000000Positive zero
-00x800x80000000Negative zero
+NaN0x7F0x7FC00000Quiet NaN, exp = 15, mant ≠ 0
-NaN0xFF0xFFC00000Quiet NaN, signed
+448 (max)0x7E0x43E00000Max normal = 448
-4480xFE0xC3E00000Min normal = -448
1.00x380x3F800000Normal, exp = 7, mant = 0
Min denorm0x010x3B0000001/512 = 2⁻⁹
Max denorm0x070x3BE000007/512 = 7 × 2⁻⁹

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

See also

nk_*_to_f32_best× 2Scalar conversion from FP6 e2m3 to f32.
cast.h:187 ↗
void nk_e2m3_to_f32_best(
    nk_e2m3_t const *src,
    nk_f32_t *dest,
    nk_capability_t capabilities);
SymbolsrcBackends
nk_e2m3_to_f32_bestnk_e2m3_t1
nk_e3m2_to_f32_bestnk_e3m2_t1

Backends

  • nk_e2m3_to_f32serial
  • nk_e3m2_to_f32serial

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.
nk_f32_to_f16_bestScalar conversion from f32 to f16, rounding to nearest, for all IEEE 754 inputs.
cast.h:224 ↗
void nk_f32_to_f16_best(
    nk_f32_t const *src,
    nk_f16_t *dest,
    nk_capability_t capabilities);

Backends

  • nk_f32_to_f16serialneonhaswellsapphirepowervsx
InputF32 HexF16 HexDescription
+00x000000000x0000Positive zero
-00x800000000x8000Negative zero
+inf0x7F8000000x7C00Positive infinity
-inf0xFF8000000xFC00Negative infinity
NaN0x7FC000000x7E00Quiet NaN, payload truncated
1.00x3F8000000x3C00Normal number
655040x477FE0000x7BFFMax f16 normal
65520+>0x477FE0000x7C00Overflow → infinity
2⁻¹⁴0x388000000x0400Min f16 normal
2⁻²⁴0x338000000x0001Min f16 denormal
<2⁻²⁵<0x330000000x0000Underflow → zero

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

See also

nk_f32_to_bf16_bestScalar conversion from f32 to bf16.
cast.h:236 ↗
void nk_f32_to_bf16_best(
    nk_f32_t const *src,
    nk_bf16_t *dest,
    nk_capability_t capabilities);

Backends

  • nk_f32_to_bf16serial

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

See also

nk_f32_to_*_best× 2Scalar conversion from f32 to FP8 e4m3, rounding to nearest even per IEEE 754 and the OCP FP8 specification.
cast.h:266 ↗
void nk_f32_to_e4m3_best(
    nk_f32_t const *src,
    nk_e4m3_t *dest,
    nk_capability_t capabilities);
SymboldestBackends
nk_f32_to_e4m3_bestnk_e4m3_t1
nk_f32_to_e5m2_bestnk_e5m2_t1

Backends

  • nk_f32_to_e4m3serial
  • nk_f32_to_e5m2serial

E4M3 has 1 sign bit, 4 exponent bits biased by 7, and 3 mantissa bits. It spans [-448, +448] with no infinities and only two NaN encodings. Values with |x| < 2⁻⁶ are encoded as subnormals.

InputF32 HexE4M3 HexDescription
+00x000000000x00Positive zero
-00x800000000x80Negative zero
+inf0x7F8000000x7ESaturates to max, +448
-inf0xFF8000000xFESaturates to min, -448
NaN0x7FC000000x7FQuiet NaN
1.00x3F8000000x38Normal, exp = 7, mant = 0
448+>0x43E000000x7EOverflow → max
2⁻⁶0x3E8000000x08Min normal
≤2⁻¹⁰≤0x3A8000000x00Underflow → zero, RNE boundary

E5M2 has 1 sign bit, 5 exponent bits biased by 15, and 2 mantissa bits. Its range is ±57344, and it keeps IEEE 754 infinities and NaNs. Values with |x| < 2⁻¹⁴ are encoded as subnormals.

InputF32 HexE5M2 HexDescription
+00x000000000x00Positive zero
-00x800000000x80Negative zero
+inf0x7F8000000x7CPositive infinity
-inf0xFF8000000xFCNegative infinity
NaN0x7FC000000x7DQuiet NaN
1.00x3F8000000x3CNormal, exp = 15, mant = 0
57344+>0x476000000x7COverflow → infinity
2⁻¹⁴0x388000000x04Min normal
≤2⁻¹⁷≤0x370000000x00Underflow → zero, RNE boundary

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.

See also

nk_f32_to_*_best× 2Scalar conversion from f32 to FP6 e2m3, rounding to nearest even per IEEE 754.
cast.h:310 ↗
void nk_f32_to_e2m3_best(
    nk_f32_t const *src,
    nk_e2m3_t *dest,
    nk_capability_t capabilities);
SymboldestBackends
nk_f32_to_e2m3_bestnk_e2m3_t1
nk_f32_to_e3m2_bestnk_e3m2_t1

Backends

  • nk_f32_to_e2m3serial
  • nk_f32_to_e3m2serial

E2M3FN has 1 sign bit, 2 exponent bits biased by 1, and 3 mantissa bits. It spans [-7.5, +7.5] with no infinities or NaNs, and saturates to the maximum on overflow. Values with |x| < 0.5 are encoded as subnormals.

E3M2FN has 1 sign bit, 3 exponent bits biased by 3, and 2 mantissa bits. It spans [-28, +28] with no infinities or NaNs, and saturates to the maximum on overflow. Values with |x| < 0.25 are encoded as subnormals.

Parameters

srcinThe scalar to convert.
destoutReceives the converted scalar.
capabilitiesinThe CPU's capabilities, like nk_cpu_capabilities_enabled reports; serial always stays.
nk_e2m1x2_to_f32x2_serialUnpacks a byte of two E2M1 nibbles into two f32 values: the high nibble lands in dest[0] and the low nibble in dest[1], as in nk_i4x2_t and nk_u4x2_t.
cast.h:356 ↗
void nk_e2m1x2_to_f32x2_serial(nk_e2m1x2_t const *src, nk_f32_t *dest);

Backends

  • nk_e2m1x2_to_f32x2serial
nk_f32x2_to_e2m1x2_serialPacks two f32 values into one byte of two E2M1 nibbles: src[0] becomes the high nibble and src[1] the low one, as in nk_i4x2_t and nk_u4x2_t.
cast.h:360 ↗
void nk_f32x2_to_e2m1x2_serial(nk_f32_t const *src, nk_e2m1x2_t *dest);

Backends

  • nk_f32x2_to_e2m1x2serial
nk_ue8m0_to_f32_serialConverts a UE8M0 power-of-two scale byte, as used by OCP MX, to f32.
cast.h:367 ↗
void nk_ue8m0_to_f32_serial(nk_ue8m0_t const *src, nk_f32_t *dest);

Backends

  • nk_ue8m0_to_f32serial

A zero byte decodes to 0, 0xFF to NaN as the block-NaN sentinel, and any other v to 2^(v - 127).

nk_f32_to_ue8m0_serialConverts an f32 magnitude to a UE8M0 power-of-two scale byte.
cast.h:377 ↗
void nk_f32_to_ue8m0_serial(nk_f32_t const *src, nk_ue8m0_t *dest);

Backends

  • nk_f32_to_ue8m0serial

Rounds to the nearest power of two, ties to even in log2 space, per the OCP MX, NVIDIA and AMD convention. Plain ceil or floor biases the block's dynamic range, as floor underestimates it, so the split sits at the geometric midpoint √2 × 2^e. NaN maps to 0xFF as the block-NaN sentinel, zero and subnormals map to 0x00, and overflow saturates to 0xFE.

nk_ue4m3_to_f32_serialConverts a UE4M3 byte, the NVFP4 scale that is an E4M3 with its sign bit forced to 0, to f32.
cast.h:380 ↗
void nk_ue4m3_to_f32_serial(nk_ue4m3_t const *src, nk_f32_t *dest);

Backends

  • nk_ue4m3_to_f32serial
nk_f32_to_ue4m3_serialConverts an f32 magnitude to a UE4M3 NVFP4 scale byte.
cast.h:389 ↗
void nk_f32_to_ue4m3_serial(nk_f32_t const *src, nk_ue4m3_t *dest);

Backends

  • nk_f32_to_ue4m3serial

Takes the absolute value first, as the sign bit is not representable, then rounds to nearest even like the underlying E4M3 encoder, matching the NVFP4 and OCP scale convention. NaN maps to the E4M3 NaN code 0x7F.

nk_nvfp4_to_f32x16_serialDecode one NVFP4 block (16 elements) to f32.
cast.h:392 ↗
void nk_nvfp4_to_f32x16_serial(
    nk_nvfp4_t const *src,
    nk_f32_t tensor_scale,
    nk_f32_t *dest);

Backends

  • nk_nvfp4_to_f32x16serial

tensor_scale is the per-tensor multiplier.

nk_f32x16_to_nvfp4_serialEncode 16 f32 values into one NVFP4 block, deriving a UE4M3 scale via per-block amax.
cast.h:395 ↗
void nk_f32x16_to_nvfp4_serial(
    nk_f32_t const *src,
    nk_f32_t tensor_scale,
    nk_nvfp4_t *dest);

Backends

  • nk_f32x16_to_nvfp4serial
nk_block_scaled_elements_sizeNumber of element storage bytes needed for count logical elements of format.
cast.h:434 ↗
nk_size_t nk_block_scaled_elements_size(
    nk_size_t count,
    nk_block_scaled_format_t format);
nk_block_scaled_scales_sizeNumber of scale storage bytes needed for count logical elements of format.
cast.h:437 ↗
nk_size_t nk_block_scaled_scales_size(
    nk_size_t count,
    nk_block_scaled_format_t format);
nk_nvfp4{nk_e2m1_k, nk_ue4m3_k, nk_f32_k, 16, 8} — NVIDIA NVFP4 (Blackwell-native).
types.h:1678 ↗
nk_block_scaled_format_t nk_nvfp4(void);
nk_mxfp4{nk_e2m1_k, nk_ue8m0_k, unknown, 32, 16} — OCP MXFP4.
types.h:1684 ↗
nk_block_scaled_format_t nk_mxfp4(void);
nk_mxfp6e2m3{nk_e2m3_k, nk_ue8m0_k, unknown, 32, 32} — OCP MXFP6 (E2M3 variant).
types.h:1690 ↗
nk_block_scaled_format_t nk_mxfp6e2m3(void);
nk_mxfp6e3m2{nk_e3m2_k, nk_ue8m0_k, unknown, 32, 32} — OCP MXFP6 (E3M2 variant).
types.h:1696 ↗
nk_block_scaled_format_t nk_mxfp6e3m2(void);
nk_mxfp8e4m3{nk_e4m3_k, nk_ue8m0_k, unknown, 32, 32} — OCP MXFP8 (E4M3 variant).
types.h:1702 ↗
nk_block_scaled_format_t nk_mxfp8e4m3(void);
nk_mxfp8e5m2{nk_e5m2_k, nk_ue8m0_k, unknown, 32, 32} — OCP MXFP8 (E5M2 variant).
types.h:1708 ↗
nk_block_scaled_format_t nk_mxfp8e5m2(void);
nk_mxint8{nk_i8_k, nk_ue8m0_k, unknown, 32, 32} — OCP MXINT8.
types.h:1714 ↗
nk_block_scaled_format_t nk_mxint8(void);
nk_plain{element_dtype, unknown, unknown, 0, 0} — plain scalar buffer of element_dtype.
types.h:1720 ↗
nk_block_scaled_format_t nk_plain(nk_dtype_t element_dtype);
nk_block_scaled_format_of_dtypeBuild a block-scaled format descriptor from a composite dtype enum value.
types.h:1727 ↗
nk_block_scaled_format_t nk_block_scaled_format_of_dtype(
    nk_dtype_t dtype);

Returns nk_plain(dtype) when dtype is not a composite.

nk_dtype_is_block_scaledTrue when dtype encodes a composite block-scaled format.
types.h:1741 ↗
int nk_dtype_is_block_scaled(nk_dtype_t dtype);
nk_dtype_elementExtracts the element dtype from a composite; returns dtype unchanged for plain inputs.
types.h:1755 ↗
nk_dtype_t nk_dtype_element(nk_dtype_t dtype);
nk_dtype_scaleExtracts the scale dtype from a composite; returns nk_dtype_unknown_k for plain inputs.
types.h:1769 ↗
nk_dtype_t nk_dtype_scale(nk_dtype_t dtype);
nk_dtype_block_sizeBlock size implied by a composite dtype; 0 for plain inputs.
types.h:1783 ↗
nk_size_t nk_dtype_block_size(nk_dtype_t dtype);
nk_dtype_familyClassifies the family of the dtype.
types.h:1797 ↗
nk_dtype_family_t nk_dtype_family(nk_dtype_t dtype);
nk_dtype_bitsReturns the number of bits in a single scalar of a given type.
types.h:1838 ↗
nk_size_t nk_dtype_bits(nk_dtype_t dtype);
nk_accumulation_error_boundReturns the rounding error each term may add to a sum kept in dtype, relative to the terms' magnitudes: |result − exact| ≤ (roundings + 1) · bound · Σ|terms|.
types.h:1887 ↗
nk_f64_t nk_accumulation_error_bound(nk_dtype_t dtype);

Floats get their unit roundoff with two bits of slack for matrix units that truncate; integer sums are exact. Kernel families derive their bounds from it, like nk_dot_error_bound.

nk_dtype_namedInverse of nk_dtype_name over an explicit-length string; nk_dtype_unknown_k for unrecognized names.
types.h:1940 ↗
nk_dtype_t nk_dtype_named(char const *name, nk_size_t length);
nk_dimensions_per_valueReturns how many logical dimensions are packed into one storage value.
types.h:1979 ↗
nk_size_t nk_dimensions_per_value(nk_dtype_t dtype);

For sub-byte types multiple dimensions share a single byte container. For byte-or-larger types this is always 1.

Macros

NUMKONG_F64_INFInfinities as an overflowing product, since C names them portably only in <math.h>.
types.h:1227 ↗
#define NUMKONG_F64_INF ((nk_f64_t)(1e300 * 1e300))
nk_min_of_twoThe smaller of two values of any comparable type; each argument is evaluated twice.
types.h:2479 ↗
#define nk_min_of_two(first, second) ((first) <(second) ? (first) : (second))
nk_max_of_twoThe larger of two values of any comparable type; each argument is evaluated twice.
types.h:2482 ↗
#define nk_max_of_two(first, second) ((first) <(second) ? (second) : (first))