Skip to content

[Bugfix] Drain FlyDSL stage-1 LDS-DMA loads before the tile barrier - #5561

Draft
kevin-mii wants to merge 2 commits into
ROCm:mainfrom
kevin-mii:fix/flydsl-moe-lds-dma-drain
Draft

kevin-mii wants to merge 2 commits into
ROCm:mainfrom
kevin-mii:fix/flydsl-moe-lds-dma-drain

Conversation

@kevin-mii

@kevin-mii kevin-mii commented Sep 15, 2026 •

Copy link
Copy Markdown

Motivation

Investigate the gfx950 FlyDSL MoE stage-1 LDS-DMA ordering concern originally carried by sgl-project/sglang#39186. This remains a draft: the current tests do not reproduce a failure on unpatched main, so the necessity and performance tradeoff of the stronger synchronization are not established.

Change

  • Replace the ordinary stage-1 pipeline's tile-derived partial VMEM wait with s_waitcnt(0) before the tile barrier. The heterogeneous async path already drains VMEM.
  • Add a scheduling fence after the next LDS-DMA prefetch group.
  • Remove the unused partial-wait estimate.
  • Compare async and synchronous execution with exact equality, then check 50 poisoned eager outputs and 20 graph replays for each of three gfx950 tile configurations.

Updated onto main 1dd826c42b38aa71adf058053b9c512a9b47d20f with a normal merge; current head 1351b12745203860de6cba4c37f04430137cd102.

Validation

On MI355X gfx950, ROCm 10, PyTorch 2.11, FlyDSL 0.4:

  • Patched branch: 3/3 tile cases pass with rtol=atol=0 and a fresh FlyDSL cache.
  • Unpatched main: the same 3/3 cases also pass, using a separate fresh cache. This is not a discriminating failure reproducer.
  • Disassembly of those freshly compiled async kernels confirms the body barriers still follow partial waits on main: vmcnt(6) for t64x128, vmcnt(10) for t64x256, and vmcnt(8) for t128x128. The corresponding patched body barriers follow vmcnt(0). The compiler has not made the patch a no-op; this difference alone does not prove a correctness bug.
  • Black, Ruff and diff whitespace checks pass locally. Required upstream CI is awaiting maintainer approval for this fork head.
  • Preliminary stage-1 timings were collected on different GPUs and are not a controlled performance comparison. Full-model accuracy and production performance were not validated.

The earlier ROCm 7.2.4 / MI350X test also passed on both patched and unpatched code.

Flags and remaining work

TRITON_HIP_USE_ASYNC_COPY=0, used in the original test command, works around a separate Triton supporting-kernel failure. The FlyDSL test explicitly requests async copying. Current AITER's production stage-1 wrapper also passes use_async_copy=True.

AITER_FLYDSL_MOE_EXPERT_SCHEDULING_MODE is currently consumed by the gfx1250 TDM kernel, not this gfx950 mixed-MoE builder. AITER_FLYDSL_FORCE=0 is a backend-selection knob, not a synchronization fix or a guaranteed override of tuned CSV choices.

Before requesting undraft/review: establish an affected failing configuration or a sufficiently justified ordering test, address the sibling pipeline audit from the advisory review, and measure the synchronization cost on the same GPU and relevant production shapes.

Wait for all VMEM operations before exposing the next LDS tile, and keep scale loads after the DMA group. Remove the unused partial-wait estimate. Add async-versus-sync, repeatability, and graph replay coverage on gfx950.

Signed-off-by: Kevin Mi <[email protected]>
@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; main branch always runs both MI35X and MI300X
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5561 --add-label <label>

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 opt this PR out.

@zufayu

zufayu commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Advisory review (static + hand-run; not a merge gate). Validation/Perf ran no GPU stage — reasons are on their lines below. Findings tagged [verified] are traced to code/repro.

Replaces the tile-derived partial VMEM wait before the MoE stage-1 K-loop barrier with a full s_waitcnt(0) drain and adds a scheduling fence after the LDS-DMA prefetch group, so a consumer wave can no longer read an incompletely populated LDS tile.

