Skip to content

perf(fused): MoE stage1 gemm tile-loop changes behind --tile-opt (driven by mori-harness) - #1069

Draft
kawhil-amd wants to merge 1 commit into
ROCm:mainfrom
kawhil-amd:perf/stage1-gemm1-tile-loop
Draft

kawhil-amd wants to merge 1 commit into
ROCm:mainfrom
kawhil-amd:perf/stage1-gemm1-tile-loop

Conversation

@kawhil-amd

Copy link
Copy Markdown
Contributor

Summary

Example 13 (mega-MoE stage1: SDMA dispatch + gated GEMM1) gets a new opt-in switch, --tile-opt (with --ready-first). It changes only the GEMM1 tile loop. The output is unchanged: every checked call equals aiter after stage2.

V4.1-Flash EP8 end to end, measured in one process (upstream ready-first vs --tile-opt, 20 interleaved graph rounds): -3.9% at bs 512, -10.7% at 1024, -13.2% at 2048, -12.3% at 4096 and -12.3% at 8192. --tile-opt was faster in 20/20 rounds at every batch size.

The changes were found with the mori-harness self-driven optimisation loop. A loop-nest performance model of the kernel (the kernel-roofline-model skill) finds the critical path, ranks the levers and registers a prediction before each run. It prices each cost by removing that cost alone (a probe build). The cco-fusion agent builds each change, reads the ISA, and A/B-tests the change on the GPU. The loop stopped when the model reported that the MFMA pipe binds. At that point the bandwidth ceilings (B from L2, A from LDS) were measured below the MFMA time, and the remaining items were structural (2 waves per SIMD), numerics changes, or under 2%.

Changes

All the changes are in examples/cco/python/13_flydsl_mega_moe_stage1_sdma/. With --tile-opt off, the kernel is the same as before. Each change is a keyword of compile_gemm1_sdma; --tile-opt turns on the set that pays at the shape's sort_block_m.

switch what it does sbm 64 sbm 128
hoist_prologue The next tile's ready-queue read, rowmap words, A k-step 0 and A scales are issued inside the current tile (K-loop start and the two epilogue halves). The next tile then starts with one LDS barrier. on on
kpipe=1 The next A k-step goes global -> registers -> ds_write, not buffer_load ... lds. LLVM's waitcnt pass made each step's first A ds_read wait for the outstanding LDS DMA, because it cannot prove the two A buffers disjoint. on on
a_dbuf=1 The A operand is double-buffered in registers: group g+1's ds_read pair is issued before group g's MFMAs, fenced with sched_barrier. on on
xcd_order, xcd_steal=2 XCD-affine tile order. The scheduler also fills 8 per-XCD work lists, so expert slice (e, n) always runs on one XCD and its weights live in one L2. At the end, a workgroup steals from the fullest list in one round trip. on on
fin_off The final k-step's A buffer parity is made opaque to LLVM. Otherwise LLVM folds it into 32 constant addresses, hoists them out of the persistent tile loop and spills them at sbm 128, so every tile reloads them from scratch. aiter's do_tile has the same spill. on on
kunroll=2 The K-loop body is two k-steps with two B register sets that alternate, so there is no loop-carried B copy and no vmcnt(0) at the loop head. on -
sa_pack The epilogue writes the next tile's A scales to LDS packed, one 16-byte record per (k-step, lane). Each k-step then reads its A scales with 1 ds_read_b128, not 16 ds_read_u8 with 8 serial lgkmcnt(0). - on
epi_remat=1 The lane constants of the sa-pack writer and the store pass are recomputed per tile, not hoisted, spilled and reloaded behind vmcnt waits. - on

New file tile_hoist.py: aiter's GEMM1 do_tile (aiter 849f711d3) cut into prologue / tile_main / epilogue. The MFMAs, their order and the arithmetic are unchanged. sdma_dispatch.py: the scheduler wave optionally appends published work items to the 8 XCD lists. run_stage1.py: --tile-opt.

How each change was found (model vs agent):

  • hoist: the model's hoist rewrite of the loop-carried tile edge.
  • kpipe: the model pointed at the K-loop memory exposure; the agent's ISA reading found the LDS-DMA alias wait.
  • xcd: the model ranked by marginal price, and B L2 misses were the largest single price.
  • fin-off / epi-remat: register-spill findings from the ISA, after the model's pricing showed sbm 128 far from its roofline.
  • sa-pack: the nosa probe priced the A-scale chain at 6.9 us/tile at sbm 128. This falsified the model's earlier assumption that single K-loop overheads are hidden.

