Skip to content

[FlyDSL] [gfx1250] MegaMoE: split cross-rank sync out of the compact plan kernel - #8667

Open
XingerZhu wants to merge 1 commit into
mainfrom
zxe/compact_without_sync
Open

XingerZhu wants to merge 1 commit into
mainfrom
zxe/compact_without_sync

Conversation

@XingerZhu

Copy link
Copy Markdown
Contributor

Motivation

The gfx1250 MegaMoE compact plan (tdm_compact_plan) was a single kernel that tallied local routes, pushed its histogram to every peer, spun on the peer done counter, and only then derived the compact rows. While waiting on a peer it kept all of its waves and LDS resident. The plan runs on a side stream and overlaps the previous layer's expert GEMM, so a spinning, LDS-heavy kernel is a poor neighbour, and the peer wait is charged to the plan's own time.

What changed

compile_tdm_compact_plan now launches three back-to-back kernels on the same stream (the compile/launch signature is unchanged, so mega_moe.py call sites are untouched):

kernel role
tdm_compact_plan_arrive tally local routes, push the histogram to every peer, bump each peer's done counter. Never waits on a peer.
tdm_compact_plan_sync one wave; the only cross-rank wait (spin until every peer has arrived, then system acquire fence).
tdm_compact_plan_finish read the allgathered histograms, compute masked_m / psum / send_base, rewrite tok_map to the final compact rows.

Implementation notes:

  • LDS does not survive a kernel boundary, so the packed per-route word (segment | intra << 16) is staged through tok_map (the former merge_routes LDS shortcut is gone) and finish re-reads the histograms from the arena. The protocol (gen counter, hist_pingpong, slot-specific off_hist/off_done, dense/sparse/TDM/fallback hist layouts) is otherwise unchanged.
  • The split kernels are single-block (PLAN_BLOCKS == 1, which is already the value). The dead plan_blocks > 1 grid-barrier paths are removed and compile_tdm_compact_plan raises ValueError if PLAN_BLOCKS != 1. block_hist is still accepted but unused.
  • Docstrings in compact_plan.py and MegaMoEGfx1250.prefetch_compact_plan updated.

Testing

Run on gfx1250, 2 ranks (the other GPUs were fully occupied by an unrelated serving job, so no 4-rank / end-to-end run):

  • Functional: a standalone 2-rank test compared masked_m, psum, send_base and every route's destination row (including invalid expert ids) against a pure-python reference. Covered dense-TDM, dense buffer_store fallback, sparse histogram, double-slot alternation and hist_pingpong=True, 4 iterations each with varying token counts. All PASS.
  • Per-kernel time (npes=2, epr=96, topk=6, 128 tok/rank, median of 30):
before after
rank that does not wait on its peer tdm_compact_plan 23.0 us arrive 15.5 + finish 10.5 + sync 3.6 = ~30 us
rank that waits on its peer wait is inside the plan kernel (121 us) arrive ~16 + finish ~10 us, wait isolated in sync (69 us)

Caveats / what I did not verify

  • Total latency does not improve. With no peer wait the split costs ~6 us extra (two more launches + one tok_map write/read round trip). The intended benefit is that the wait no longer holds the plan's waves/LDS and is no longer counted as plan time; I have not measured the effect under a real GEMM overlap.
  • The skew injected in the benchmark (torch.cuda._sleep) is noisy, so the "waiting rank" numbers only show that the wait moved into sync, not exact values.
  • Still needed: bench_mega_moe.py ... --stage1_fused 1 --combine fused on 4 ranks, main vs this branch, once the GPUs are free.

…plan kernel

The compact plan used to be one kernel that tallied local routes, pushed the
histogram to every peer, spun on the peer done counter, and then derived the
compact rows. While spinning it kept its 32 waves and LDS occupied, which hurts
when the plan overlaps the previous expert GEMM on a side stream.

Split it into three back-to-back kernels on the same stream:

- tdm_compact_plan_arrive: tally routes, push histogram to peers, bump each
  peer's done counter. Never waits on a peer.
- tdm_compact_plan_sync: one wave, the only cross-rank wait.
- tdm_compact_plan_finish: read the allgathered histograms, write masked_m /
  psum / send_base and rewrite tok_map.

LDS does not survive a kernel boundary, so the packed per-route word goes
through tok_map and finish re-reads the histograms from the arena. The split
kernels are single-block (PLAN_BLOCKS == 1); the dead multi-block paths are
removed and guarded with a ValueError. The compile/launch signature is
unchanged.
@XingerZhu
XingerZhu requested review from a team and a balanced review from Copilot November 25, 2026 09:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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

@aiter-bot

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision 404b4885c349 · 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. What is the most important boundary or failure mode introduced by this change, and what evidence covers 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 — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • 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

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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.

4 participants