Skip to content

[ASM] [HIP] [FlyDSL] Optimize gfx1250 PS1 FP8 MLA decode for Kimi-K3 target and draft workloads - #8736

Open
xiangM99 wants to merge 4 commits into
ROCm:mainfrom
xiangM99:mla-head64-pin
Open

xiangM99 wants to merge 4 commits into
ROCm:mainfrom
xiangM99:mla-head64-pin

Conversation

@xiangM99

@xiangM99 xiangM99 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Optimize gfx1250 PS1 FP8 MLA decode for Kimi-K3 target and draft workloads, adding native multi-token QH64 execution and automatic QH96/q5 row packing.
This PR also picks the following prerequisite changes:

Motivation

existing K3 draft path pads 64 query heads to 96 for qlen=4, wasting compute on 32 zero heads. The QH96/q5 target path also processes query rows independently, causing repeated KV passes on large-batch, long-context workloads.

Changes

  • Support multi-token QH32/QH64 decode through tiled query-row planning.
  • Route non-CP FP8 QH64 qlen=1–8 to native precompiled code objects.
  • Add QH96/q5 row packing with an automatic profitability check.
  • Add a row-parallel reducer for supported wave32 decode shapes.
  • Add VGPR scheduling hints to reduce register pressure.

Performance (if applicable)

Measured on gfx1250 using the K3 grid:

  • Target: QH96, q1/q5, causal.
  • Draft: native QH64, q4, non-causal.
  • Batch: 8–128; context: 8K–128K.
  • Combined step: 24 × target(q5) + 5 × draft(q4).
Hardware Workload/configuration Before After Change
MI455X (gfx1250) K3 combined step, B64, 32K context 13.70 ms 12.21 ms 10.9% faster
MI455X (gfx1250) K3 combined step, B64, 64K context 26.67 ms 22.56 ms 15.4% faster
MI455X (gfx1250) K3 combined step, B64, 128K context 54.34 ms 44.98 ms 17.2% faster
MI455X (gfx1250) K3 combined step, B128, 64K context 55.85 ms 45.80 ms 18.0% faster
MI455X (gfx1250) K3 combined step, B128, 128K context 132.81 ms 104.14 ms 21.6% faster

Additional results:

  • Aggregate reduction across the 25-shape grid: 15.6%
  • QH96/q5 row packing: 5.5%–18.1% faster
  • Native QH64 draft: 3.3%–47.4% faster
  • B8/B16/B32 at 8K: 0.4%/0.2%/1.8% faster
  • Worst isolated small-shape QH96/q5 regression: 2.3%

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

PR Self-Review

Reviewed revision

Behavior and intent

Validation and unverified scope

PR-specific question

Changed op tests

@xiangM99
xiangM99 requested review from a team, coderfeli and shengnxu November 26, 2026 07:09
@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 8736 --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 [HIP][FlyDSL] Optimize gfx1250 PS1 FP8 MLA decode for Kimi-K3 target and draft workloads [ASM] [HIP] [FlyDSL] Optimize gfx1250 PS1 FP8 MLA decode for Kimi-K3 target and draft workloads Nov 26, 2026
@aiter-bot

aiter-bot commented Nov 26, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 40849b1dfbb5 · 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 — 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_flydsl.py
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_mla_shape_support.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.