Results

8x MI355X, V4.1-Flash, EP8, --network flash --ready-first --stress 3, same process: upstream vs --tile-opt, 20 interleaved rounds x 30 CUDA-graph replays, median.

tokens/rank sbm upstream --tile-opt change faster
512 64 0.2541 ms 0.2452 ms -10.0 us (-3.9%) 20/20
1024 64 0.3407 0.3037 -36.5 us (-10.7%) 20/20
2048 64 0.4761 0.4137 -63.0 us (-13.2%) 20/20
4096 128 0.7757 0.6797 -95.4 us (-12.3%) 20/20
8192 128 1.3561 1.1908 -167.2 us (-12.3%) 20/20

Where the gain comes from at bs 4096, from incremental end-to-end A/Bs: fin-off ~61%, sa-pack ~21% (-19.8 us), a-dbuf ~8%, epi-remat ~8%, the sbm-64-era switches ~2%. At bs 2048, hoist + kpipe + xcd-order + xcd-steal alone give -47.5 us (-9.9%).

Correctness

  • Every poisoned graph call (--stress 3) equals aiter's output after stage2, on all 8 ranks, for both arms at every batch size above. The stage1 bytes themselves are not a gate: the layout is in arrival order, and the padding rows differ between runs of the upstream kernel too.
  • This branch is the measured dev branch with the probe builds and experiment variants removed. The gated GEMM1 ISA of the cleaned branch (--tile-opt) is identical to the measured build at bs 2048 (sbm 64) and bs 4096 (sbm 128), all 8 rank kernels (kernel names aside), and both pass --stress 3.

Test plan

  • run_stage1.py --network flash --ready-first --tile-opt --stress 3 at bs 2048 (sbm 64) and 4096 (sbm 128): all calls == aiter after stage2
  • Same-process A/B (upstream vs the kept switches) at bs 512..8192, 20 rounds each
  • V4-Pro shapes (not measured with these switches)
  • ruff / black

🤖 Generated with Claude Code

… (driven by mori-harness)

The gated ready-first GEMM1 of example 13 gets an opt-in set of tile-loop changes, same results
(every checked call == aiter after stage2):

- hoist_prologue: the next tile's ready-queue read, rowmap words, A k-step 0 and A scales are issued
  inside the current tile (tile_hoist.py: aiter's do_tile cut into phases, same MFMA order)
- kpipe 1 / a_dbuf 1: A k-step through registers (no LDS-DMA alias wait), A operand double-buffered
- xcd_order / xcd_steal 2: per-XCD work lists so an expert slice stays in one L2, steal at the end
- fin_off: opaque final-step A parity, so LLVM does not hoist + spill 32 ds_read addresses
- sbm 64: kunroll 2 (two-step K-loop body, no loop-carried B copies)
- sbm 128: sa_pack (A scales one ds_read_b128 per k-step), epi_remat (no epilogue lane-constant spills)

V4.1-Flash EP8, same process, 20 interleaved graph rounds: -3.9% (bs 512), -10.7% (1024),
-13.2% (2048), -12.3% (4096), -12.3% (8192), faster in 20/20 rounds at each.

Found with the mori-harness loop: a loop-nest performance model ranks levers and prices costs by
single removal, the cco-fusion agent implements, ISA-checks and A/B-tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

GPU CI for d6e5af3d (run): none, draft PR (add ci:full or mark it ready to run CI).

Lanes follow the changed files. Adding ci:full re-runs CI with every lane, the full internode sweeps and every fused GEMM case; adding ci:mi300x re-runs it with the MI300X lanes added. /ci-rerun re-runs CI against the current main.

@kawhil-amd kawhil-amd changed the title perf(cco/example13): stage1 GEMM1 tile-loop changes behind --tile-opt (driven by mori-harness) perf(fused): stage1 GEMM1 tile-loop changes behind --tile-opt (driven by mori-harness) Nov 22, 2026
@kawhil-amd kawhil-amd changed the title perf(fused): stage1 GEMM1 tile-loop changes behind --tile-opt (driven by mori-harness) perf(fused): MoE stage1 gemm tile-loop changes behind --tile-opt (driven by mori-harness) Nov 23, 2026

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