Repository navigation
[ASM] [HIP] [JIT] [Perf] Replace gfx950 MLA v4 prefill 16mx8 kernels with 32mx4 kernels - #7784
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
There was a problem hiding this comment.
🔵 Needs a closer look
The named-register gfx950 kernels and prebuilt objects require GPU correctness and base-versus-head performance validation unavailable here, while the shared gfx1250 changes are reported as compile-checked only.
No open issues 🎉
What changed in this PR
Updates AITER’s OPUS MLA v4 sparse prefill on gfx950 to use 32mx4_32nx1 kernels for H > 32, while retaining the existing kernels for H ≤ 32.
Changes:
- Adds BF16 and FP8 kernel implementations with split-K variants and prebuilt-code-object dispatch.
- Updates automatic split-K fits and consolidates argument validation across gfx950 and gfx1250.
- Removes FP16 support for unscaled prefill and updates the affected tests and documentation to BF16.
| File | Description |
|---|---|
op_tests/test_mla_sparse_prefill.py |
Changes affected unscaled prefill tests to BF16 only. |
csrc/kernels/mla/opus/gfx950/mla_v4_prefill_traits.h |
Defines tile, register operand, and shared-memory configuration for the new kernels. |
csrc/kernels/mla/opus/gfx950/mla_v4_prefill_a8w8_32mx4_32nx1.hpp |
Implements FP8 prefill with BF16 RoPE and split-K support. |
csrc/kernels/mla/opus/gfx950/mla_v4_prefill_a8w8_32mx4_32nx1.cu |
Exports FP8 kernel entry points and records build flags. |
csrc/kernels/mla/opus/gfx950/mla_v4_prefill_a16w16_32mx4_32nx1.hpp |
Implements BF16 prefill with split-K support. |
csrc/kernels/mla/opus/gfx950/mla_v4_prefill_a16w16_32mx4_32nx1.cu |
Exports BF16 kernel entry points and records build flags. |
csrc/kernels/mla/opus/gfx950/mla_v4_prefill_a16w16_16mx8_32nx1.hpp |
Removes the superseded BF16 kernel implementation. |
csrc/kernels/mla/opus_mla_prefill_fwd.cu |
Adds prebuilt-kernel dispatch, shares validation, and groups launchers by architecture and version. |
aiter/ops/mla_sparse_prefill.py |
Updates split-K selection and enforces the BF16-only unscaled API. |
aiter/jit/optCompilerConfig.json |
Removes obsolete 16mx8 headers from JIT source dependencies. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The register-pinned GPU pipelines and prebuilt code objects need AMD-kernel specialist review, as independent GPU validation is unavailable and the gfx1250 validation refactor has only compile evidence.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
…2 rows Measured on MI355X against main's OPUS, whose H > 32 kernel #7784 and #7897 sped up: - H=64: OPUS takes 0.90x the triton backend's time on index lists captured from GLM-5.3-Flash prefill and 0.83-0.94x on uniformly random ones, so backend=None keeps OPUS there. backend="triton" still serves H=64. - H=32: OPUS takes 1.09x the triton backend's time on the captured lists and 1.75-2.07x on the random ones, but below 512 query rows 0.39-0.95x, so the bound rises from 64 to 512. test_default_backend_gfx950 runs at the bound, expects OPUS at H=64, and adds a case one row below the bound, which expects OPUS. Signed-off-by: Rony Leppänen <[email protected]>

