Skip to content

[Triton/Gluon] [gfx942] Enable sparse_mla_fwd on gfx942 - #5539

Closed
jin-amd wants to merge 1 commit into
ROCm:cagri/sparse_pa_optimizationsfrom
jin-amd:gfx942-sparse-mla
Closed

jin-amd wants to merge 1 commit into
ROCm:cagri/sparse_pa_optimizationsfrom
jin-amd:gfx942-sparse-mla

Conversation

@jin-amd

@jin-amd jin-amd commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Enables sparse_mla_fwd on gfx942, on top of #4919.

The Gluon kernel needs no change to run there — the gl.amd.cdna4 intrinsics it
uses (async_copy, mfma, buffer_load/buffer_store) all lower fine on
gfx942 under Triton 3.7.1. The arch gate was the only thing in the way, plus two
launch-config values sized against gfx950's LDS budget.

Why the tile has to change

gfx942 (CDNA3) has 64 KB of LDS per workgroup against gfx950's 160 KB. The
bf16 KV tile alone is BLOCK_K * (kv_lora_rank + LDS_PAD) * 2 B, so the gfx950
tile of 64 asks for 68 608 B and will not launch:

OutOfResources: out of resource: shared memory, Required: 68608, Hardware limit: 65536

BLOCK_K=32 is the largest that fits.

num_warps is decoupled from BLOCK_K in the same change. It was derived as
BLOCK_K // 16, so capping the tile for LDS would have dropped num_warps from 4
to 2 as a side effect rather than as a tuning decision. Keeping it at 4 is
worth 1.19× → 1.55× on the prefill shapes, so it is worth making explicit.

dot_precision="fp8" is rejected on gfx942

This one is a genuine hardware limit and was the only real surprise. The fp8 dot
path feeds the cache's own code points to the matrix core, which needs OCP
e4m3 MFMA — that arrives with CDNA4
. CDNA3 has fp8 MFMA in the fnuz encoding
only, so OCP code points read back wrong.

It was silently wrong (rel-err 7.5e-1) rather than faulting, which is why
this raises now, naming the alternative. dot_precision="bf16" dequantizes the
tile on its way into LDS and works on every arch and every cache format —
including the fp8 caches, which is what production uses here.

gfx950 is unchanged

_arch_block_k → 64, _arch_num_warps → 4, lds_limited False, and
FP8_DOT_ARCHS contains gfx950, so every value and branch resolves exactly as
before. I do not have gfx950 hardware, so that claim is by construction rather
than by test — worth a second pair of eyes.

Validation

On MI325X (gfx942), TP4, GLM-5.3-Flash at 131 k context. This matters on that
model because its NoPE MLA has qk_rope_head_dim = 0, which has no AITER path
today, so vLLM falls back to a vendored Triton gather+dot — the single largest
kernel in the model in both phases.

op_tests/triton_tests/attention/test_sparse_mla.py:

32 passed, 12 skipped in 23.61s
SKIPPED [12] fp8 matrix-core dots need OCP e4m3, absent on gfx942

Kernel bucket, from a real torch profile at concurrency 12 (rank 0):

phase bucket Triton (vLLM) this kernel speedup
decode per step 3.099 ms 0.400 ms 7.74×
prefill per call 10 988 µs 10 330 µs 1.06×

End-to-end, 131 k in / 1024 out, same image both arms with only the dispatch
switched:

conc out tok/s before → after delta
2 80.92 → 91.36 +12.90%
4 110.96 → 121.09 +9.13%
8 129.61 → 137.74 +6.27%
12 141.29 → 147.94 +4.71%
16 143.24 → 149.89 +4.64%

Won 7/7 rows, mean +7.14% output throughput, zero failed requests. gsm8k
(5-shot, full 1319 questions) is neutral: 0.9719 vs 0.9712 strict-match, against
a ±0.0046 standard error.

The gain being largest at low concurrency is the signature of this kernel rather
than noise: the operator is batch-independent, so replacing it takes a roughly
constant ~2.7 ms off every decode step, which is 16.6% of TPOT at concurrency 2
but 4.9% by concurrency 16.

Note on prefill

The 1.06× prefill figure is the honest one, measured in a profile. A
microbenchmark using randperm top-k indices reports 1.55× for the same shape,
but that flatters it — random indices give the Triton gather far worse locality
than production does (11.0 ms real vs 15.7 ms synthetic for the same shape),
while this kernel gathers whole 512 B rows and is locality-insensitive. Prefill
microbenchmarks on this operator should not be trusted without a profile.

@zufayu
zufayu requested review from a team and Dewei-Wang-sh September 16, 2026 01:52
sparse_mla_fwd was gated to gfx950. The Gluon kernel itself needs no change to
run on gfx942 -- the gl.amd.cdna4 intrinsics it uses lower fine there -- so the
gate was the only thing in the way, plus a tile size chosen against gfx950's
LDS budget.

gfx942 has 64 KB of LDS per workgroup against gfx950's 160 KB, so BLOCK_K=64
asks for 68608 B and fails to launch:

  OutOfResources: shared memory, Required: 68608, Hardware limit: 65536

BLOCK_K=32 is the largest tile that fits. num_warps is pinned at 4 rather than
following block_k // 16, so the LDS cap does not halve it as a side effect
rather than as a tuning decision; that is worth 1.19x -> 1.55x on the prefill
shapes.

dot_precision="fp8" is rejected on gfx942. It feeds the cache's own code points
to the matrix core, which needs OCP e4m3 MFMA; CDNA3 has fp8 MFMA in the fnuz
encoding only, so those code points come out wrong. It was silently wrong
(rel-err 7.5e-1) rather than faulting, so this is now an explicit error naming
the alternative. dot_precision="bf16" dequantizes the tile into LDS and works
on every arch and every cache format, fp8 caches included.

The bench's fp8-dot series is built from FP8_DOT_ARCHS for the same reason:
with the arch gate widened it would otherwise reach that series on gfx942 and
raise on its first point, and triton's perf_report does not catch it, so the
run died before printing a table.

The test's cache builders go back to an explicit OCP e4m3 rather than the
arch-native fp8 dtype. These records are OCP by definition of the format, and
the kernel's dequant reads OCP code points; on gfx942 the native dtype is
float8_e4m3fnuz, so building with it decoded to garbage (rel-err 1.0) on every
fp8-cache case. _classify_flat already rejects fnuz when a uint8 view is not
hiding the dtype.

gfx950 is unchanged: _arch_block_k -> 64, _arch_num_warps -> 4, lds_limited
False, FP8_DOT_ARCHS contains gfx950, and FP8_DTYPE is OCP e4m3 there either
way, so every value and branch resolves exactly as before.

Validated on MI325X (gfx942), TP4, GLM-5.3-Flash at 131k context, where this
path serves the rope-free NoPE MLA that has no AITER kernel today:

  op_tests test_sparse_mla   32 passed, 12 skipped (fp8 dots)
  bench_sparse_mla           runs clean, bf16 series only
  sparse-MLA decode bucket   3.099 -> 0.400 ms/step   7.74x
  sparse-MLA prefill         10988 -> 10330 us/call   1.06x
  end-to-end sweep           +7.14% mean output tok/s, 7/7 rows won
  gsm8k                      0.9719 vs 0.9712 strict-match (neutral)

Co-authored-by: Cursor <[email protected]>
@cagrikymk
cagrikymk deleted the branch ROCm:cagri/sparse_pa_optimizations September 18, 2026 15:25
@cagrikymk cagrikymk closed this Sep 18, 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.

3 participants