Skip to content

[HIP] [Perf] Wave-per-head MLA reduce for wave32 (gfx1250) decode with few splits per tile - #7876

Open
gbyu-amd wants to merge 5 commits into
mainfrom
gyu/mla-reduce-wave-head-gfx1250
Open

gbyu-amd wants to merge 5 commits into
mainfrom
gyu/mla-reduce-wave-head-gfx1250

Conversation

@gbyu-amd

@gbyu-amd gbyu-amd commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds kn_mla_reduce_v1_wave_head, an MLA split-KV reduce for wave32 GPUs (gfx1250) with 512-wide heads, for decode and verify steps whose reduce tiles carry few splits each. On MI455X:

  • the reduce of a 96-head MLA decode with a split KV gets 1.14–2.8x faster (e.g. 12.5 → 5.1 µs for 160 tiles x 2 splits), and the whole decode call up to 27% faster;
  • the reduce of a 64-head, 4-token draft-block decode, whose tiles hold 2 query rows each, gets 18–50% faster at batch 16–64 and 1–14% at batch 8.

The host picks it only on wave32 when there is enough parallelism; everything else keeps kn_mla_reduce_v1, and AITER_MLA_REDUCE_WAVE_HEAD=0 turns it off.

The fourth commit adds kn_mla_reduce_v1_adaptive for batches with very different context lengths, where one long request's tiles carry 15–60 splits and the wave-head kernel walks them in one wave. Helper workgroups share those splits; on MI455X the reduce of such a batch gets 1.3–2.9x faster (e.g. 32.5 → 11.4 µs for a tile with 47 splits), and 18–22 µs draft-block reduces drop to ~10 µs. Tables of more than 64 sequences are unchanged.

Motivation

On gfx1250, kn_mla_reduce_v1[_ps] gives each (tile, head) one 2-wave workgroup, stages the split map in LDS behind __syncthreads, and walks the splits one after another (2 KB per split per workgroup). Little data is in flight, so the reduce is latency-bound. On MI455X it moves 5–12 TB/s and takes about as long as on MI355X, despite MI455X's much higher HBM bandwidth.

For MLA decode with 96 heads (DSV3-style MLA, TP8 + DCP8, 4-draft-token verify), the planner's auto split gives 40–192 reduce tiles of 2–7 splits each. At short contexts the reduce was up to 47% of the MLA call.