Summary
For H > 32, gfx950 MLA v4 sparse prefill (
mla_sparse_prefillfor bf16,mla_sparse_prefill_v4for fp8 NoPE) now runs two new32mx4_32nx1kernels instead of the16mx8_32nx1kernels. H ≤ 32 still runs the 16mx1 kernels.Motivation
Every H = 64 and H = 128 shape ran on the 16mx8 kernels, where each of 8 waves owns 16 heads. In the 32mx4 kernels each of 4 waves owns 32 heads in QK and a 128-wide slice of dv in PV, and P is exchanged through LDS. This keeps the matrix cores busier: in the main loop of the bf16 kernel, MFMA is busy about 92% of the cycles (thread trace on MI355X). Over the shapes below, the new kernels are 1.21x (bf16) and 1.29x (fp8) faster (geomean).
Changes
mla_v4_prefill_{a16w16,a8w8}_32mx4_32nx1.{hpp,cu}undercsrc/kernels/mla/opus/gfx950/and their code objects inhsa/gfx950/mla_opus/.opus/build_co.shbuilds them with the amdgpu-named-reg-pin-std LLVM. The first line of each.culists its extra build flags.mla_v4_prefill_{a16w16,a8w8}_16mx8_32nx1.hpp), their traits and their JIT entries.num_kv_splitsis auto.mla_sparse_prefillaccepts bf16 only. gfx950 also accepted fp16 before; gfx1250 was already bf16-only.opus_mla_prefill_fwd.cuis grouped by arch, then by MLA version. The gfx950 and gfx1250 entries share their argument validation: one helper for a16w16 and one for a8w8.Performance (if applicable)
python op_tests/test_mla_sparse_prefill.py --backend opus --no-verify --prec <dtype>with N ∈ {1, 64, 256, 1024, 4096}, H ∈ {64, 128}, topk ∈ {384, 1024, 2048}, total_pages 65536 and auto split: 30 shapes per dtype. Before is the 16mx8 kernels onmain, After is this PR. Before and After are mean times over the shapes of each row. Change is the geomean speedup over the same shapes.Testing
Documentation
Dependencies
Breaking Changes
On gfx950, the opus backend of
mla_sparse_prefillnow raisesRuntimeErrorfor fp16 inputs. Callers must pass bf16q,unified_kvandkv. gfx1250 already required bf16.PR Self-Review
Reviewed revision
dc06a62
Behavior and intent
On gfx950, MLA v4 sparse prefill with H > 32 (bf16 and fp8 NoPE) now launches the prebuilt 32mx4_32nx1 code objects instead of the JIT-compiled 16mx8_32nx1 kernels. The 16mx8 kernels were 1.21x (bf16) and 1.29x (fp8) slower (geomean) on the benchmark shapes above. The opus bf16 entry now rejects fp16, so the a16w16 path has one dtype on both architectures. The
opus_mla_prefill_fwd.curestructure and the shared validation do not change which kernel runs.Validation and unverified scope
MI355X (gfx950), ROCm 7.2.3, PyTorch 2.10:
pytest op_tests/test_mla_sparse_prefill.py: 38 passed.python op_tests/test_mla_sparse_prefill.py -n 1 64 1024 --h_q 16 32 64 128 --prec bf16 v4_fp8 v41_fp8 v41_fp4 --backend opus --num_kv_splits 1 3 auto --no-bench: 576/576 passed.-n 0with H 16 and 128, bf16 and v4_fp8, splits 1 and 3: passed.Unverified: the gfx1250 entries, whose validation moved into the shared helpers, are compile-checked only because no gfx1250 hardware was available. MI250X and MI300X are not applicable: the opus prefill runs only on gfx950 and gfx1250. End-to-end model accuracy (for example DeepSeek-V4 under vLLM or ATOM) was not run.
PR-specific question
opus_mla_v4_prefill_a16w16_gfx950_fwd,opus_mla_v4_prefill_a8w8_gfx950_fwd) load the new code objects._opus_fwdpicks them fromget_gfx_runtime(), and architectures other than gfx950 and gfx1250 raise. gfx1250 dispatch is unchanged.q,unified_kv,kvandout. a8w8 takes fp8 NoPE rows (448 values, 14 E8M0 scales and padding in 512 bytes), bf16 RoPE (64) and bf16out. Indices and indptr are int32.num_kv_splits> 1 selects the split-K kernel and the reduce. N = 0 returns before any launch.opus_mla_v4_prefill_a16w16_kargsoropus_mla_v4_prefill_a8w8_kargs. These check dtypes, D, shapes, strides and index layout before any launch. The Python wrapper rejects non-bf16qandnum_kv_splitsoutside 1–32, and the a16w16 kernel has astatic_assertthat its data type is bf16.Changed op tests
op_tests/test_mla_sparse_prefill.py: removes the fp16 parametrization oftest_opus_csr_boundaries,test_opus_csr_without_sinkandtest_opus_csr_one_key_scale_one, because the op now rejects fp16. Their bf16 cases are unchanged. No test is added: the existingtest_mla_sparse_prefillmatrix already runs the new kernels for bf16 and v4_fp8. Its H = 64 case picks 4 auto splits, which exercises the split-K kernel and the reduce. Its H = 96 and H = 128 cases run unsplit, and H = 96 leaves a partial head block.