MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / float_to_bf16

Function float_to_bf16

csrc/cpu_ops.h:139–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137void quantize_cpu_fp16(float* code, fp16_t* A, float* absmax, unsigned char* out, long long blocksize, long long n);
138
139static inline bf16_t float_to_bf16(float x) {
140 uint32_t bits;
141 std::memcpy(&bits, &x, 4);
142 uint32_t r = bits + 0x7FFF + ((bits >> 16) & 1);
143 return bf16_t{static_cast<uint16_t>(r >> 16)};
144}
145
146static float bf16_to_float(uint16_t bf16) {
147 uint32_t bits = (uint32_t)bf16 << 16;

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected