Skip to content

Commit 7fd9101

Browse files
committed
Don't flush bf16 subnormals to zero
See ggml-org/llama.cpp#7843
1 parent b2f587c commit 7fd9101

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

llama.cpp/ggml-impl.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ static inline float ggml_compute_bf16_to_fp32(ggml_bf16_t h) {
8181

8282
/**
8383
* Converts float32 to brain16.
84-
*
85-
* This function is binary identical to AMD Zen4 VCVTNEPS2BF16.
86-
* Subnormals shall be flushed to zero, and NANs will be quiet.
87-
* This code should vectorize nicely if using modern compilers.
8884
*/
8985
static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
9086
ggml_bf16_t h;
@@ -97,10 +93,6 @@ static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
9793
h.bits = (u.i >> 16) | 64; /* force to quiet */
9894
return h;
9995
}
100-
if (!(u.i & 0x7f800000)) { /* subnormal */
101-
h.bits = (u.i & 0x80000000) >> 16; /* flush to zero */
102-
return h;
103-
}
10496
h.bits = (u.i + (0x7fff + ((u.i >> 16) & 1))) >> 16;
10597
return h;
10698
}

llama.cpp/ggml-vector.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,12 +859,12 @@ void ggml_bf16_to_fp32_row(const ggml_bf16_t * x, float * y, int64_t n) {
859859

860860
void ggml_fp32_to_bf16_row(const float * x, ggml_bf16_t * y, int64_t n) {
861861
int i = 0;
862-
#if defined(__AVX512BF16__)
862+
#if defined(__AVX512BF16__) && 0 // [jart] it kills subnormals
863863
for (; i + 32 <= n; i += 32) {
864864
_mm512_storeu_si512(
865865
(__m512i *)(y + i),
866866
m512i(_mm512_cvtne2ps_pbh(_mm512_loadu_ps(x + i + 16),
867-
_mm512_loadu_ps(x + i))));
867+
_mm512_loadu_ps(x + i))));
868868
}
869869
#endif
870870
for (; i < n; i++) {

0 commit comments

Comments
 (0)