Repository navigation
[FlyDSL] [Bugfix] gfx1250 FP8 GEMM: store C from registers / LDS read-back, not a TDM store from LDS - #8486
[FlyDSL] [Bugfix] gfx1250 FP8 GEMM: store C from registers / LDS read-back, not a TDM store from LDS#8486XiaobingSuper wants to merge 3 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
02f6345 to
6855131
Compare
…-back, not a TDM store from LDS On gfx1250 the epilogue of launch_gemm_a8w8 ds_stored the C tile to LDS, passed s_wait_dscnt 0 + s_barrier, and each wave TDM-stored a box of whole rows. Now and then the TDM store's LDS read returned a 16-byte piece as LDS held it before the ds_stores: the last k-tile's FP8 A operand, 1e24-1e38 as bf16. bf16 / f16 C without split-K is now stored straight from the accumulators with global stores (no LDS staging, no barrier). Unfused split-K fp32 partials go LDS -> barrier -> ds_load read-back -> global stores. Rows past M are dropped as before; the fused-quant epilogue is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
6855131 to
de1fa01
Compare
|
Head de1fa01 is the register-store / LDS-read-back fix: 0 bad replays in 10 min of the repro (main: bad in 4 of 4 runs) and in both split-K cases (main: 15 and 5); kernel time vs main -7.9% to +3.6% at the M3.1 shapes; rel err 1.6-1.7e-3 vs torch in all 16 configs. Ready for review. |
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
op_tests/flydsl_tests/repro_gemm_a8w8_tdm_race.py replays one CUDA graph with the M3.1 shared-expert down_proj GEMMs on stream A beside the routed MXFP4 MoE on stream B and counts outputs that differ from a clean eager run (main: bad > 0, this PR: 0). Standalone script, not collected by pytest (~2 min a run). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…thread The reproducer is a standalone two-stream CUDA-graph script (about 2 minutes a run) that no CI runner executes; it is posted on the PR instead of living in op_tests/. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Reproducer for this PR, moved here from python repro_gemm_a8w8_tdm_race.py # main: RESULT BAD, this PR: RESULT CLEAN
python repro_gemm_a8w8_tdm_race.py --moe-t 2 # same, if the default 8 MoE tokens do not collide (see the PR description)
DEBUG_HIP_FORCE_GRAPH_QUEUES=1 python repro_gemm_a8w8_tdm_race.py # control, one graph queue: CLEAN
python repro_gemm_a8w8_tdm_race.py --bg none # control, nothing on stream B: CLEAN
python repro_gemm_a8w8_tdm_race.py --m 32,64 --n 1536 --k 6144 \
--kernel flydsl_mxfp8_32_bpreshuffle_wmma_t16x32x512_mw1_nw2_nb2_sk4_cm1_cn1_fsk,flydsl_mxfp8_32_bpreshuffle_wmma_t32x128x128_mw1_nw4_nb4_sk8_cm1_cn1 # split-K
|
|
Closing in favor of #8737, which keeps the TDM store and adds an LDS flush before it. Checked on one gfx1250 GPU (256 CUs; image with torch 2.13 / ROCm 10.3, FlyDSL 0.5.3) with this PR's reproducer, unchanged, at M = 64 (
So the flush is what fixes it; moving C alone does not. With C moved, the stale values become tiny (about 1e-24), which would be harder to notice in a model. #8737 was also clean with 1 MoE token, a plain FP8 GEMM beside it, and the split-K kernels (sk4 / sk8). |
…DS_STORE The C-tile LDS read-back and its environment gate move to ROCm#8486, which owns that fix; the non-fused epilogue here is main's TDM store again. Also merge the two fused split-K checks into one and drop the unused cur_kt argument threaded through the k-tile helpers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflict resolved (from #8737, LDS flush before TDM stores): - gemm_a8w8_gfx1250: keep this branch's rank0 epilogue (direct global stores, no LDS) ahead of main's C offset. The rotated fused split-K rows and the row-stripe epilogue use the C staging at c_base_ptr, like the plain TDM store. Merged cleanly but needed changes: - splitk_fused_epilogue_gfx1250: an optional flush_addr flushes the reduced rows before their LDS -> TDM store (split_k > 2). The generic kernel passes its flush scratch; the compute and a4w4 callers are unchanged. With the #8486 two-stream reproducer, a split_k 4 row-stripe kernel gave 140 bad replays in 4 minutes without it and 0 with it.
What
launch_gemm_a8w8(gfx1250 FP8 / MXFP8 GEMM,gemm_a8w8_gfx1250.py) no longer writes C with a TDM store from LDS:ds_loadread-back → global stores in 16-byte row chunks.Why
The old epilogue
ds_stored the C tile over the last k-tile's operands, passeds_wait_dscnt 0+s_barrier, and then each wave TDM-stored a box of whole rows. On gfx1250 that TDM store now and then reads a 16-byte piece as LDS held it before theds_stores: the last k-tile's FP8 A operand, which read as bf16 is 1e24-1e38 and never NaN.In MiniMax-M3.1-Flash TP4 decode on MI455X (shared-expert down_proj beside the routed MoE on another stream of the captured graph) the poisoned residual made RMSNorm output 0, the logits row all zero, and argmax token 0.
Validation
Reproducer: a standalone script, posted in this comment instead of committed. One CUDA graph: stream A runs 64 launches of the M3.1 shared-expert down_proj (N = 6144, K = 768, M = 8 and 64), stream B the M3.1 routed MXFP4 MoE; every output is compared with an eager run. 1x MI455X, bad replays:
DEBUG_HIP_FORCE_GRAPH_QUEUES=1), nothing on stream B (--bg none)The collision depends on timing. Reproduced again on two more nodes: with torch 2.11 / ROCm 10.1 / FlyDSL 0.5.0 the default command fires (main 30 / 649,300, this PR 0 / 637,000); with torch 2.13 / ROCm 10.3 / FlyDSL 0.5.3 the default 8 MoE tokens did not collide (main 0 / 4.9 M), but
--moe-t 1or2does (main 276 / 2.7 M, this PR 0 / 3.8 M).Correctness: against torch, all 16 configs of the table below at full shape, rel err 1.6-1.7e-3 (the FP8 quantization error); nothing is written past M.
Kernel time vs main
M3.1 TP4 shapes with their tuned kernels, CUDA graph, 1x MI455X, median of 6 interleaved rounds, us:
gate_up M = 8 is within the run-to-run spread (main 4.32-4.88, this PR 4.48-5.02).
Open question for HW / compiler
Triton / Gluon lower the same handoff to the same
ds_store→s_wait_dscnt→s_barrier→tensor_store_from_ldssequence, andgemm_a8w8_256x256relies on it too (not changed here). The LLVM AMDGPU memory model leaves tensor ops out and documents no DS → TDM fence. Which fence, if any, orders a TDM store's LDS read after other waves'ds_stores at a workgroup barrier?#8273 carries the earlier version of this fix and drops it once this lands.
PR Self-Review
Reviewed revision
fd44a48
Behavior and intent
On gfx1250,
launch_gemm_a8w8no longer TDM-stores C from LDS. bf16 / f16 C without split-K goes from registers straight to global memory; unfused split-K fp32 partials are read back from LDS withds_loadafter the barrier; fused quant is unchanged. This removes stale-LDS bytes from C.Validation and unverified scope
python repro_gemm_a8w8_tdm_race.py): main bad in 4 of 4 runs (22, 2, 17, 4 bad replays in 2 min); this PR 0 / 930,100 (M = 8) and 0 / 667,900 (M = 64) in 10 min.--m 32,64 --n 1536 --k 6144 --kernel ...sk4...,...sk8...): main 15 / 122,200 and 5 / 114,900; this PR 0 / 120,700 and 0 / 113,100.--moe-t 1and--moe-t 2, main 276 / 2.7 M, this PR 0 / 3.8 M.DEBUG_HIP_FORCE_GRAPH_QUEUES=1and--bg noneboth 0.PR-specific question
Most important boundary: the M edge of the last tile. The TDM store's tensor extent used to clip rows past M; both new store paths (bf16 / f16 from registers, split-K fp32 read back from LDS) now guard each row with
row < Mthemselves, and a wrong guard would write past M into whatever follows C. Columns are unchanged: the old TDM box was also a fulltile_nwide. Evidence: the eager check above writes nothing past M in all 16 configs, which include M = 1 and 8 (rows end inside a tile), plus the split-K sk4 / sk8 runs.Changed op tests
None. The reproducer is not committed: it is a standalone two-stream CUDA-graph script (about 2 minutes a run) that no CI runner executes, so it lives in this comment.
🤖 Generated with Claude Code