gbyu-amd added a commit that referenced this pull request Nov 26, 2026
… VGPR pins (#8736 @ 13b071f, head 2026-11-26T06:02:59Z) (#8743)

Port of #8736's commits d9926d2 and 13b071f onto k3-455-dev; its
first commit (#8181 + #7913) is already here.

Conflicts:
- mla_pagesize1_fp8_fp8.py: #8736's file. It carries #7913 @ 51bb7c6
  (k3-455-dev had 067fee3), the only difference in that file.
- mla_reduce_kernels.cuh: k3-455-dev's file (keeps #7876 and #7914) plus
  #8736's row-parallel reducer and its dispatch, checked first as in #8736.

Co-authored-by: xiangM99 <[email protected]>
@zejunchen-zejun

Copy link
Copy Markdown
Contributor

@xiangM99 Thanks for this PR; its QH64 objects and q5 row packing are already in the k3-455-dev integration branch. We'd like to ask for help tuning one more combination: Kimi-K3 decode at concurrency 192 with DSpark k=7. That is our latency (interactivity) point, and MLA is now the largest part of its decode step.

The shapes (k=7 instead of this PR's k=4)

heads query rows mask covered by this PR?
target verify (24 MLA layers) QH96 8 causal no: q8 runs the generic path, one query row per work item (16mx6), 3 of 4 waves computing
DSpark draft block (5 MLA layers) QH64 7 non-causal the native QH64 path (planner cuts 7 rows into 4 tiles)
  • FP8 Q/KV, page size 1, kv_lora_rank 512 + rope 64. Decode runs DP8 with attention TP1, so each rank holds all heads.
  • Late in an agentic run, each rank decodes 16-24 requests at ~100-130K context.
  • There, MLA (24 target + 5 draft layers) is roughly 40% of the decode step (~22 of ~57 ms).

What we measured (gfx1250, op_tests/test_mla_flydsl.py harness, code objects unless noted)

1. q8 costs ~6.6x q1 at the same shape (QH96, causal):

batch / context q1 q4 q8
16 / 98K 94 µs 304 µs 571-617 µs
24 / 98K 134 µs 453 µs 895-990 µs
32 / 98K 168 µs 585 µs 1091-1197 µs
24 / 128K 1323 µs

2. q8 row packing pays at long context, not at 32K. Packed vs generic, both built with the public FlyDSL 0.5.3
toolchain:

batch 32K 48K 64K 98K 128K
16 +13% +3% -1% -5% -8%
24 +13% +6% +1% -8% -14%
32 +3% -3% -6% -8% -7%
  • We have a draft: branch zejun/k3-455-mla-q8, with (96, 7) and (96, 8) in ROW_PACKED_SHAPES and the C++ gate, plus
    8 code objects (16mx42 / 16mx48, causal x lse) and an exporter that reproduces the checked-in objects byte for
    byte.
  • But our exports use the public LLVM, which is ~13-15% slower than the toolchain that built this PR's objects
    (same generic kernel: b16/98K 571 µs as shipped vs 656 µs from the public build). That cancels the packing gain.
  • The planner gate (kMlaPs1PackMinBatches = 16, cost model tuned on q5) also rejects q8 at these shapes.

3. Where the time goes in generic q8:

  • Not LDS bandwidth. Measured 214-222 B/clk/CU. Cutting K or V LDS reads 4x in a JIT build makes it slower, not
    faster.
  • Not HBM re-reads of the same KV. Co-scheduling a request's 8 row items on one XCD for L2 reuse: <= 3% for QH96,
    7-15% for the QH64 draft.
  • Our estimate: per-pass efficiency. ~43% WMMA utilization, with 3 of 4 waves computing and softmax/LDS latency
    not fully hidden.

4. Draft, QH64 q7 non-causal: b16/98K 324 µs, b24/98K 490 µs (q1: 92 µs).

The ask

  1. Row packing for QH96 q7/q8 with objects built by your toolchain (feel free to take our branch), plus a
    context-aware pack decision: pack from ~64K mean context (~48K at 32+ requests), keep generic at 32K.
  2. The QH64 q7 non-causal draft path at b16-24, 64-130K.
  3. Beyond packing: per-pass efficiency for 7-8 query rows (QK/PV overlap, hiding softmax and LDS latency), if
    there is headroom.

Rough target: -20-30% MLA time at b16-24 x 96-128K. That would shorten the late-window decode step by ~8-12%.

Repro:

AITER_MLA_PS1_PACK_ROWS=0|1 python3 op_tests/test_mla_flydsl.py --mode ps1-asm --num-heads 96 --q-seq-len 8 \
  -b 16 24 32 -c 32768 65536 98304 131072
python3 op_tests/test_mla_flydsl.py --mode ps1 --num-heads 64 --q-seq-len 7 --causal 0 -b 16 24 -c 65536 98304 131072

We can share our timing-only harness and the full tables, and can run validation on our side. Thanks!

gbyu-amd added a commit that referenced this pull request Dec 3, 2026
… VGPR pins (#8736 @ 13b071f, head 2026-11-26T06:02:59Z) (#8743)

Port of #8736's commits d9926d2 and 13b071f onto k3-455-dev; its
first commit (#8181 + #7913) is already here.

Conflicts:
- mla_pagesize1_fp8_fp8.py: #8736's file. It carries #7913 @ 51bb7c6
  (k3-455-dev had 067fee3), the only difference in that file.
- mla_reduce_kernels.cuh: k3-455-dev's file (keeps #7876 and #7914) plus
  #8736's row-parallel reducer and its dispatch, checked first as in #8736.

Co-authored-by: xiangM99 <[email protected]>
(cherry picked from commit 5b18892)

This branch has not been deployed

No deployments
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.

4 participants