kn_mla_reduce_v1_wide (#7570) targets the opposite shape (few tiles, at least 8 splits each, heads x rows <= 128). On gfx1250 it is currently never selected (mla_reduce_use_wide compares dev_prop.warpSize with a kWaveSize that is 64 in the host pass); #7914 fixes that separately. The two do not compete: the wide check runs first, the 96-head shapes below have 96 heads x 5 rows or fewer than 8 splits, and the 64-head draft-block tables are far past the wide kernel's wave32 size bound in #7914.

Changes

  • kn_mla_reduce_v1_wave_head (csrc/include/mla_reduce_kernels.cuh). One wave owns kHeadsPerWave adjacent heads of one row of a tile; their partial rows are adjacent in memory.
    • Lane l reads float4 number c * 32 + l of each head's 512-float row, so every load instruction covers 512 contiguous bytes. The first version gave each lane 16 contiguous floats; one instruction then touched 16 cache lines, a quarter of each, and was 10–30% slower.
    • Lane i holds split i's slot and LSE. The weights come from a wave max/sum.
    • Each wave keeps a ring of kInFlight split loads in flight. The first kInFlight splits' rows are requested before the weights are known, and split i + kInFlight as soon as split i is accumulated.
    • No LDS, no barrier: the waves of a workgroup are independent.
    • The body is compiled out for wave64 targets; it is never launched there.
  • Two instances.
    • One-row tiles (more than 64 heads, or max_seqlen_q == 1): 2 heads per wave, 2 splits in flight, one workgroup row per table entry. 4 in flight was up to 1 µs better at batch 8–16 of a 96-head decode, but as much worse at batch 32–64.
    • Multi-row tiles (the decode planner cuts a multi-token query of up to 64 heads into tiles of ceil(q / ceil(heads * q / 128)) rows, e.g. 64 heads x 4 tokens → two 2-row tiles):
      • grid.y spreads a tile's rows over that many row parts (at most 4), and 1 head per wave with 4 splits in flight keeps more loads going per CU.
      • These tiles come few, with many splits each. Walking rows and splits back to back in one wave made the first version slower than kn_mla_reduce_v1 here.
      • At most 256 tiles go along grid.x; workgroups walk the rest and stop at the first tile that starts at the table's end (reduce_indptr does not decrease). Launching every entry of an empty, graph-batch-sized table cost 7–10 µs more than kn_mla_reduce_v1 (8.4–12.6 against 1.2–2.4 µs).
    • A tile with more rows than the row parts is still covered: part p walks rows p, p + parts, …
  • Host routing (mla_reduce_use_wave_head), after the wide-kernel check, for kSizeDV == 512 only. Requires all of:
    • warpSize == 32
    • 1 <= max_seqlen_q <= 16
    • 1 <= num_kv_splits <= 32. Past 32 splits a wave would walk them one at a time; that path is kept for correctness, but not selected.
    • num_reduce_tile * waves_per_tile * row_parts >= 6 * num_cu. Below that, each wave has too much serial work and kn_mla_reduce_v1 is as fast or faster (grids below).
  • Environment switch. AITER_MLA_REDUCE_WAVE_HEAD=0 keeps kn_mla_reduce_v1; =1 drops the parallelism condition.
  • Semantics match kn_mla_reduce_v1.
    • Without a final map, a 1-split tile has no rows.
    • A single -1 split (v1_0 tile) is skipped.
    • A row whose splits all have zero weight comes out as 0 with LSE +inf.
  • op_tests/test_mla_reduce.py: 6 LAYOUT_CASES with few splits per tile (≤ 9).
    • 4 one-row-instance cases: no final map, a -1 tile, a padded reduce_indptr tail, and tiles with more rows than max_seqlen_q.
    • 2 multi-row-instance cases (64 heads, 2-row tiles, max_seqlen_q 4): 64 tiles, and 300 tiles plus a 40-entry empty tail, which goes past the 256-tile grid.
    • The existing layout cases all have 40+ splits per tile, so they never reach this kernel.
  • Adaptive reduce for skewed batches: kn_mla_reduce_v1_adaptive (fourth commit).
    • The decode planner hands out its split budget by KV length. A batch that mixes very different context lengths (e.g. one 190k-token request among 2k–40k ones) gives the long request's tiles 15–60 splits and the others 2–6. kn_mla_reduce_v1_wave_head has one wave walk every split of its heads, so the most-split tile sets the kernel time (about 3.2 µs + 0.59 µs a split), and past 32 splits it walks them one at a time.
    • One launch, two kinds of 4-wave workgroups. Helpers come first in the grid: each stages the live part of reduce_indptr in LDS, prefix-sums the work of the long tiles (more than 12 splits) and takes a contiguous block of it. A long tile's head gets 2 waves up to 24 splits, 4 above; their partial sums are added in LDS. More than 32 splits are walked 32 at a time. The short tiles keep the wave-head walk. There is no cross-workgroup synchronization (a merge through device-scope atomics / fences was measured: it writes back and invalidates L2 that holds the stage-1 partials and was slower).
    • Routing: taken where kn_mla_reduce_v1_wave_head would be, with a final map (persistent decode metadata), for tables of at most 64 sequences (4 helpers a CU up to 32 sequences, 2 up to 64). Larger tables keep kn_mla_reduce_v1_wave_head: their tiles carry 2–5 splits, so there is nothing to share, and the adaptive kernel's wave-head grid compiles to more VGPRs.
    • Environment: AITER_MLA_REDUCE_ADAPTIVE=0 keeps kn_mla_reduce_v1_wave_head everywhere, =1 also takes the larger tables; AITER_MLA_REDUCE_ADAPTIVE_HELPERS=<n> sets the helper workgroups, AITER_MLA_REDUCE_ADAPTIVE_SPLITS=<s1>,<s2> the short / mid split counts (default 12,24, measured on gfx1250 over decode batches of 8–128 sequences). AITER_MLA_REDUCE_WAVE_HEAD=0 still keeps kn_mla_reduce_v1 for everything.
    • op_tests/test_mla_reduce_adaptive.py checks every live tile (output and LSE) against a torch reference: synthetic tables with 1–100 splits per tile (chunked past 32), 1 / 2 / 4-row tiles, 16–128 heads, padded table tails, LSE on / off; and planner tables (get_mla_metadata_v1, persistent fast mode, page 1) for verify (96 heads, 5 rows, causal, round-robin context parallel) and draft blocks (96 / 64 heads, 4 rows, non-causal), skewed and uniform. The 64-head draft-block planner cases need the 32/64-head multi-token decode route ([HIP] [FlyDSL] [gfx1250] MLA PS1: take 32/64-head multi-token decode as several qo tiles #7913) and are skipped without it.

Performance (if applicable)

Reduce kernel only (measured with the first commit, one-row instance with 1 split in flight; the current 2-in-flight one-row instance is equal or up to 1 µs faster on these shapes), one MI455X (gfx1250, 256 CUs), L2/MALL flushed before every call, torch profiler kernel time. The inputs are the real partials of mla_decode_fwd, captured right before the reduce: 96 heads x 512, fp8 MLA decode with persistent page-1 metadata as ATOM builds it (max_split_per_batch=-1), a 4-draft-token verify (5 query rows) for batch 8–128 and a 1-token decode for batch 384. Context is per DCP rank (DCP 8).

Hardware Workload/configuration Before After Change
MI455X batch 8 verify, 512 tokens/rank (40 tiles x 4 splits) 4.1 us 3.5 us -15%
MI455X batch 8 verify, 8k tokens/rank (40 tiles x 7 splits) 4.8 us 4.2 us -13%
MI455X batch 16 verify, 512 / 8k tokens/rank (80 tiles x 3–4 splits) 7.8 / 7.9 us 3.9 / 4.5 us -50% / -43%
MI455X batch 32 verify, 512 / 8k tokens/rank (160 tiles x 2–3 splits) 12.5 / 14.4 us 5.1 / 5.4 us -59% / -63%
MI455X batch 64 verify, 512 / 8k tokens/rank (160–192 tiles x 2 splits) 16.2 / 17.4 us 7.6 / 6.2 us -53% / -64%
MI455X batch 128 verify, 512 tokens/rank (128 live tiles x 2 splits) 12.8 us 4.7 us -63%
MI455X batch 384 decode, 512 tokens/rank (128 live tiles x 2 splits) 13.0 us 4.7 us -64%

Whole mla_decode_fwd call (stage 1 + reduce), CUDA graph replay, caches flushed, median of 100, with this PR's final revision against AITER_MLA_REDUCE_WAVE_HEAD=0 on the same GPU. Context lengths are per request before DCP. The sweep covers 4k–256k and 8 batch points. The new kernel is faster in 39 of 56 cells. The others are the batch 256/512 rows, whose reduce tables are empty (last row, re-measured after the final change), and three long-context cells within 1%. Selected rows:

Hardware Workload/configuration Before After Change
MI455X batch 8 verify, 4k ctx 23.6 us 23.1 us -2%
MI455X batch 16 verify, 4k ctx 31.1 us 25.9 us -17%
MI455X batch 32 verify, 4k / 16k ctx 43.1 / 58.9 us 31.3 / 45.5 us -27% / -23%
MI455X batch 64 verify, 8k ctx 64.2 us 48.1 us -25%
MI455X batch 128 verify, 4k ctx 62.9 us 52.8 us -16%
MI455X batch 384 decode, 4k ctx 57.3 us 45.1 us -21%
MI455X batch 256 / 512 decode, 4k ctx (reduce table all empty), two runs each 18.9–19.1 / 31.3–31.6 us 19.5–19.7 / 32.0–32.3 us +0.4–1.0 us

The last row is a known cost. At batch 256/512 the planner leaves no tile to reduce, but the CUDA-graph-sized table still has 256/512 entries. The one-row instance launches a workgroup per entry and head group, and every one exits after two scalar loads. A grid-stride variant that launched fewer workgroups made the busy shapes slower (3.4 → 5.0 µs at batch 8), so the one-row instance keeps one workgroup per entry. The multi-row instance, whose waves per entry are 4x as many, caps the grid instead (Changes).

Synthetic grid from op_tests/test_mla_reduce.py (bf16, uniform splits, one row per tile), forced on (=1) vs kn_mla_reduce_v1 (=0). It sets the routing threshold, waves = tiles x heads / 2 against 6 x 256 CUs = 1536:

waves shapes (tiles x splits, heads) old / new
128–1152 16x32 / 24x4 / 32x2 / 32x8 / 40x4 / 40x7 / 48x2 / 64x4 / 128x8 at 16 heads; 16x32 / 24x4 at 96 heads; 16x32 at 128 heads 0.66–0.97 (old kernel faster; routed to it)
1536–2048 32x2 / 32x8 at 96 heads; 24x4 / 32x2 / 32x8 at 128 heads; 256x2 / 256x16 at 16 heads 0.96–1.34 (32x8 at 96/128 heads: 0.97 / 0.96)
1920–16384 40x4 / 40x7 / 48x2 / 64x4 / 128x8 / 256x2 / 256x16 at 96 and 128 heads 1.03–2.61

Multi-row tiles on real decode metadata: 64 heads, a 4-token non-causal draft block (two 2-row tiles per request), fp8, page-1 persistent metadata as ATOM builds it; reduce kernel time, kn_mla_reduce_v1 (=0) → this PR (default routing):

Hardware Workload/configuration Before After Change
MI455X batch 8, 512 / 8192 / 32768 KV tokens per rank (16 live tiles) 7.7 / 13.3 / 16.1 us 6.6 / 12.7 / 16.0 us -14% / -5% / -1%
MI455X batch 16, same (32 live tiles) 10.0 / 13.1 / 13.9 us 7.5 / 10.3 / 11.4 us -25% / -21% / -18%
MI455X batch 32, same (64 live tiles) 11.8 / 13.6 / 13.9 us 7.8 / 10.8 / 11.2 us -34% / -21% / -19%
MI455X batch 64, same (128 live tiles) 19.7 / 19.6 / 23.0 us 9.9 / 10.6 / 11.7 us -50% / -46% / -49%
MI455X batch 128, same (no tile to reduce) 1.3 / 2.0 / 2.4 us 2.5 / 3.3 / 4.3 us +1.2–1.9 us

The batch-128 row is the empty-table cost of the capped multi-row grid: workgroups for the first 256 entries still launch and exit. Whole calls there are 22.6 → 24.4, 148.7 → 149.1 and 567.2 → 571.7 µs.

Synthetic grid from op_tests/test_mla_reduce.py's builder (bf16, uniform splits, the table holds only live tiles), forced on (=1) vs kn_mla_reduce_v1 (=0):

  • 60 multi-row shapes: 16 / 32 heads x 4-row tiles and 64 heads x 2-row tiles, 16–256 tiles x 4–32 splits. New / old ranges from 0.56 to 1.18.
  • The 4 slower shapes:
    • 16 tiles with 16–32 splits at 16 heads (1.18): below the wave threshold (1024 waves), so they keep kn_mla_reduce_v1;
    • 16 tiles x 8 splits at 32 heads (1.04) and 32 tiles x 16 splits at 16 heads (1.05): both 2048 waves, so the default routing takes them.
shape kn_mla_reduce_v1 new
64 heads x 2 rows, 16 tiles x 8 splits 11.1 us 10.7 us
64 heads x 2 rows, 64 tiles x 16 splits 37.1 us 23.2 us
64 heads x 2 rows, 256 tiles x 32 splits 225.0 us 136.1 us
32 heads x 4 rows, 64 tiles x 16 splits 37.1 us 23.4 us
32 heads x 4 rows, 256 tiles x 8 splits 70.1 us 41.6 us
16 heads x 4 rows, 128 tiles x 8 splits 19.9 us 13.8 us
16 heads x 4 rows, 256 tiles x 16 splits 55.8 us 41.1 us

kn_mla_reduce_v1 also has an LDS race on such tiles once a workgroup reduces more than one row on its massive path (fix: #7912): in the =0 runs of this grid on main many multi-row shapes give wrong output. The new kernel uses no LDS and matches the torch reference on all 60.
Fourth commit (adaptive reduce). Reduce kernel only, main 03f9f37 + this PR, one MI455X: real planner tables (get_mla_metadata_v1, fp8, page 1, persistent fast mode, 8-way round-robin context parallel, the shard of one rank), tables sized for the batch's graph size; each CUDA-graph replay first rewrites the live partials (as stage 1 leaves them, warm in L2/MALL), kernel time from the profiler; every live tile checked against torch. 96 heads; verify = 5 rows causal, draft = 4-row non-causal block. Columns: this commit (default), AITER_MLA_REDUCE_ADAPTIVE=0 (wave-head, the first three commits), AITER_MLA_REDUCE_WAVE_HEAD=0 (kn_mla_reduce_v1).

Hardware Workload/configuration adaptive wave-head kn_mla_reduce_v1
MI455X verify, 12 batches of 5–7 requests, 2k–190k contexts (most-split tile 12–22), table 32 10.2 us (9.6–11.1) 13.0 us (10.5–15.9) 10.7 us (9.7–12.1)
MI455X verify, 190k + 40k/35k/30k/25k/10k (most-split tile 30), table 32 9.7 us 20.4 us 14.1 us
MI455X verify, 190k + 4 x 2k (most-split tile 47), table 32 11.4 us 32.5 us 18.4 us
MI455X draft block, 6 batches of 5–7 requests (most-split tile 14–22), table 32 9.8 us (9.3–10.2) 18.5 us (15.6–21.8) 10.6 us (9.9–11.3)
MI455X verify, batch 24 / 32 (table 64) 9.8 / 9.9 us 9.8 / 9.7 us 18.3 / 21.0 us
MI455X verify, batch 48 / 64 (table 64) 11.0 / 11.3 us 10.9 / 11.3 us 27.7 / 31.4 us
MI455X draft block, batch 32 (table 64) 9.7 us 11.3 us 17.9 us
MI455X verify / draft block, batch 96–128 (table 128: wave-head kernel) 12.2 / 11.8 us 12.2–12.3 / 11.9 us 33.9–34.9 / 34.5 us
MI455X verify, batch 8 / 16 at uniform 32k or 128k (4–8 splits, table 32) 8.5–9.7 us 7.4–8.6 us 8.8–13.2 us

The last row is the known cost: when every tile is short, the helpers find no work, and the adaptive kernel's wave-head grid compiles to more VGPRs (lower occupancy) than kn_mla_reduce_v1_wave_head: +1.1–1.2 µs at batch 8–16 with uniform contexts. Forcing the occupancy back made it spill and run 3–13 µs slower. Real mixed-length batches always have long tiles and are faster.

Testing

  • Unit tests added or updated (6 few-split LAYOUT_CASES)
  • Performance benchmarks run (above)
  • Tested on MI250X
  • Tested on MI300X

MI250X/MI300X/MI355X are wave64. There the routing never selects the new kernel and the kernel body is compiled out. module_mla_reduce was built for gfx950 + gfx1250 but not run on gfx9.

Documentation

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

The kernel is selected automatically. AITER_MLA_REDUCE_WAVE_HEAD is documented next to the routing code, as AITER_MLA_REDUCE_WIDE is.

Dependencies

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

Breaking Changes

None. Output agrees with kn_mla_reduce_v1 to bf16 rounding (max |Δout| 2e-3, max |Δlse| 1e-6 on every row of the real inputs above). The all-zero-weight convention (0 / +inf) is the same.

PR Self-Review

Reviewed revision

deb5b6c (on main 03f9f37). Four commits: the kernel (identical to the earlier 978c4b4); a single-row condition; row parts, a ring of split loads, and the multi-row instance, which replace that condition; then the adaptive reduce for skewed batches. The first three are c53d322 rebased onto main 03f9f37 without conflicts (mla_reduce_kernels.cuh and test_mla_reduce.py are unchanged on main since #7570).

Behavior and intent

On wave32 GPUs with 512-wide heads, decode/verify reduces with enough (tile, row, head) parallelism and ≤ 32 splits per tile now run kn_mla_reduce_v1_wave_head instead of kn_mla_reduce_v1. The old kernel is latency-bound there (see Motivation). The new one coalesces its loads, keeps 2–4 split loads in flight per wave, and spreads multi-row tiles over row parts. wave64 behaviour is unchanged.

Validation and unverified scope

Fourth commit, on MI455X (gfx1250), aiter main 03f9f37 plus the four commits; module_mla_reduce built for gfx950 + gfx1250:

First three commits, as before: aiter main at 111fbd8 plus this change (the first commit was also run on e9efac0); module_mla_reduce built for gfx950 + gfx1250:

PR-specific question

To be answered after the automated PR Self-Review comment.

Changed op tests

op_tests/test_mla_reduce_adaptive.py (new, fourth commit): see Changes. It runs aiter.mla_reduce_v1 with the routing the process environment selects, so on wave64 it checks kn_mla_reduce_v1.

op_tests/test_mla_reduce.py: 6 LAYOUT_CASES with ≤ 9 splits per tile, DV 512. The existing layout cases (40–250 splits per tile) never reach the new kernel; these cover its layout handling. On wave64 they run kn_mla_reduce_v1 and pass as before.

  • 4 for the one-row instance (96 and 16 heads): no final map, a -1 tile, a padded reduce_indptr tail, and tiles with more rows than max_seqlen_q.
  • 2 for the multi-row instance (64 heads, 2-row tiles, max_seqlen_q 4): 64 tiles, and 300 tiles plus a 40-entry empty tail past the 256-tile grid (the tile walk and its stop at the table's end).

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

…h few splits per tile

(cherry picked from commit 81995fc)
@gbyu-amd
gbyu-amd force-pushed the gyu/mla-reduce-wave-head-gfx1250 branch from 978c4b4 to 81995fc Compare November 13, 2026 03:52
The decode planner cuts a multi-token query of up to 64 heads into tiles of several rows. In decode those come few, with many splits each, while num_reduce_tile (the table size) is several times the live tile count, so the wave count check passes anyway; one wave walking rows and splits back to back is then slower than kn_mla_reduce_v1 (64 heads x 4-token draft block, batch 8/32: 10.3-20.3 vs 7.5-13.9 us). Take the new kernel for single-row tiles only: more than 64 heads, or max_seqlen_q 1.

(cherry picked from commit 5cc0d00)
Multi-row tiles (the decode planner cuts a multi-token query of up to 64 heads
into tiles of 2-4 rows) now take the wave-per-head kernel too, replacing the
single-row condition of the previous commit:

- grid.y spreads a tile's rows over row parts (the planner's rows per tile,
  at most 4), so each wave owns one (tile, row, head group);
- each wave keeps a ring of split loads in flight: split i + kInFlight is
  requested as soon as split i is accumulated, and the first kInFlight
  splits' rows before the weights are reduced;
- two instances: one-row tiles keep 2 heads per wave with 2 splits in
  flight; multi-row tiles take 1 head per wave with 4 splits in flight and
  at most 256 tiles along grid.x, the workgroups walking the rest and
  stopping at the table's end (an empty graph-batch-sized table otherwise
  launched 7-10 us of empty waves);
- the wave-count check counts row parts.

On a 64-head, 4-token draft-block decode (MI455X) the reduce of its 2-row
tiles drops 12-50% against kn_mla_reduce_v1 (batch 16-64) and up to 14% at
batch 8. op_tests/test_mla_reduce.py gains two 2-row layout cases (64 heads),
one past the 256-tile grid with an empty padded tail.

(cherry picked from commit c53d322)
A decode batch that mixes very different context lengths gets most of the
planner's split budget on its longest request: that request's tiles carry
15-60 splits while the others carry 2-6. kn_mla_reduce_v1_wave_head has one
wave walk every split of its heads, so the most-split tile sets the kernel
time (about 3.2 us + 0.59 us a split on gfx1250), and above 32 splits it
falls back to one split at a time.

kn_mla_reduce_v1_adaptive keeps the wave-head walk for tiles with few splits
and adds helper workgroups, first in the grid. Each helper stages the live
part of reduce_indptr in LDS, prefix-sums the work of the long tiles (more
than 12 splits) and takes a contiguous block of it: 2 waves a head up to 24
splits, 4 above, partial sums added in LDS; more than 32 splits are walked
32 at a time. There is no cross-workgroup synchronization.

It is taken where kn_mla_reduce_v1_wave_head would be, with a final map, for
tables of at most 64 sequences (4 helpers a CU up to 32 sequences, 2 up to
64); larger tables keep kn_mla_reduce_v1_wave_head, whose tiles carry 2-5
splits there. AITER_MLA_REDUCE_ADAPTIVE=0 keeps the wave-head kernel, =1
also takes larger tables; AITER_MLA_REDUCE_ADAPTIVE_HELPERS and
AITER_MLA_REDUCE_ADAPTIVE_SPLITS override the helper count and the 12 / 24
split thresholds.

op_tests/test_mla_reduce_adaptive.py checks every live tile (output and LSE)
against a torch reference on synthetic tables (1-100 splits, 1 / 2 / 4-row
tiles, 16-128 heads, padded tails) and on planner tables for verify and
draft-block shapes.
@gbyu-amd
gbyu-amd force-pushed the gyu/mla-reduce-wave-head-gfx1250 branch from c53d322 to deb5b6c Compare November 17, 2026 09:08
@gbyu-amd
gbyu-amd marked this pull request as ready for review November 19, 2026 02:23
@gbyu-amd
gbyu-amd requested a review from a team November 19, 2026 02:23
@github-actions github-actions Bot added the HIP label Nov 19, 2026
@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision f3d8ffe42f2a · 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 — PR-specific question is too short to show concrete reasoning (9 units; need 14)

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
gbyu-amd requested a review from yuychang November 19, 2026 02:27
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
…per tile (#7876 @ f3d8ffe, head 2026-11-19T02:23:24Z)

Applied as the diff 99211b6..f3d8ffe (3 files) onto the rebased 1116 tree; PR state: open, author gbyu-amd, base main.

(cherry picked from commit 1b04472)
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants