Skip to content

Commit

Permalink
Don't flush bf16 subnormals to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Jun 29, 2024
1 parent b2f587c commit 7fd9101
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
8 changes: 0 additions & 8 deletions llama.cpp/ggml-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ static inline float ggml_compute_bf16_to_fp32(ggml_bf16_t h) {

/**
* Converts float32 to brain16.
*
* This function is binary identical to AMD Zen4 VCVTNEPS2BF16.
* Subnormals shall be flushed to zero, and NANs will be quiet.
* This code should vectorize nicely if using modern compilers.
*/
static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
ggml_bf16_t h;
Expand All @@ -97,10 +93,6 @@ static inline ggml_bf16_t ggml_compute_fp32_to_bf16(float s) {
h.bits = (u.i >> 16) | 64; /* force to quiet */
return h;
}
if (!(u.i & 0x7f800000)) { /* subnormal */
h.bits = (u.i & 0x80000000) >> 16; /* flush to zero */
return h;
}
h.bits = (u.i + (0x7fff + ((u.i >> 16) & 1))) >> 16;
return h;
}
Expand Down
4 changes: 2 additions & 2 deletions llama.cpp/ggml-vector.inc
Original file line number Diff line number Diff line change
Expand Up @@ -859,12 +859,12 @@ void ggml_bf16_to_fp32_row(const ggml_bf16_t * x, float * y, int64_t n) {

void ggml_fp32_to_bf16_row(const float * x, ggml_bf16_t * y, int64_t n) {
int i = 0;
#if defined(__AVX512BF16__)
#if defined(__AVX512BF16__) && 0 // [jart] it kills subnormals
for (; i + 32 <= n; i += 32) {
_mm512_storeu_si512(
(__m512i *)(y + i),
m512i(_mm512_cvtne2ps_pbh(_mm512_loadu_ps(x + i + 16),
_mm512_loadu_ps(x + i))));
_mm512_loadu_ps(x + i))));
}
#endif
for (; i < n; i++) {
Expand Down

0 comments on commit 7fd9101

Please sign in to comment.