Skip to content

[ASM] [HIP] Walk prefix and extend as one tile stream in gfx950 MLA sparse prefill - #7897

Merged
kaiyang-1 merged 3 commits into
mainfrom
kaiyang-1/mla_tile_stream
Nov 13, 2026
Merged

kaiyang-1 merged 3 commits into
mainfrom
kaiyang-1/mla_tile_stream

Conversation

@kaiyang-1

@kaiyang-1 kaiyang-1 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • gfx950 MLA v4/v4.1 sparse prefill (16mx1, 16mx4, 32mx4): a workgroup walks its prefix tiles, then its extend tiles, as one stream. The pipeline no longer drains between the two segments, and either segment may be empty.
  • v4 16mx1: the waves exchange their row maxima with their fp32 P in one round. The bf16 kernel also moves K/V to registers before the next tile's gather ([HIP] [Perf] Pipeline CSR segments in unsplit OPUS sparse prefill #6831's approach, now on the split-K path too).
  • v4.1 16mx1: tile 1's page index is issued before tile 0's K, so under ROCm 7.2 the first tile no longer waits on it.
  • v4.1 a8w4 16mx4: the NVFP4 dequant of the next tile stays interleaved with the PV MFMAs. Its temporaries are now per tile, so the compiler no longer hoists one stage's dequant ahead of the PV. Each group's v_pk_mul_f32 run back to back, so they wait for a running MFMA once per group instead of once per pair.
  • Rebuilt the four gfx950 code objects (v4 32mx4 x2, v4.1 16mx4 x2).
  • Refit the gfx950/gfx1250 split-K constants on the new test inputs. The 16mx1 entries gain a packed factor.
  • test_mla_sparse_prefill.py: the CLI inputs follow DeepSeek V4/V4.1 inference.
    • --window (each token's last W extend rows, default 128) replaces --total_tokens.
    • --topk is the prefix count (default 512 1024).
    • -n defaults to 1024 4096 16384.
    • The pytest cases are unchanged.

Performance

MI355X. Default sweep of op_tests/test_mla_sparse_prefill.py --backend opus --no-verify: N 1024/4096/16384, H 16/32/64/128, topk 512/1024, window 128, total_pages 64K/1M. Median of 3 runs; speedups are geomeans.

prec kernel (H) #7784 vs before this PR vs main this PR vs before #7784
bf16 16mx1 (16, 32) 1.00x 1.00x 1.00x
bf16 32mx4 (64, 128) 1.26x 1.01x 1.27x
v4_fp8 16mx1 (16, 32) 1.00x 1.03x 1.03x
v4_fp8 32mx4 (64, 128) 1.38x 1.00x 1.38x
v41_fp8 16mx1 (16) 1.00x 1.01x 1.01x
v41_fp8 16mx4 (32, 64, 128) 1.00x 1.03x 1.03x
v41_fp4 16mx1 (16) 1.00x 1.01x 1.01x
v41_fp4 16mx4 (32, 64, 128) 1.00x 1.05x 1.05x

Across all 192 cases this PR is 1.022x over main (0.986x to 1.074x). #7784 only replaced the 16mx8 kernels with 32mx4 for H > 32.

Split-K: auto only splits when the grid underfills (N up to ~512).

  • 704 fit shapes: the auto pick's geomean loss against the best measured split count drops from 1.3% to 0.2%.
  • 240 shapes outside the fit grid: 21 picks change, 1.046x geomean on those (0.93x to 1.25x).

Testing

  • pytest op_tests/test_mla_sparse_prefill.py: 38 passed.
  • CLI correctness:
    • all four precs;
    • H 16, 17, 64, 65, 128;
    • window 128, 0, 1000;
    • empty prefix or extend;
    • num_kv_splits auto, 1, 2, 3, 7, 32;
    • small-N auto splits.
      All pass.

@kaiyang-1
kaiyang-1 requested review from a team and a balanced review from Copilot November 12, 2026 18:16
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter standard tests on MI35X
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7897 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@github-actions github-actions Bot changed the title Walk prefix and extend as one tile stream in gfx950 MLA sparse prefill [ASM] [HIP] Walk prefix and extend as one tile stream in gfx950 MLA sparse prefill Nov 12, 2026
@aiter-bot

aiter-bot commented Nov 12, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision d315afa452f6 · mode shadow

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

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_mla_sparse_prefill.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The rewritten BF16 16mx1 split-K path lacks reference-checked tests with explicit split counts covering a partial prefix/extend boundary and an empty split on a 256-CU gfx950.

1 open issue
What changed in this PR

This PR extends earlier OPUS sparse-prefill optimizations by processing prefix and extend tiles as one stream in gfx950 MLA kernels, reducing pipeline drains and repeated synchronization.

Changes:

  • Unifies tile traversal and updates prefetching across BF16, FP8, and mixed FP4/FP8 kernels.
  • Combines row-maxima and FP32 probability exchange in v4 16mx1 kernels and refits automatic split-K selection.
  • Adds window-based CLI inputs matching DeepSeek inference workloads while preserving existing pytest cases.
File Description
op_tests/​test_mla_sparse_prefill.py Adds window-based extend inputs and updates CLI defaults.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v41_prefill_a8w8_16mx4_64nx1.hpp Streams prefix and extend tiles through one pipeline.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v41_prefill_a8w8_16mx1_16nx4.hpp Unifies traversal and advances page-index prefetching.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v41_prefill_a8w4_16mx4_64nx1.hpp Reuses staged queries across the FP4-to-FP8 handoff.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v41_prefill_a8w4_16mx1_16nx4.hpp Joins extend and prefix processing with format-specific stages.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v4_prefill_traits.h Updates shared-memory sizing for FP32 probability exchange.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v4_prefill_a8w8_32mx4_32nx1.hpp Refactors segment selection, prefetching, and tail masking.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v4_prefill_a8w8_16mx1_16nx4.hpp Unifies traversal and combines cross-wave softmax exchange.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v4_prefill_a16w16_32mx4_32nx1.hpp Simplifies stream addressing and segment-tail handling.
csrc/​kernels/​mla/​opus/​gfx950/​mla_v4_prefill_a16w16_16mx1_16nx4.hpp Shares the pipelined implementation between split and unsplit paths.
aiter/​ops/​mla_sparse_prefill.py Refits gfx950 and gfx1250 automatic split-K constants.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 13, 2026 03:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The DMA/LDS hand-offs and register-lifetime changes require native gfx950 review and exact-head GPU validation, while rebuilt code-object parity and gfx1250 performance remain unverified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@kaiyang-1
kaiyang-1 requested a review from shengnxu November 13, 2026 07:00
@kaiyang-1
kaiyang-1 merged commit 33ff6b5 into main Nov 13, 2026
@kaiyang-1
kaiyang-1 deleted the kaiyang-1/mla_tile_stream branch November 13, 2026 07:03
vpietila-amd pushed a commit that referenced this pull request Nov 13, 2026
…parse prefill (#7897)

* Walk prefix and extend as one tile stream in gfx950 MLA sparse prefill

* Refit the auto split-k parameters of MLA sparse prefill

* Keep the NVFP4 dequant interleaved with the PV MFMAs
eppaneamd added a commit that referenced this pull request Nov 13, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants