Skip to content

[FlyDSL] [Perf] MegaMoE stage1: fold the ready-order tile wait into the scheduler block - #6431

Merged
coderfeli merged 2 commits into
ROCm:mainfrom
AMD-yanfeiwang:perf/megamoe-stage1-ready-order-wait
Oct 13, 2026
Merged

coderfeli merged 2 commits into
ROCm:mainfrom
AMD-yanfeiwang:perf/megamoe-stage1-ready-order-wait

Conversation

@AMD-yanfeiwang

@AMD-yanfeiwang AMD-yanfeiwang commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

#6259 fixed a race on the compact ready-order path of MegaMoE V2 Stage1 by making every compact work item run tid0 wait(tile_ready) + barrier + fence_system_acquire. On the ready-order path the scheduler block already runs a barrier and a system acquire after popping the ready queue, so each work item now pays for them twice. Under skewed routing this costs 5-6%.

Technical Details

  • Ready-order path: tid0 waits for tile_ready in the scheduler block, right after it reads the queued tile and before the existing barrier and system acquire.
  • The per-work-item wait + barrier + acquire stays only on the sequential compact path. Fixed-slot is unchanged.

Ordering is the same as in #6259: every thread's system acquire still follows tid0 observing tile_ready for the tile it reads. A work batch never crosses an m-tile (N_TILES % WORK_BATCH == 0), so one wait per pop covers the batch.

Test Plan

  • op_tests/multigpu_tests/test_mega_moe_v2.py on MI355X, EP4 and EP8, main (6bf550b) vs this PR: v4_pro (at EP8 on fixed-slot with the default MTPR and on compact with MTPR 8192), kimi_k3_route (incl. --force-fanout-boundary), uneven ranks, burst 2000. Plus expert-skewed routing to exercise the ready-order path: the rank-balanced-hot route of bench_mega_moe_v2.py, where each slot lands on its rank's expert 0 with probability 0.6 or 0.9 (hot share); bs 1-4096, accuracy checked at every bs.
  • EP8 perf A/B on 392 experts / topk 7, MTPR 8192: the skewed test above and bench_mega_moe_v2.py --mega-only (rank-balanced-hot, hot-rank0, uniform).
  • DSv4-Pro EP8 a8w4 (392 experts, topk 7, MTPR 8192), skewed and uniform routing.
  • This kernel is skipped in CI (.github/scripts/aiter_test.sh).

Test Result

All accuracy checks pass at EP4 and EP8 (relL2 0.050-0.059), on fixed-slot and on both compact orders; CUDA Graph replay is bit-exact, and bursts complete.

DSv4-Pro EP8, fused op time, skewed routing:

