Skip to content

Commit d7442af

Browse files
foreverrookiecodex
andcommitted
Fix MegaMoE combine readiness on CUDA graph replay
CUDA graph replay can reuse the kernel grid ID. Clear local peer-ready flags before the existing pull barrier so a later replay cannot consume the previous invocation's combine data when inputs change. Preserve the workspace layout and existing barriers. Validated on 8 B300 ranks with input staging, unequal/empty source ranks, and successive CUDA graph replays with updated inputs (3 tests passed per rank). Co-authored-by: Codex <[email protected]> Signed-off-by: foreverrookie <[email protected]>
1 parent 78b6900 commit d7442af

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎deep_gemm/include/deep_gemm/impls/sm100_fp8_fp4_mega_moe.cuh‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,13 @@ sm100_fp8_fp4_mega_moe_impl(void* y,
388388

389389
// Write expert count
390390
if (sm_idx == 0) {
391-
// Push this launch's grid index to every peer for tagging combine readiness; +1 differs from a zeroed workspace
391+
// CUDA graph replay can reuse grid IDs. Clear local readiness before the pull barrier,
392+
// which separates these resets from every peer's current L2 completion notification.
392393
DG_STATIC_ASSERT(kNumRanks <= kNumDispatchThreads, "Insufficient threads for the grid index push");
393-
if (thread_idx < kNumRanks)
394+
if (thread_idx < kNumRanks) {
395+
ptx::st_rel_sys(workspace.get_combine_ready_grid_idx_ptr(thread_idx), uint64_t(0));
394396
*sym_buffer.map(workspace.get_peer_grid_idx_ptr(sym_buffer.rank_idx), thread_idx) = ptx::get_grid_idx() + 1;
397+
}
395398
__syncwarp();
396399

397400
#pragma unroll

‎deep_gemm/include/deep_gemm/layout/mega_moe.cuh‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ struct alignas(128) MegaMoESignals {
6969
uint32_t shared_l2_task_count;
7070

7171
// Combine readiness: `combine_ready_grid_idx[peer] == own grid index` means the peer's L2 writes into this
72-
// rank are done; grid indices are unique per launch, so no reset is needed. Peers push theirs during dispatch.
72+
// rank are done. Dispatch resets readiness before the pull barrier because graph replay can reuse grid indices.
73+
// Peers push their current grid indices during dispatch.
7374
alignas(128) uint64_t combine_ready_grid_idx[kNumMaxRanks];
7475
alignas(128) uint64_t peer_grid_idx[kNumMaxRanks];
7576

0 commit comments

Comments
 (0)