Skip to content

[ASM] [gfx1250] mla v4 prefill: rebuild the sparse_pfl kernel - #5367

Merged
junhaha666 merged 1 commit into
mainfrom
gfx1250/mla_v4_sparse_pfl_co
Sep 10, 2026
Merged

junhaha666 merged 1 commit into
mainfrom
gfx1250/mla_v4_sparse_pfl_co

Conversation

@junxiaguo

@junxiaguo junxiaguo commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Rebuild mla_a8w8_qh128_1tg_32mx4_32nx1_sparse_pfl.co

  • fp8 e8m0 scale granularity corrected to one scale per 32 elements, and the packed row's 448:511 tail is zeroed (with the S_to_P MSB fix it exposed).
  • update coreloop.

Performance

op_tests/test_pa_sparse_prefill.py, --backend asm --prec fp8 --h_q 128 -d 512, on gfx1250. Three interleaved A/B runs, best run each:

mode N total_pages before µs after µs speedup TFLOPS
sparse 1024 4096 296.55 255.17 1.16× 2339 → 2718
sparse 1024 16384 911.10 791.55 1.15× 2537 → 2920
sparse 4096 4096 1559.73 1346.34 1.16× 2830 → 3279
sparse 4096 16384 3736.42 3235.25 1.16× 2950 → 3415
dense 1024 4096 455.32 399.01 1.14× 3019 → 3445
dense 1024 16384 1480.73 1296.32 1.14× 3156 → 3605
dense 4096 4096 2836.98 2478.22 1.14× 3101 → 3549
dense 4096 16384 6975.46 6109.89 1.14× 3153 → 3599

Peak moves 3155 → 3605 TFLOPS. Run-to-run spread also tightens: the old build had a run where sparse regressed 40% (1024/16384 at 1260 µs, 4096/16384 at 5242 µs); the new build stayed within 1% across all three runs.

Correctness

  • All eight cases above pass the test's PyTorch reference check (atol=rtol=0.01, err=0.0).
  • Validated end to end on DeepSeek-V4-Pro: gsm8k 100 questions 3-shot, 0.94 / 0.94, no memory faults.

🤖 Generated with Claude Code

Rebuild mla_a8w8_qh128_1tg_32mx4_32nx1_sparse_pfl.co from the current
32mx4_32nx1 source. Binary-only change; no host or dispatch code moves.

What is in the new build, on top of the one shipped by #4926:

* head/tail schedule rework -- the prologue index chain is hoisted and the
  Q/K TDM descriptor setup is packed into the blocking window, so the
  non-core-loop cost stops dominating at small nnz_prefix.
* core-loop reorder -- 124 DS ops moved into WMMA shadows, ~2129 -> ~1933
  issue slots per tile.
* PTL (page-table) prefetch hazard fixed: the CSR index prefetch is bounded
  and waits for the writelane before the shift reads it.
* fp8 e8m0 scale granularity corrected to one scale per 32 elements, and the
  packed row's 448:511 tail is zeroed (with the S_to_P MSB fix it exposed).

Measured with op_tests/test_pa_sparse_prefill.py, backend=asm prec=fp8
h_q=128 d=512, on gfx1250:

  mode    N     total_pages   before us   after us   speedup
  sparse  1024  4096             296.55     255.17    1.16x
  sparse  1024  16384            911.10     791.55    1.15x
  sparse  4096  4096            1559.73    1346.34    1.16x
  sparse  4096  16384           3736.42    3235.25    1.16x
  dense   1024  4096             455.32     399.01    1.14x
  dense   1024  16384           1480.73    1296.32    1.14x
  dense   4096  4096            2836.98    2478.22    1.14x
  dense   4096  16384           6975.46    6109.89    1.14x

