From 78f5588d761f0df66eb11c2b79bee7c22fb0d132 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Tue, 16 Jun 2026 16:34:12 +0200 Subject: api: dedup scalar bf16-to-f32 into dtype.h --- src/dtype.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/dtype.h (limited to 'src/dtype.h') diff --git a/src/dtype.h b/src/dtype.h new file mode 100644 index 0000000..5c1ce8f --- /dev/null +++ b/src/dtype.h @@ -0,0 +1,19 @@ +#ifndef EMBED_DTYPE_H +#define EMBED_DTYPE_H + +#include +#include + +/* BF16 is the upper 16 bits of an IEEE-754 binary32, so widening one value is a + * left shift reinterpreted as a float. Shared by every host-side caller (the + * CPU loader, the safetensors reader); the CUDA backend keeps its own + * __nv_bfloat16 device kernels, and kernels.c keeps the SIMD buffer variant + * embed_bf16_to_f32_buf for hot, contiguous conversions. */ +static inline float embed_bf16_to_f32(uint16_t bf16) { + uint32_t bits = (uint32_t)bf16 << 16; + float f; + memcpy(&f, &bits, sizeof(f)); + return f; +} + +#endif /* EMBED_DTYPE_H */ -- cgit v1.3.1