tokens/rank 41630d0 (before #6259) with #6259 this PR
1024 1269.4 us 1334.7 us 1271.7 us

With 2x the skew, relative to 41630d0:

tokens/rank with #6259 this PR
64 +4.6% -1.3%
256 +5.8% +0.3%
1024 +6.1% -0.6%

Uniform routing is unchanged and the outputs are identical.

EP8, skewed routing (test_mega_moe_v2.py, 7168x3072, 392 experts, topk 7, MTPR 8192), main -> this PR, rank-mean time per call, mean of 2 rounds. Stage1 order is what every rank ran, read back from the workspace (max_expert_tiles * 4 >= num_m_tiles selects ready-order):

hot share tokens/rank Stage1 order Stage1 end to end
0.6 64 sequential 345.8 -> 345.4 us (-0.1%) 467.7 -> 467.5 us (-0.1%)
0.6 256 ready-order 482.1 -> 450.9 us (-6.5%) 748.5 -> 726.4 us (-3.0%)
0.6 1024 ready-order 749.0 -> 695.1 us (-7.2%) 1154.6 -> 1101.0 us (-4.6%)
0.6 4096 ready-order 1661.1 -> 1595.8 us (-3.9%) 3004.9 -> 2954.7 us (-1.7%)
0.9 64 ready-order 362.2 -> 330.9 us (-8.7%) 459.6 -> 429.6 us (-6.5%)
0.9 256 ready-order 504.7 -> 465.0 us (-7.9%) 821.1 -> 782.5 us (-4.7%)
0.9 1024 ready-order 842.6 -> 785.1 us (-6.8%) 1276.7 -> 1215.1 us (-4.8%)
0.9 4096 ready-order 1757.8 -> 1695.6 us (-3.5%) 3191.5 -> 3131.0 us (-1.9%)

EP8, bench_mega_moe_v2.py --mega-only --hot-bias 0.6 (392 experts, topk 7, MTPR 8192), main -> this PR, mean of 2 rounds:

route tokens/rank Stage1 end to end
rank-balanced-hot 64 349.3 -> 350.6 us (+0.4%) 471.1 -> 470.2 us (-0.2%)
rank-balanced-hot 256 487.2 -> 452.8 us (-7.1%) 766.4 -> 738.0 us (-3.7%)
rank-balanced-hot 1024 755.4 -> 704.6 us (-6.7%) 1166.2 -> 1110.0 us (-4.8%)
hot-rank0 64 357.2 -> 351.6 us (-1.6%) 469.0 -> 470.2 us (+0.2%)
hot-rank0 256 541.7 -> 536.4 us (-1.0%) 843.4 -> 843.9 us (+0.1%)
hot-rank0 1024 1188.6 -> 1199.3 us (+0.9%) 2206.9 -> 2213.7 us (+0.3%)
uniform 64 355.5 -> 354.9 us (-0.2%) 471.9 -> 473.7 us (+0.4%)
uniform 256 400.0 -> 398.6 us (-0.3%) 605.5 -> 606.0 us (+0.1%)
uniform 1024 682.1 -> 690.2 us (+1.2%) 1156.2 -> 1153.8 us (-0.2%)

At EP8, wherever Stage1 runs the ready-order path this PR is 1.7-6.5% faster end to end (3.5-8.7% in Stage1); the sequential-path, rank-skewed (hot-rank0) and uniform cases are within 0.4% end to end.

EP4, skewed routing (7168x3072, 384 experts, topk 4, MTPR 8192), main -> this PR, rank-mean time per call, mean of 6 rounds (hot share 0.6) or 2 rounds (0.9), Stage1 order read back as above:

hot share tokens/rank Stage1 order Stage1 end to end
0.6 64 sequential 379.4 -> 382.2 us (+0.8%) 519.5 -> 522.1 us (+0.5%)
0.6 256 sequential 583.4 -> 584.9 us (+0.3%) 951.8 -> 954.9 us (+0.3%)
0.6 1024 ready-order 789.2 -> 739.9 us (-6.3%) 1244.2 -> 1187.8 us (-4.5%)
0.6 4096 ready-order 1277.8 -> 1230.4 us (-3.7%) 2381.0 -> 2329.0 us (-2.2%)
0.9 64 ready-order 263.6 -> 243.5 us (-7.6%) 341.8 -> 319.6 us (-6.5%)
0.9 256 sequential 501.6 -> 504.7 us (+0.6%) 821.1 -> 821.0 us (0.0%)
0.9 1024 ready-order 844.8 -> 782.5 us (-7.4%) 1359.3 -> 1293.5 us (-4.8%)
0.9 4096 ready-order 1532.6 -> 1446.2 us (-5.6%) 2760.7 -> 2691.8 us (-2.5%)

The sequential rows are noise: at bs 64 and 256, main's per-round times span 3.3% and 2.6%, and this PR's fall inside that range.

EP4, uniform routing (v4_pro, topk 6, MTPR 8192), main -> this PR, mean of 3 rounds:

tokens/rank Stage1 end to end
1 127.5 -> 124.9 us (-2.0%) 161.3 -> 160.5 us (-0.5%)
8 279.0 -> 280.3 us (+0.4%) 380.7 -> 381.7 us (+0.3%)
64 515.1 -> 515.2 us (0.0%) 707.3 -> 706.1 us (-0.2%)
256 560.6 -> 561.2 us (+0.1%) 884.4 -> 885.3 us (+0.1%)
1024 753.1 -> 754.6 us (+0.2%) 1343.2 -> 1345.3 us (+0.2%)

Co-authored-by: @Duyi-Wang

@AMD-yanfeiwang
AMD-yanfeiwang requested a review from a team October 12, 2026 10:50
@github-actions

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 (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: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 6431 --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.

ROCm#6259 fixed a race on the compact ready-order path (a consumer could
read per-tile metadata before the planner's store was visible) by making every
compact work item run tid0 wait(tile_ready) + barrier + fence_system_acquire.
On the ready-order path that is a second barrier + system acquire per work
item, on top of the ones the scheduler block already does after popping the
ready queue.

Do the tile_ready wait in the scheduler block instead (tid0, right after
reading the queued tile, before the existing barrier and system acquire), and
keep the per-work-item wait only for the sequential path. The ordering
guarantee is unchanged: every thread's system acquire still follows tid0
observing tile_ready for the tile it is about to read.

DSv4-Pro EP8 a8w4, MTPR 8192, 392 experts / topk 7, skewed routing:
1024 tok/rank 1334.7 -> 1271.7 us (41630d0: 1269.4 us); 2x skew
64/256/1024 tok/rank +4.6/+5.8/+6.1% -> -1.3/+0.3/-0.6% vs 41630d0.
Uniform routing unchanged; outputs identical. test_mega_moe_v2.py
(v4_pro compact/fixed-slot/uneven ranks/burst 2000, kimi_k3_route incl.
--force-fanout-boundary + burst 2000) passes.

Co-authored-by: Duyi-Wang <[email protected]>
@AMD-yanfeiwang
AMD-yanfeiwang force-pushed the perf/megamoe-stage1-ready-order-wait branch from b63dfdc to 8a7db10 Compare October 12, 2026 10:53
@zufayu
zufayu requested a review from yadaish October 13, 2026 01:41
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.

4 participants