Archived
libr4d: the split-KV row sum read with fetch-inactive (#328)
The prefill KV split (6a7824a) stores each segment's row sum under `if (h == 0)`, so only half the
wave consumes `l_i += swap16(l_i)`. A compiler may sink the exchange into that half, where
v_permlanex16 with fi = 0 reads the lane's own value for the inactive partner, and the stored sum is
then twice one half's instead of the pair's: the merge normalises by the wrong total. The decode
kernel's f32-partial path has the same shape (lrow read under `if (h == 0)` only).
swap16_fi sets fetch-inactive, so the partner's half is read whatever exec says. With every lane
active it is the same exchange. Found by sabi-noema and posted by mordae in #328; this is their
helper and prefill change, plus the decode path.
The compilers I have do not sink it: in this tree's build (ROCm 10.1) and in the published 1.14.0
libr4d.so, every split instance of the h256/gqa6 prefill kernel exchanges before the `h == 0` mask.
So the fix changes the code (op_sel:[1,0] on those exchanges, a register shuffle around them) but
not the results here, and no test here can fail without it. r4d_selftest: the h256/gqa6 prefill and
decode rows, every cache layout, 453 checks, 0 failures.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9cf8d3dad8
commit
167595a9b4
3 files changed
+16
-2
No files matched your search
@@ -608,7 +608,9 @@ void r4d_attn_decode_body(const R4DArgs& a, int splits)
|
||||
}
|
||||
|
||||
if (!live) return;
|
||||
const float lrow = l_i + swap16(l_i);
|
||||
// fetch-inactive: the f32 partials read lrow under `if (h == 0)` only (see the prefill kernel's
|
||||
// epilogue, #328).
|
||||
const float lrow = l_i + swap16_fi(l_i);
|
||||
const int tok = qoff + qrow;
|
||||
const size_t idx = (size_t)(tok * a.q_heads + qhead) * splits + sp;
|
||||
const size_t nrow = (size_t)r4d_q_total(a) * a.q_heads * splits;
|
||||
|
||||
Reference in new issue
Block a user