Repository navigation
fix(EPv2): use last-arrival-resets for wide-EP grid barrier - #709
Conversation
The wide-EP path in EpCrossDeviceBarrier had every block spin on the transient value gridDim.x then store 0. A block delayed by scheduling jitter could skip straight past gridDim.x to the post-reset 0 and spin forever — a deadlock under wide EP (>64 ranks). Switch the wide path to last-arrival-resets: the final block to atomicAdd resets to 0, everyone else waits for the stable terminal 0. The narrow path (lockstep-safe) is unchanged. Applies to both the portable and gfx1250 barriers. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
jhchouuu
left a comment
There was a problem hiding this comment.
LGTM — the race is real and last-arrival-resets fixes it.
Checked the things that would break wait == 0: each barrier is called once per launch, dispatch and combine use separate gridBarrier tensors, staged is uniform across the grid, and the counter ends at 0, same as before. The narrow path still selects a single wavefront in block 0, so leaving it alone is correct. The clang-format hunks come from the pinned v20.1.8 pre-commit (main was out of format there).
One note on the test plan: bench_ep --ep 128 across nodes takes the internode path (world_size > gpu_per_node), which doesn't use this barrier, so it won't exercise the fix. The wide branch only runs for intranode with world_size > waveSize (>32 on gfx1250, >64 on wave64). If there's no box for that, please say "compile-verified only" in the body.
| if (thdId == 0) { | ||
| EpWaitEq(args.gridBarrier, static_cast<unsigned int>(gridDim.x)); | ||
| __hip_atomic_store(args.gridBarrier, 0u, __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_AGENT); | ||
| if (_gridArvl == static_cast<unsigned>(gridDim.x) - 1) |
There was a problem hiding this comment.
Non-blocking: blocks other than 0 don't actually need the rendezvous. They are already gated on block 0 downstream, via fanLines here and localBarrier on the portable path (ep_intranode_kernel.hpp), so a block-0-only wait+reset would also work and would drop the per-block polling. Fine to leave as is.
There was a problem hiding this comment.
seems could be remove, i will try it on next time.
Summary
EpCrossDeviceBarrier(portable) andEpCrossDeviceBarrier1250x(gfx1250) had an inter-block race: every block spun on the transient valuegridDim.xthen stored 0, but a block delayed by scheduling jitter could skip pastgridDim.xto the post-reset 0 and deadlock.atomicAddresets to 0, everyone else waits for the stable terminal 0. The narrow path (lockstep-safe) is unchanged.Test plan
bench_ep --ep 128(wide EP) on multi-node to verify no hangbench_ep --ep 8(narrow EP) regression check🤖 Generated with Claude Code