fix(gemm): guard the W4A8 prefill tail scale read

The epilogue computed $v = acc * Ascale[m]$ before the store guard, so on the
last row tile of an M that is not a multiple of the tile height it named
Ascale[M] -- a row the caller does not own. The read is under the guard now.

inside is STFAST && (m0 + BM <= M), so it implies m < M for every row of the
tile, and n < N holds unconditionally because the launch rejects N % BN != 0.

No behaviour change is claimed: on gfx1201 at -O3 the compiler already
predicates the whole scale-and-store block (s_and_saveexec + s_cbranch_execz
around both the global_load_b32 of the scale and the store), so the published
binary does not issue the invalid load. This keeps the source honest for
compilers and ISA levels that do not.
This commit is contained in:
orca authored and StillDeadcode committed 2026-10-27 17:55:10 +01:00
1 parent 6645337f69
commit 9d37941a44
1 file changed
+4 -2
+4 -2
View File
@@ -279,9 +279,11 @@ __global__ __launch_bounds__(WM * WN * 32, 8) void r4d_gemm_w4a8_prefill_kernel(
for (int e = 0; e < 8; e++) {
const int n = n0 + (wn * TN + j) * 16 + (lane & 15);
const int m = mb + e;
const __hip_bfloat16 v =
(__hip_bfloat16)(acc[j][i][e] * (ASCVEC ? as[e] : Ascale[m]) * 0.0625f);
if (inside || (n < N && m < M)) {
// The scale read stays under the guard: past the last full tile `m >= M`, and the row it
// would read belongs to the next tile or to nothing at all.
const __hip_bfloat16 v =
(__hip_bfloat16)(acc[j][i][e] * (ASCVEC ? as[e] : Ascale[m]) * 0.0625f);
// the non-temporal builtin does not take a __hip_bfloat16*, so store its bits
if (STNT)
__builtin_nontemporal_store(*(const unsigned short*)&v,