gfx12 prompt attention: pin the q.k WMMA before the trimmed store

With q4_lite's G = 8 the trimmed store guard passes only lanes 0-15 (halves differ for Flash-Next's
G = 12), and the compiler could sink the whole-wave WMMA into that half-wave branch; the R9700 then
stored -nan and every prompt past a few thousand tokens ended in non-finite logits (#879). Pinning s
with an empty asm before the store keeps the arithmetic unchanged and makes TRIM 2/1/0 bit-identical;
Flash-Next checksums are unchanged.

The hip parity test now counts non-finite outputs before comparing: NaN comparisons are false, so the
broken kernel used to pass with a bogus FP64 error of 0.
This commit is contained in:
Saatvik Viniak committed 2026-12-04 01:17:59 -06:00
1 parent bd90b8c526
commit ffec4241bd
2 files changed
+10

No files matched your search

@@ -2101,6 +2101,10 @@ __device__ __forceinline__ void prompt_attn_wmma_body(const float* __restrict__
s = wmma_f16(qh[kk], b, s);
if constexpr (SPLIT) s = wmma_f16(ql[kk], b, s);
}
// the WMMA needs the whole wave: pin s here, so a store guard that only one half of the wave passes
// (G <= 8: rows 8..15 are all padding) cannot pull the WMMAs into that branch
#pragma unroll
for (int i = 0; i < 8; ++i) asm volatile("" : "+v"(s[i]));
#pragma unroll
for (int i = 0; i < 8; ++i) if (!TR || PA_ROW(i, half) < G) S.part[warp][PA_ROW(i, half)][nt * 16 + col] = s[i] * cd.ksc[nt];
}
@@ -238,6 +238,12 @@ int run(int fmt, int64_t ctx, int64_t nq, int reps) { // fmt 1 int8, 0 fp16, 2
for (float x : nw) { uint32_t u; std::memcpy(&u, &x, 4); hh = (hh ^ u) * 1099511628211ull; }
std::printf("NEWHASH %016llx\n", (unsigned long long) hh);
}
{ // a non-finite output fails every comparison below silently (NaN > x is false): count them first
long long bad = 0;
for (float x : nw) bad += !std::isfinite(x);
for (float x : im) bad += !std::isfinite(x);
if (bad) { std::printf("FAIL ctx %lld, %lld queries: %lld non-finite outputs\n", (long long) ctx, (long long) nq, bad); return 1; }
}
// 1. FP64 reference on a sample of queries
double err_old = 0, err_new = 0, err_im = 0, ref_scale = 0;
for (int64_t i = 0; i < nq; i += std::max<int64_t>(1, nq / 16)) {