Skip to content

hip: RDNA3 (gfx1100) WMMA kernel for the QSA block-score select/scorer (opt-in STRATA_SELECT_WMMA, gfx12/gfx11) - #856

Closed
xyzzing wants to merge 3 commits into
Niko1221:mainfrom
xyzzing:feature/select-wmma-rdna3-0139
Closed

xyzzing wants to merge 3 commits into
Niko1221:mainfrom
xyzzing:feature/select-wmma-rdna3-0139

Conversation

@xyzzing

@xyzzing xyzzing commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Companion to #786: the same RDNA3 WMMA treatment for the QSA select/scorer path, which the profiler puts at ~12-14% of 128K prefill on gfx1100.

What

  • qsa_block_scores_wmma: a gfx11 (RDNA3) WMMA block-scorer arm. Dispatch in qsa_block_scores_tc (qsa_select.cu) tries the gfx12 WMMA kernel first, then this arm under STRATA_SELECT_WMMA (opt-in; default unchanged). The tail block keeps the warp kernel's arithmetic (shared block_scores_tail_kernel, bitwise) and the +1e9 dead-tail rule is exact.
  • Parity harness src/kernels/qsa_select_wmma_parity.cpp (new): ragged query/block tiles, whole tiles, an x8-magnitude FP16-headroom case, degenerate n_kv=0, one-hot lane/store-adversarial case.

Arithmetic contract and parity (pre-derived before the kernel, rollout records §18): WMMA arm = FP16 inputs / FP32 accumulation; bound per entry B = 2^-9.5·S + 8·2^-24·|score| against a float64 oracle (S = the |k·q| magnitude sum, computed in f64 in the harness). Measured on the 10.2 nightly SDK: worst bound utilisation 11.0% across all cases, 0 differing selection IDs (top-k over warp vs WMMA scores, near-tie-gap guard), tail block bitwise the warp arm's, write-set canaries intact, negative control (+2.5·B perturbation) fails as required. The warp arm's host-model contraction pin (7.1.1-era: fma-left) no longer fits the nightly clang's v_fmac interleaving; the harness now enumerates six contraction shapes and reports the best fit as a diagnostic, with the oracle bound + selection agreement + tail check as the hard gates.

Measured, paired A/B (RX 7900 XTX, 0.1.39 + #786 arm-on in BOTH arms, arms differ only in STRATA_SELECT_WMMA; 5 pairs × 1k/32k/128k, odd pairs a-first):

tier prefill tok/s a→b (median) Δ decode tok/s a→b (median) Δ
128K 1506 → 1675 +11.2% 66.0 → 69.3 +4.9%
32K 1595 → 1689 +5.9% 73.6 → 74.4 +1.1%
1K 764 → 791 +3.5% 72.0 → 72.0 -0.0%

Mechanism: the qsa select phase drops 10249 ms → 1952 ms (5.25×; 11.8% → 2.4% of 128K prefill). Consistent with the earlier 0.1.33 measurement (+9.8% @128k, scorer microbench 11.6×). Decode: no regression in any tier (medians; the one 51.9 tok/s outlier in b-128k-p2 does not move the median).

Opt-in only. STRATA_SELECT_WMMA=1 enables the arm; the default path and the gfx12 arm are untouched.

… (opt-in STRATA_HIP_WMMA, gfx12/gfx11)

The S6 matrix-core prompt attention was RDNA4-only; gfx1100 kept the ordered FP32
fallback - measured at 25.6-26.9% of prefill GPU time at 32K/128K on a 7900 XTX.

RDNA3 runs the same v_wmma_f32_16x16x16_f16 instruction through the unsuffixed
builtin, whose wave32 fragment layout differs from the gfx12 builtin's on all three
operands (AMD Matrix Instruction Calculator, rdna3 tables, hardware-confirmed by a
standalone probe): A[l&15][i], B[j][l&15], D[(l>>4)+2j][l&15]. The packing sites
re-index accordingly; softmax, staging, scales and the online-softmax protocol are
unchanged; the K side keeps one cell per lane so the per-cell scale folds as before.

Parity (upstream's hip_prompt_attn_wmma, first time it runs off gfx12): 3/3 PASS,
vs FP64 3.3-4.5e-06 (old kernel 1.8-2.1e-06, same class); kernel 4.17-4.91x per chunk.
Paired e2e on the 7900 XTX (production-mirrored config, 5 pairs x 1k/32k/128k,
arms alternate): prefill +22.8% median @128k (5/5) and +17.9% @32k (5/5), decode
flat (protection cap holds). Opt-in unchanged: STRATA_HIP_WMMA=1.
Niko1221#368 content)

Carried from the pr-qsa-select-wmma-rdna3 branch (0.1.38 rebase 7e8adda) onto the
current line (0.1.39 + the RDNA3 WMMA prompt-attention arm). The gfx11 kernel keeps
its rename (block_scores_wmma_gfx11_kernel; the gfx12 kernel keeps the plain name),
the arch dispatch inside qsa_block_scores_tc routes gfx12 -> gfx1100-under-opt-in ->
false (warp fallback), and the arm prints once so no fallback can masquerade.
Parity + bench re-registered in CMake.
…diagnostic

The nightly SDK's newer clang no longer contracts the warp kernel's 4-product dot
into any single host-emulable shape (it interleaves the four head-accumulators
through v_fmac; previously the harness pinned fma-left on the 7.1.1 toolchain).
The pinned-pattern check is a warp-kernel drift detector, not the WMMA arm's
contract - the arm's gates are the FP64-oracle bound, selection-id agreement, the
bitwise tail, the canaries and the negative controls. The pattern set grew from
three to six shapes and the check prints as a WARN when no shape fits 100%.
@xyzzing

xyzzing commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of the refreshed pr-qsa-select-wmma-rdna3 branch (a3cf018 = upstream/main 6f32ec0 + the two select commits), which keeps this arm disjoint from #786; measured-numbers comment posted on #368's thread. This PR carried the same two commits (9687100 port + 972a637 parity-harness contraction-pin diagnostic) on the fork working line — the fork main merge (fc19bf7) stands as our production line; production 8081 runs the arm opt-in (STRATA_SELECT_WMMA=1) with the +11.2% @128k / no-decode-regression A/B recorded in the rollout records.

@xyzzing xyzzing closed this Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant