Skip to content

[HIP] [gfx1250] MLA reduce: run kn_mla_reduce_v1_wide on wave32 GPUs - #7914

Draft
gbyu-amd wants to merge 1 commit into
mainfrom
gyu/mla-reduce-wide-wave32
Draft

gbyu-amd wants to merge 1 commit into
mainfrom
gyu/mla-reduce-wide-wave32

Conversation

@gbyu-amd

Copy link
Copy Markdown
Contributor

Summary

kn_mla_reduce_v1_wide (#7570) is never selected on wave32 GPUs (gfx1250). This makes its traits and dispatch follow the device wave size, so on gfx1250 the few-tile, many-split decode/verify reduces it was written for take it, as they do on gfx950. On MI455X those reduces get up to 5.5x faster (1 tile x 250 splits, 16 heads: 76.2 → 13.7 us). The size bound is tightened for wave32, where kn_mla_reduce_v1 catches up sooner.

Motivation

MlaReduceWideTraits::kWaveSize is opus::get_warp_size(), which the host compiler pass evaluates to 64 whatever the target. mla_reduce_use_wide compares it with dev_prop.warpSize, 32 on gfx1250, so the check always fails there. Taking the kernel anyway would not work either: the launch takes its block size (kNumWarps * kWaveSize) and LDS size from the host's 64, while the device code is compiled for 32.

So on gfx1250, few tiles with many splits stay on kn_mla_reduce_v1, which walks the splits of each (tile, head) with one 2-wave workgroup: a batch-1 verify with 250 splits takes 76 us. The layout cases added with the wide kernel ("8 rows, max_seqlen_q 1/4") also run on kn_mla_reduce_v1 there and hit its LDS race (fixed separately in #7912).

Changes

All in csrc/include/mla_reduce_kernels.cuh:

  • MlaReduceWideTraits takes the wave size as a third template parameter, defaulting to opus::get_warp_size() (existing uses are unchanged).
  • kn_mla_reduce_v1_wide compiles its body (moved to mla_reduce_v1_wide_impl) only when the device wave size matches Traits::kWaveSize. Each target keeps one live instance; the other is an empty kernel.
  • dispatch_mla_reduce_v1 picks MlaReduceWideTraits<DV, H, 32> or <DV, H, 64> from the runtime warpSize, so the launch's block size, LDS size and routing check all use the device's wave size.
  • mla_reduce_use_wide: on wave32 the bound on num_reduce_tile x heads x max_seqlen_q is 4 units per CU instead of 16. On gfx1250, kn_mla_reduce_v1 is as fast or faster from about 8 units per CU (table below).

wave64 targets take the same instance and route the same shapes as before.

Performance (if applicable)

MI455X (gfx1250, 256 CUs), op_tests/test_mla_reduce.py (bf16, DV 512, one row per tile, uniform splits unless listed). "Units" = tiles x heads x rows, the routing's size measure.

Forced on (AITER_MLA_REDUCE_WIDE=1) vs kn_mla_reduce_v1 (=0), which sets the wave32 bound:

Hardware Workload/configuration units kn_mla_reduce_v1 wide Change
MI455X 16 heads, 1 tile x 250 splits 16 76.2 us 13.7 us -82%
MI455X 16 heads, 1 tile x 64 splits 16 21.3 us 6.5 us -69%
MI455X 16 heads, 8 tiles x 64 splits 128 25.0 us 9.3 us -63%
MI455X 16 heads, 16 tiles x 32 splits 256 14.2 us 6.7 us -52%
MI455X 16 heads, 64 tiles x 8 / 16 splits 1024 7.6 / 10.6 us 6.6 / 10.7 us -13% / +2%
MI455X 16 heads, 128 tiles x 8 / 16 splits 2048 8.3 / 15.4 us 9.8 / 22.3 us +18% / +45%
MI455X 16 heads, 256 tiles x 8 splits 4096 11.6 us 15.9 us +37%
MI455X 128 heads, 1 tile x 250 splits 128 79.0 us 14.9 us -81%
MI455X 128 heads, 8 tiles x 8 / 16 / 64 splits 1024 7.4 / 10.4 / 31.3 us 6.0 / 10.7 / 28.8 us -19% / +3% / -8%
MI455X 128 heads, 16 tiles x 8 / 16 / 32 splits 2048 9.2 / 13.9 / 23.0 us 8.8 / 17.3 / 32.5 us -5% / +25% / +41%
MI455X 128 heads, 32 tiles x 8 / 16 / 32 splits 4096 11.3 / 19.3 / 37.5 us 13.9 / 35.5 / 66.7 us +23% / +84% / +78%

With main's 16 units per CU (4096 here), the shapes in the last rows would take the wide kernel and run slower than today. With 4 per CU they keep kn_mla_reduce_v1.

Default routing after this change vs kn_mla_reduce_v1, grid from the same test:

Hardware Workload/configuration units Before (kn_mla_reduce_v1) After Change
MI455X 16 heads, 2 tiles x 8 splits 32 5.9 us 4.5 us -24%
MI455X 16 heads, 8 tiles x 8 / 16 splits 128 6.4 / 9.0 us 4.8 / 5.8 us -24% / -36%
MI455X 16 heads, 16 tiles x 32 splits 256 16.2 us 7.9 us -51%
MI455X 16 heads, 32 tiles x 8 splits 512 7.2 us 5.3 us -26%
MI455X 16 heads, 64 tiles x 16 splits 1024 13.3 us 13.3 us 0%
MI455X 96 heads, 2 tiles x 8 splits 192 6.4 us 4.9 us -24%
MI455X 96 heads, 8 tiles x 8 / 16 splits 768 7.3 / 10.1 us 5.5 / 9.8 us -25% / -2%
MI455X 128 heads, 2 tiles x 8 splits 256 6.5 us 5.0 us -23%
MI455X 128 heads, 8 tiles x 8 / 16 splits 1024 7.5 / 10.3 us 5.9 / 10.5 us -22% / +2%

The rest of the grid keeps kn_mla_reduce_v1 and is within ±3%. That covers fewer than 8 splits per tile (1x2, 4x4, 32x2, 64x4, 256x2, 512x2) and more than 4 units per CU: 16 heads 128x8 / 256x16; 96 and 128 heads 16x32, 32x8, 64x16, 128x8, 256x16.

Testing

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

On MI455X (gfx1250), aiter main at 111fbd8 plus this change, module_mla_reduce built for gfx950 + gfx1250:

Documentation

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

Routing only; the kernel and AITER_MLA_REDUCE_WIDE behave as documented in the code.

Dependencies

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

Breaking Changes

None. wave64 behaviour is unchanged. On wave32 the kernel gives the same results as on wave64 (the existing correctness tests, above).

cc @yuychang (#7570)

@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 7914 --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.

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]>
gbyu-amd added a commit that referenced this pull request Dec 3, 2026
… head 2026-11-13T04:18:42Z)

Applied as the diff 111fbd8..674cce0 (1 files) onto the rebased 1116 tree; PR state: draft, author gbyu-amd, base main.

(cherry picked from commit 5dd26d3)
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant