Repository navigation
[SM100] Mega MoE: batch the dispatch counters and let every SM wait on the NVLink barrier - #147
Merged
Merged
Conversation
…n the NVLink barrier Dispatch prologue of the fp8xfp4 kernel: - a dispatch thread issues all of its per-expert send-count atomics before it stores any result, and SM 0 does the same with its count-push loads - an SM without tokens for an expert no longer touches that expert's counter; SM 0 writes the arrival count into the status it pushes - nvlink_barrier takes thread 0's copy of the barrier counter; with it every SM polls the signal word and the trailing grid sync is skipped Outputs are bitwise identical. Co-Authored-By: Claude Fable 5.2 <[email protected]>
…load Co-Authored-By: Claude Fable 5.2 <[email protected]>
…pert loop - nvlink_barrier decodes the status once and uses the same wait loop for SM 0 and the SMs that wait on the signal word; the counter copy is const and only passed to the barrier that reads it - the dispatch prologue's per-thread expert loops go through one helper and keep the send status in 32 bits Outputs are bitwise identical. Co-Authored-By: Claude Fable 5.2 <[email protected]>
… check the counter copy - nvlink_barrier asserts on SM 0 that the caller's counter copy decodes to the same signal word as the live counter, and its timeout print names the SM - comments state what the all-SM wait relies on: the next barrier's prologue grid sync, and the grid sync before the count push - the combine's two waits share one timeout print Outputs are bitwise identical. Co-Authored-By: Claude Fable 5.2 <[email protected]>
zcnrex
marked this pull request as ready for review
November 11, 2026 20:51
This was referenced Nov 12, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
At decode sizes the fp8xfp4 Mega MoE kernel is a chain of memory round trips, and three of them sit in the dispatch prologue before any token can be pulled:
atom.global.add.u64per expert on the send counters, including experts it sends nothing to. A dispatch thread issues them one at a time, each waiting for the previous result. With 448 experts that is 3.5 serial round trips per thread on counters all 210 SMs contend for.Change
Batched counters. A dispatch thread issues all of its send-count atomics, then stores the results. SM 0 issues all of its count-push loads, then the remote stores.
Counters only for SMs with tokens. An SM with no tokens for an expert skips that expert's atomic. The upper half of the counter (SM arrivals) is no longer accumulated; SM 0 writes
kNumSMsinto the status it pushes, after the grid sync that already orders it behind every SM. The receiver's check (kNumSMs * kNumRanks) is unchanged.Every SM waits on the barrier signal.
nvlink_barriertakes an optionalknown_counter: thread 0's copy of the barrier counter, read at the start of the dispatch role and incremented locally per barrier. With it, the non-zero SMs poll the signal word themselves and the trailing grid sync becomes a plain CTA barrier. The copy is read before the CTA's first grid sync, and SM 0 only advances the counter after that grid sync, so the phase and sign cannot be stale. Callers that do not pass it keep the old behaviour (sm100_bf16_mega_moe,sm90_fp8_mega_moe).Combine waits per slot. The combine waited for the ranks of all of a token's experts before issuing its first load. Now each slot waits for its own rank right before its load, so the shared slot and the slots of ranks that are already done load while the rest are awaited. Slot order is unchanged. The post-expert-norm path keeps the single wait, since it reads every slot's sum first.
Outputs are bitwise identical to
dev.Benchmark
Setup:
fp8_fp4_mega_moeon Vera Rubin (CC 10.7), 448 experts, top-6, 1 shared expert, hidden 5120, intermediate 2304, K=64 MMA and SIMT pull as SGLang runs it.dev.Each change measured on its own at 32 ranks, 256 tokens per rank: batched counters 0.971, plus the barrier 0.949, plus the token-owning counters 0.940.
End to end: DeepSeek-V4.1-Flash on SGLang, DEP32 decode, 64 requests per rank at 128K context, ABBA with two runs per arm: decode step 0.989 of
dev.The per-slot combine wait on top of the rest (this PR / previous commit), 32 ranks: 0.997 at 64 and 256 tokens per rank, 0.982 at 896; 16 ranks: 0.996 at 256, 0.987 at 1024. End to end at DEP32 with 224 requests per rank, ABBA with two runs per arm: decode step 0.995; at 64 requests per rank 1.000.
Tried and left out: a grid sync that arrives with
red.releaseinstead ofatom.release(1.003 of the batched version), andredinstead of skipping for the zero-count experts (1.009). Also measured at 32 ranks, 256 tokens per rank, relative to this PR without the combine change:Tests
devin the multi-rank rig at 1, 7, 64, 256 and 1000 tokens per rank with 112 and 448 experts on 8 ranks, and at 32, 256 and 1024 tokens per rank on 2, 4, 16 and 32 ranks.tests/test_mega_moe.pyneeds DeepEP for its correctness path and was not run.🤖 Generated with Claude Code