include/vecmat/fp16.h file

IEEE binary16 storage and vm_gemm_fp16f32.

Not a vm_float_t width.

Compiled into the library only when VECMAT_ENABLE_FP16=ON. Not part of vecmat.h. Symbols are not in abi.h.

Classes

struct vm_vec4_fp16
struct vm_mat4_fp16

Typedefs

using vm_fp16_t = uint16_t
IEEE binary16 bits.
using vm_vec4_fp16 = struct vm_vec4_fp16
using vm_mat4_fp16 = struct vm_mat4_fp16
using vm_fp16_gemm_fn = void(*)(float*c, int ldc, const vm_fp16_t*a, int lda, const vm_fp16_t*b, int ldb, int m, int n, int k, float alpha, float beta)
Row-major C = alpha * A * B + beta * C with fp16 inputs and an f32 accumulator.

Functions

auto vm_fp16_from_f32(float x) -> vm_fp16_t
Round a binary32 value to binary16, ties to even.
auto vm_f32_from_fp16(vm_fp16_t h) -> float
Expand binary16 bits to binary32.
void vm_fp16_init(void)
Install the scalar GEMM, then run vm_fp16_modules_register().
void vm_fp16_set_gemm(vm_fp16_gemm_fn fn, const char* note)
Replace the GEMM slot.
auto vm_fp16_note(void) -> const char*
fp16=scalar until a module overrides the slot.
void vm_gemm_fp16f32(float* c, int ldc, const vm_fp16_t* a, int lda, const vm_fp16_t* b, int ldb, int m, int n, int k, float alpha, float beta)
See vm_fp16_gemm_fn.

Typedef documentation

typedef uint16_t vm_fp16_t

IEEE binary16 bits.

Not a C _Float16.

typedef void(*vm_fp16_gemm_fn)(float*c, int ldc, const vm_fp16_t*a, int lda, const vm_fp16_t*b, int ldb, int m, int n, int k, float alpha, float beta)

Row-major C = alpha * A * B + beta * C with fp16 inputs and an f32 accumulator.

No transpose and no layout flag. This is not vm_gemm (that default is column-major and takes transpose flags). lda / ldb are in vm_fp16_t elements; ldc is in float elements.

Function documentation

vm_fp16_t vm_fp16_from_f32(float x)

Round a binary32 value to binary16, ties to even.

Inf maps to inf. Every NaN maps to the canonical quiet NaN 0x7e00. Subnormals are kept.

float vm_f32_from_fp16(vm_fp16_t h)

Expand binary16 bits to binary32.

Subnormals are kept.

void vm_fp16_init(void)

Install the scalar GEMM, then run vm_fp16_modules_register().

Call before the first vm_gemm_fp16f32 if a module must override the slot. A second call does not replace an already installed slot.

void vm_fp16_set_gemm(vm_fp16_gemm_fn fn, const char* note)

Replace the GEMM slot.

fn == NULL is ignored.

note is printed by the caller via vm_fp16_note(). It is not vm_cpu_note().

void vm_gemm_fp16f32(float* c, int ldc, const vm_fp16_t* a, int lda, const vm_fp16_t* b, int ldb, int m, int n, int k, float alpha, float beta)

See vm_fp16_gemm_fn.

Dispatches the installed slot.