Review (advisory): ⚠️ NEEDS WORK
Validation (deterministic): NOT RUN — auto-validation disabled (REVIEW_AUTO_VALIDATE=0), and the single test target op_tests/test_flydsl_moe_lds_dma.py is gfx950-only while this box is gfx942, so the changed sync path cannot be executed here; verification is static analysis of the emitted wait/fence sequence only.
Perf (advisory): NOT RUN — the triaged target op_tests/test_flydsl_moe_lds_dma.py exposes no benchmark entry point and no gfx950 is available on this box; the PR ships no timing of its own and leaves "Measure the additional wait" unchecked.

⚠️ [inferred] The partial-VMEM-wait-before-barrier idiom that this PR's own new comment declares unsafe ("Partial VMEM waits can leave LDS-DMA loads crossing the barrier", aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py:1530) remains live in sibling FlyDSL kernels on the same arch: aiter/ops/flydsl/kernels/preshuffle_gemm.py:561/590/625 (s_waitcnt(num_b_loads) before gpu.barrier with dma_a_to_lds in the same pipeline), aiter/ops/flydsl/kernels/gemm_a16w16_gfx950.py:1111/1135/1155 (wait_vmcnt_and_barrier(half_ldg_b_iters + half_ldg_a_iters) around cdna4 BufferLoadAsyncLDS), aiter/ops/flydsl/kernels/mega_moe/gemm1.py:154 (wait_lds_barrier(NUM_ACC_N*_PACK + NUM_B_SCALE) with a_gather.prefetch_to_lds), aiter/ops/flydsl/kernels/fmha_gfx950/pipeline.py:38 and hstu_attention_fwd.py:782. If instruction scheduling can interleave the counted loads into the DMA group in this kernel, the same mechanism can do it there — silent wrong output for those kernels' consumers. Author must either apply the same full drain to the sites that guard LDS-DMA consumption or state for each site why its counted group cannot be interleaved.