Peak moves 3155 -> 3605 TFLOPS. All eight cases pass the test's PyTorch
reference check (atol=rtol=0.01, err=0.0). Also validated end to end on
DeepSeek-V4-Pro (gsm8k 100q 3-shot, 0.94/0.94, no memory faults).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@junxiaguo
junxiaguo requested a review from a team September 9, 2026 10:01
@github-actions github-actions Bot changed the title [ASM][gfx1250] mla v4 prefill: rebuild the sparse_pfl kernel [ASM] [gfx1250] mla v4 prefill: rebuild the sparse_pfl kernel Sep 9, 2026
@github-actions github-actions Bot added the ASM label Sep 9, 2026
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5367 --add-label <label>

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 opt this PR out.

@zufayu
zufayu requested a review from amd-ruitang3 September 10, 2026 02:39
@junhaha666
junhaha666 merged commit feba81f into main Sep 10, 2026
50 of 52 checks passed
@junhaha666
junhaha666 deleted the gfx1250/mla_v4_sparse_pfl_co branch September 10, 2026 08:54
valarLip pushed a commit that referenced this pull request Sep 17, 2026
… rework (#5580)

Rebuild mla_a8w8_qh128_1tg_32mx4_32nx1_sparse_pfl.co from the current
32mx4_32nx1 source. Binary-only change; the kernarg layout, the symbol name
and the mla_v4_asm.csv row are all unchanged, so no host or dispatch code
moves.

What is in the new build, on top of the one shipped by #5367:

* tail store address hoist (T1 + T5-b) -- the store address comes out of the
  inner loop, two alternating pack buffers on a global parity let the fence
  relax to `vm_vsrc: 1`, and the WAR distance becomes two stores everywhere.
  The 46 idle cycles per iteration were not free issue slots before: the wave
  was parked on the `s_wait_alu { vm_vsrc: 0 }` sitting right after ds_store.
* split final R writeback (T6) -- the 32 KB tensor_store_from_lds became two
  per-q transfers. A 20-tile ttrace measured the TAIL as one hole, not many:
  every one of the 16 waves had exactly one gap above 100 cycles, four
  instructions from the end, 2519..4050 cyc, 56-67% of TAIL. q0's sixteen
  rows are complete in LDS halfway through the batched store, so issuing
  that half early puts it in flight across q1's scale/convert work. Same
  bytes, same order.
* prologue index prefetch and prologue scheduling reworked; the final R LDS
  stores are pipelined and batched.
* HEAD_KV_PTL_PREFETCH added behind a knob and left OFF -- on a warmed
  capture it moved nothing (HEAD 3423 -> 3500, K0 span 796 -> 836) and cost
  28 B when off. Whether it pays on a genuinely cold first dispatch is
  untested.

Measured with op_tests/test_pa_sparse_prefill.py, backend=asm prec=fp8
h_q=128 d=512, on gfx1250 (256 CU). Each figure is the median of three
alternating before/after passes; both binaries ran in the same window on an
otherwise idle GPU.

  mode    N     total_pages   before us   after us   speedup
  sparse  1024  4096             241.57     235.57    1.025x
  sparse  1024  16384            741.08     739.83    1.002x
  sparse  4096  4096            1278.32    1269.58    1.007x
  sparse  4096  16384           3081.76    3073.65    1.003x
  dense   1024  4096             378.67     375.47    1.009x
  dense   1024  16384           1231.62    1227.15    1.004x

The gain is small here and that is expected: this round of work is all in
the head and the tail, which are a fixed cost per dispatch, so their share
shrinks as the tile count grows. It is largest at the shortest rows
(N=1024, total_pages=4096) and the ordering is consistent -- across two
independent runs the new binary was faster in 36 of 36 repeat-wise pairs.

Source: my_agent_skills 0805_base/32mx4_32nx1.sp3 at 07257d72c6a7, SHA256
e017a703168b88b885f5a00080ff60dd6cb966723c175ad8a1d4556eff3ca99f. New .co
SHA256 f55d85ece7ab7b6b3f26a1d3097a9d1687fcb8b7f9b5c4cff12f6bde3a43475f.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: HaonanWang98 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants