gemm_fp8a8: the gated three-tile form pinned at 8 waves (gate_up at 48 rows 272.9 -> 180.6 us)

The gated row at 33 to 48 rows (NT 3, MW 16) was pinned at 9 waves, 168 registers, where its
epilogue spilled: 57 registers at the full tile (48 rows) and 10 below it (12 and 59 in its
chained twin). At Qwen3.8-27B FP8's gate_up at tp 2 (N 17408, K 5120) 48 rows took 272.9 us
against 180.6 at 56. The gated form is always MW 16, so a block puts four waves on each SIMD, and
8 and 9 waves both hold two blocks a WGP: at 8 the form gets 192 registers for no occupancy, and
spills 7 at 48 rows and none below. f8_waves takes the gated flag (false by default), so no other
form's pin moves.

A pin changes register allocation only. r4d_selftest --case dequant_w4_bf16 (fp8_numeric, which
checks the gated row byte for byte against the GEMM + gated_quant_fp8 pair at every M it runs),
every launch of an fp8 narrow GEMM row hashed after it in 6c33ee4 and here: 879 of 879 identical,
42 of them gated; 1,526 ok, 0 FAIL.

r4d_selftest --perf 17408 5120 M, cold, one R9700 at 240 W, five alternating rounds against
6c33ee4, medians: 48 rows 272.9 -> 180.6 us (-33.8 %), 33 to 47 rows 186.2-187.6 -> 175.9-177.1
(-5.5 %), 8 to 32 and 56 to 64 rows within 0.3 %.
This commit is contained in:
Adam Zhang authored and StillDeadcode committed 2026-10-28 13:48:23 +01:00
1 parent 14b8f21a1a
commit 3efb37254b
1 file changed
+11 -4
+11 -4
View File
@@ -151,14 +151,21 @@ constexpr uint32_t kSplitThinCap = 64u;
* tuned at (the NT accumulators and K-step unroll are sized against it), so a compiler release
* cannot change occupancy. Shapes with one or two waves per block are LDS-bound and use that
* count. */
constexpr uint32_t f8_waves(bool full, uint32_t nt, uint32_t mw, uint32_t fk, bool i8) {
constexpr uint32_t f8_waves(bool full, uint32_t nt, uint32_t mw, uint32_t fk, bool i8,
bool gated = false) {
if (mw == 1u) return nt == 1u ? 8u : nt == 2u ? 4u : nt == 3u ? 3u : 2u;
if (mw == 2u) return nt == 1u ? 12u : nt == 2u ? 8u : nt == 3u ? 5u : 4u;
if (!i8) {
if (fk == 128u)
return nt == 1u ? 16u : nt == 2u ? (full ? 16u : 12u) : nt == 3u ? 10u
: (full && mw >= 8u) ? 10u : 9u;
return nt == 1u ? 12u : nt == 2u ? 10u : nt == 3u ? 9u : mw == 4u ? 7u : 8u;
/* The gated three-tile form at 8, not 9. At 9 waves' 168 registers its epilogue spilled
* 57 at the full tile (48 rows), which ran gate_up 51 % slower than 56 rows, and 10 below
* it. 8 waves leave 192, where it spills 7 at 48 rows and none below. The gated form is
* always MW 16, four waves a SIMD a block, so 8 and 9 both hold two blocks a WGP: no
* occupancy is lost. */
return nt == 1u ? 12u : nt == 2u ? 10u : nt == 3u ? (gated ? 8u : 9u)
: mw == 4u ? 7u : 8u;
}
if (fk == 128u)
return nt == 1u ? 16u : nt == 2u ? (full ? 10u : 12u) : nt == 3u ? (full ? 9u : 10u)
@@ -598,7 +605,7 @@ __device__ __forceinline__ void gemm_fp8a8_body(
Sc, Yb, q_ld, s_ld, y_ld, Bias, c_ld
template <bool Full, uint32_t NT, uint32_t MW, uint32_t FK,
bool GATED = false, bool I8 = false, bool BIAS = false>
__global__ __launch_bounds__(MW * kWave) R4D_WAVES(f8_waves(Full, NT, MW, FK, I8))
__global__ __launch_bounds__(MW * kWave) R4D_WAVES(f8_waves(Full, NT, MW, FK, I8, GATED))
void gemm_fp8a8_kernel(
const uint8_t* __restrict__ Ap, const void* __restrict__ Sa,
const uint8_t* __restrict__ Bp, const void* __restrict__ Sb,
@@ -613,7 +620,7 @@ void gemm_fp8a8_kernel(
}
template <bool Full, uint32_t NT, uint32_t MW, uint32_t FK,
bool GATED = false, bool I8 = false, bool BIAS = false>
__global__ __launch_bounds__(MW * kWave) R4D_WAVES(f8_waves(Full, NT, MW, FK, I8))
__global__ __launch_bounds__(MW * kWave) R4D_WAVES(f8_waves(Full, NT, MW, FK, I8, GATED))
void r4dchain_gemm_fp8a8(
const uint8_t* __restrict__ Ap, const void* __restrict__ Sa,
const uint8_t* __restrict__ Bp, const void* __restrict__ Sb,