Skip to content

fix(EPv2): use last-arrival-resets for wide-EP grid barrier - #709

Merged
kawhil-amd merged 1 commit into
ROCm:mainfrom
kawhil-amd:fix/epv2-wide-ep-grid-barrier-race
Sep 24, 2026
Merged

kawhil-amd merged 1 commit into
ROCm:mainfrom
kawhil-amd:fix/epv2-wide-ep-grid-barrier-race

Conversation

@kawhil-amd

Copy link
Copy Markdown
Contributor

Summary

  • The wide-EP path in EpCrossDeviceBarrier (portable) and EpCrossDeviceBarrier1250x (gfx1250) had an inter-block race: every block spun on the transient value gridDim.x then stored 0, but a block delayed by scheduling jitter could skip past gridDim.x to the post-reset 0 and deadlock.
  • 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.

Test plan

  • bench_ep --ep 128 (wide EP) on multi-node to verify no hang
  • bench_ep --ep 8 (narrow EP) regression check

🤖 Generated with Claude Code

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]>
@kawhil-amd
kawhil-amd requested review from jhchouuu and zhangfei829 and removed request for zhangfei829 September 24, 2026 06:51

@jhchouuu jhchouuu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

seems could be remove, i will try it on next time.

@zhangfei829 zhangfei829 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice work

@kawhil-amd
kawhil-amd merged commit 78b7a5f into ROCm:main Sep 24, 2026
15 checks passed
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.

3 participants