⚠️ [verified] The new test cannot reproduce the race it is named for: the author's own Test Result states it "also passes on unpatched current main" on their toolchain (MI350X VF, gfx950, ROCm 7.2.4), so the fix's behavioral effect is unvalidated on every toolchain where the race was actually reported (upstream sgl-project/sglang#39186) — the 50 eager launches and 20 graph replays only catch the race if it happens to fire during those runs. Author must reproduce the intermittent failure on the affected toolchain (or a stress configuration of it) before merge, or add a structural assertion on the compiled kernel (asm dump: LDS-DMA group contiguous and a full drain before each s_barrier) so the test can fail statically.

⚠️ [inferred] The full drain trades the partial wait's memory-latency overlap for certainty and nobody measured the price: per half-iteration the ~6-10 in-flight post-DMA B/scale VMEM loads (the old count for t64x128/t128x128/t64x256 a8w4 interleave) must now complete before the barrier, and the added sched_barrier(0) further constrains scheduling around the DMA group; no base-vs-head timing exists. The cost concentrates on the small-count configs — fp8-B tiles whose old count was >= 16 already wrapped the raw bitfield to vmcnt(count%16), a near-full drain, and see almost no delta. Author must measure base vs head on the affected a8w4 tile/dtype combinations on gfx950 before taking the PR out of draft.

📝 [inferred] The async-vs-sync oracle in op_tests/test_flydsl_moe_lds_dma.py carries rtol=atol=0.02, but both paths load identical quantized values through the same MFMA sequence, so bitwise equality is the expected result and the 2% slack could mask a small systematic async-path discrepancy (the repeat checks are already exact, rtol=0/atol=0). Reviewer should ask whether the async-vs-sync comparison also passes at rtol=0/atol=0, and if not, why.

kevin-mii added a commit to kevin-mii/sglang that referenced this pull request Sep 24, 2026
Measured on MI355X (DeepSeek-V4.1-Flash TP4, DSpark EP4) with
AITER_BF16_FP8_MOE_BOUND=0, as the AMD DeepSeek-V4 tests and cookbook set it:
- the stage-1 LDS-DMA drain: GSM8K 0.885 unpatched vs 0.905 patched (200
  questions), throughput within noise, and its race test passes unpatched;
  it stays upstream as ROCm/aiter#5561;
- the bf16 SiLU route is never taken at bound 0; the fix is ROCm/aiter#5802;
- the tuned FMoE CSV shows no end-to-end gain; it stays upstream as
  ROCm/aiter#5562.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip pushed a commit that referenced this pull request Oct 6, 2026
* DSV4.1 ATOM-port local fixes (flydsl MoE LDS-DMA wait, fp4 prefill cache, MoE tuner GPU datagen, torch.Stream, tuned FMoE CSV)

- flydsl mixed MoE stage1: full vmcnt drain + sched_barrier before the LDS-DMA
  barrier (partial waits let LDS-DMA loads cross it; #5561)
- fp4 prefill mqa logits: unbounded kernel cache (lru_cache(32) evicted and
  recompiled per shape)
- MoE tuner: generate the E x 2I x H test weights on the GPU (CPU fp4 packing
  took tens of minutes per shape at E=385)
- cpp_itfs torch_utils: accept any torch.Stream (derive the HIP handle when
  cuda_stream is missing)
- add DSV4.1 TP2 shared-experts-fusion fp8/fp4 tuned FMoE config

* Merge DSV4.1 TP2 fp8/fp4 FMoE tuning into dsv41_fp4_{tuned,untuned}_fmoe.csv

- move the 23 shared-experts-fusion rows (E385 topk7, E129 topk4, fp8 activation x
  fp4 weight) into dsv41_fp4_tuned_fmoe.csv and their shapes into
  dsv41_fp4_untuned_fmoe.csv instead of a separate file
- drop the torch_utils, fp4 prefill cache and flydsl stage1 wait changes

---------

Co-authored-by: wunhuang <[email protected]>
@kevin-mii

Copy link
Copy Markdown
Author

Rebased the work onto current main via a normal merge in 1351b12 and tightened the async-vs-sync assertion to exact equality (rtol=atol=0).

Fresh validation on gfx950, ROCm 10 / PyTorch 2.11 / FlyDSL 0.4, with separate fresh FlyDSL caches:

  • Patched branch: 3/3 tile cases pass, including 50 poisoned eager outputs and 20 graph replays per case.
  • Unpatched main 1dd826c42: the same 3/3 cases pass exact equality and replay checks. This is still not a discriminating reproducer.
  • Preliminary stage-1 timings (baseline → patched, microseconds) were 11.80 → 11.67 for t64x128, 16.90 → 16.50 for t64x256, and 20.46 → 19.75 for t128x128. These were separate GPUs on the same idle box, so they are smoke measurements, not evidence of a performance improvement.

Keeping this PR in draft. The remaining requirements from the review still stand: a failing baseline or an assembly-level ordering check, a justified audit of sibling partial-wait pipelines (including preshuffle_gemm.py), and a controlled same-GPU performance comparison on the production workload. The exact-equality concern is addressed; the necessity of the stronger wait is not established by these tests.

@kevin-mii

Copy link
Copy Markdown
Author

Follow-up on whether an existing flag or current main supersedes this PR:

  • TRITON_HIP_USE_ASYNC_COPY=0 is the workaround documented in the original test plan. It applies to the supporting Triton kernels; the current FlyDSL stage-1 wrapper still explicitly uses async copying.
  • AITER_FLYDSL_MOE_EXPERT_SCHEDULING_MODE now defaults to 1, but its current consumer is the gfx1250 TDM kernel, not this gfx950 mixed-MoE builder.
  • Main still has the partial-wait path. I also disassembled the freshly compiled test artifacts: the async body barriers retain vmcnt(6) / vmcnt(10) / vmcnt(8) for t64x128 / t64x256 / t128x128 respectively; the proposed patch emits vmcnt(0) at the corresponding barriers.

So I could not confirm a flag or compiler change that makes this patch redundant. Both sides still pass the exact-equality stress/replay tests. That establishes neither a current bug nor its absence. Keeping this draft pending a discriminating reproduction/ordering justification and a controlled performance comparison; the description now reflects the current base and validation.

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.

2 participants