You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[None][fix] Acquire cluster-scope routing barriers in the GLM-5.2 TEP4 fused top-k routing kernels - #22712
The four fused top-k routing kernels of glm_5_2_nvfp4__sm_103__tep4/kernels/moe/ (moe_decode_topk_routing_rep.py, moe_topk_routing_push.py, moe_topk_routing_push_wide.py, moe_topk_routing_push_wide_rep.py) run as an 8-CTA cluster and exchange two words per expert across it with st.async into a peer CTA's shared memory (_compat48.store_async, st.async.shared::cluster.mbarrier::complete_tx::bytes):
exchange
peer writes
this CTA waits at
reads after the wait
expert counts, every rank to rank 0
each CTA's threads tidx < EXPERTS store their count into rank 0's all_counts, completing rank 0's count_bar
all_counts[r * EXPERTS + tidx] for every rank r (the expert totals, tile count and mn_limit)
permutation bases, rank 0 to every rank
rank 0 stores each rank's base[tidx], completing that rank's base_bar
every CTA, prims.mbarrier_try_wait_parity(base_bar, 0)
base[my_expert] (the permuted row index of each token's top-k slot)
Both waits are the default mbarrier.try_wait.parity, which acquires at CTA scope (the PTX ISA's default .scope for mbarrier.test_wait / mbarrier.try_wait). The completing operation is the peer's complete-tx, which the ISA defines as a release at cluster scope (st.async: "the complete-tx operation on the mbarrier has .release semantics at the .cluster scope"). Under the PTX memory consistency model a release and an acquire synchronize only when each specifies a scope that includes the thread executing the other; a CTA-scope acquire does not include a thread of another CTA. So no synchronizes-with edge exists between the peer's stores and this CTA's reads of all_counts / base, and the reads are not ordered after the stores. A stale all_counts entry gives a wrong expert total (a wrong tile count or mn_limit), a stale base a wrong permuted index (two tokens in one slot, or a hole).
Change (the eight waits, nothing else): each wait becomes a relaxed cluster-scope try-wait followed by an acquire fence restricted to shared::cluster, through the DSL's own primitives (prims.mbarrier_try_wait_parity(..., scope=MBarrierScope.CLUSTER, order=MemOrder.RELAXED) and prims.fence_sync_restrict(MemOrder.ACQUIRE)), which lower to mbarrier.try_wait.parity.relaxed.cluster.shared::cta.b64 and fence.acquire.sync_restrict::shared::cluster.cluster. This is the idiom of #21843 and of the sibling split-K kernels of this folder in #21846, and the ISA's own example for acquiring shared memory a peer CTA wrote through the generic proxy; the restricted fence adds no SASS instruction, unlike an .acquire.cluster wait, which invalidates L1 after every poll. The same defect and fix: flashinfer-ai/flashinfer#7443, #8853, #8854, #9224, NVIDIA/TensorRT-LLM #21843, #21846, #21847, lightseekorg/tokenspeed#3261.
Hardware verification
The patched kernels were compiled for sm_103a at the shipped configurations (rep T=64 nrep=8, push T=64, wide T=128 cluster 8, wide_rep T=128 nrep=8 cluster 8) and the generated IR shows the relaxed cluster-scope wait and the restricted acquire fence at every changed site. They were not run on hardware this round. No wrong result has been observed with the unpatched kernels and none is expected on current parts: payload and complete-tx travel together on the DSMEM path. The ISA does not promise that, which is why the sibling kernels and FlashInfer made the same change; the code is non-conforming and the fix costs nothing measurable.
Test Coverage
Existing tests exercise the kernels unchanged: tests/unittest/_torch/modeling_v2/models/glm_moe_dsa/glm_5_2_nvfp4__sm_103__tep4/ops/moe/test_modeling_v2_cute_dsl_moe_topk_routing.py, ..._moe_topk_routing_rep.py, ..._moe_topk_routing_wide_rep.py and ..._moe_prefill_topk_routing_rep.py. No new test: this is a memory-model conformance fix with no deterministic failure to test for. If a structural source check is wanted, the one of #21846 (gemm/test_modeling_v2_cute_dsl_tgv_gemm_sync.py) can be extended with the four files.
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.
Any new dependencies have been scanned for license and vulnerabilities
The change replaces eight default-scope mbarrier waits in four GLM-5.2 TEP4 top-k routing kernels. The new waits use relaxed cluster-scope try-waits followed by shared::cluster acquire fences. This fixes a memory-ordering gap for peer st.async stores.
The author did not run the kernels on hardware for this change. Verify the memory-ordering fix and the absence of regressions on SM103 before relying on it.
The diff touches only the four kernel files (+76/-8). No test, config, or public API changes.
QA Engineer Review
No test changes.
Per-File QA Perspective
moe_decode_topk_routing_rep.py: Verify routing results match the baseline for decode shapes. Waits now cover the expert-count and base-map transfers.
moe_topk_routing_push.py: Verify routing results match the baseline. Waits now cover remote histogram and base writes before all_counts and base reads.
moe_topk_routing_push_wide.py: Verify routing results match the baseline for wide configurations. Both waits changed.
moe_topk_routing_push_wide_rep.py: Verify routing results match the baseline for wide repeated configurations. Histogram and base waits changed.
…sed top-k routing kernels
The four fused top-k routing kernels (moe_decode_topk_routing_rep,
moe_topk_routing_push, moe_topk_routing_push_wide,
moe_topk_routing_push_wide_rep) exchange the per-expert counts and the
permutation bases across the 8-CTA cluster with st.async into a peer
CTA's shared memory, completing the peer's count_bar / base_bar through
complete-tx, which the PTX ISA defines as a release at cluster scope.
The receiving CTAs waited with the default mbarrier.try_wait.parity,
which acquires at CTA scope only, so rank 0's reads of all_counts and
every CTA's reads of base after the wait were not ordered after the
peers' stores under the PTX memory consistency model. Each of the eight
waits becomes a relaxed cluster-scope try_wait followed by
fence.acquire.sync_restrict::shared::cluster.cluster, the idiom the other
DSMEM mailbox kernels of this repository use.
Signed-off-by: Bastian Hagedorn <bhagedorn@nvidia.com>
No actionable comments were generated in the recent review.
Walkthrough
Four MoE routing kernels now use cluster-scope relaxed mbarrier waits followed by acquire fences before reading transferred expert counts and routing bases. Routing and assignment logic remain unchanged.
Changes
MoE routing synchronization
Layer / File(s)
Summary
Expert-count and routing-base hand-offs tensorrt_llm/.../kernels/moe/moe_decode_topk_routing_rep.py, tensorrt_llm/.../kernels/moe/moe_topk_routing_push.py, tensorrt_llm/.../kernels/moe/moe_topk_routing_push_wide.py, tensorrt_llm/.../kernels/moe/moe_topk_routing_push_wide_rep.py
The four routing kernels replace default-scope waits with cluster-scope relaxed waits and acquire fences before reading all_counts and base.
This change makes the memory ordering explicit when the MoE routing kernels read expert counts and routing bases that peer CTAs wrote. It strengthens synchronization correctness without altering routing results. Nothing indicates a current failure, and merging carries minimal risk.
Architecture risk: Low · up to e614c
The change affects 1 system.
Changed systems:tensorrt_llm
Architecture concerns
No architecture-level concerns identified.
Review details
Systems and components
observed — tensorrt_llm (service) was modified; 4 changed files map to changed impact.
Before / after behavior
observed — Modified behavior in tensorrt_llm/_torch/modeling_v2/models/glm_moe_dsa/glm_5_2_nvfp4__sm_103__tep4/kernels/moe/moe_decode_topk_routing_rep.py: The expert-count transfer wait now specifies relaxed cluster scope and is followed by an acquire fence before reading all_counts; the previous default-scope wait is removed.
observed — Modified behavior in tensorrt_llm/_torch/modeling_v2/models/glm_moe_dsa/glm_5_2_nvfp4__sm_103__tep4/kernels/moe/moe_decode_topk_routing_rep.py: The base-map transfer wait now specifies relaxed cluster scope and is followed by an acquire fence before reading base; the previous default-scope wait is removed.
observed — Modified behavior in tensorrt_llm/_torch/modeling_v2/models/glm_moe_dsa/glm_5_2_nvfp4__sm_103__tep4/kernels/moe/moe_topk_routing_push.py: Before reading all_counts, rank 0 now polls count_bar at cluster scope with relaxed ordering, then issues a shared-cluster acquire fence; this replaces the default-scope wait.
observed — Modified behavior in tensorrt_llm/_torch/modeling_v2/models/glm_moe_dsa/glm_5_2_nvfp4__sm_103__tep4/kernels/moe/moe_topk_routing_push.py: Before reading base, each participating CTA thread now polls base_bar at cluster scope with relaxed ordering, then issues a shared-cluster acquire fence; this replaces the default-scope wait.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: acquire-side cluster-scope barrier fix in the GLM-5.2 TEP4 fused top-k routing kernels. It follows the [None][fix] format and matches the eight waits in the four kerne…
Description check
The description covers the problem, the change, hardware verification status, test coverage, and the checklist. It explains the memory-model issue with the peer st.async writes and the cluster-scope f…
Linked Issues check
The only linked issue is #7443. It is closed and completed, so it supplies background only. No active directly linked target remains, so no linked-issue coding requirements apply to this pull request.…
Out of Scope Changes check
The whole-PR summary (merge base 6533070 to head e614cf5) lists changes in four kernel files under glm_5_2_nvfp4__sm_103__tep4/kernels…
Full details: Title check
Explanation
The title names the main change: acquire-side cluster-scope barrier fix in the GLM-5.2 TEP4 fused top-k routing kernels. It follows the [None][fix] format and matches the eight waits in the four kernels. It does not restate the memory-model rationale, which is acceptable for a title.
Full details: Description check
Explanation
The description covers the problem, the change, hardware verification status, test coverage, and the checklist. It explains the memory-model issue with the peer st.async writes and the cluster-scope fix. It gives the affected files and the existing tests. It does not fill the template's 'Description' section in the short form the template asks for, and the checklist is unchecked, which is expected. The template also has a 'Test Coverage' section, and the author fills it in. The only gap is that the description does not name the files in the title-format template, but it does list them.
Full details: Linked Issues check
Explanation
The only linked issue is #7443. It is closed and completed, so it supplies background only. No active directly linked target remains, so no linked-issue coding requirements apply to this pull request. The PR description cites #21843, #21846, #21847, #7443, #8853, #8854, #9224, and lightseekorg/tokenspeed#3261 as related context. None of them is a linked requirement source here. Their acceptance criteria are not assessed.
Full details: Out of Scope Changes check
Explanation
The whole-PR summary (merge base 6533070 to head e614cf5) lists changes in four kernel files under glm_5_2_nvfp4__sm_103__tep4/kernels/moe/: moe_decode_topk_routing_rep.py, moe_topk_routing_push.py, moe_topk_routing_push_wide.py, and moe_topk_routing_push_wide_rep.py. Each file shows +19/-2 lines. The summaries describe only the eight mbarrier waits and their acquire fences, which matches the PR description's stated change. The PR adds no new test and no unrelated edits are described. The summary does not show any change unrelated to the stated synchronization fix. The source diff was not read line by line, so this result rests on the summary and the PR description.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.
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
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.
Description
The four fused top-k routing kernels of
glm_5_2_nvfp4__sm_103__tep4/kernels/moe/(moe_decode_topk_routing_rep.py,moe_topk_routing_push.py,moe_topk_routing_push_wide.py,moe_topk_routing_push_wide_rep.py) run as an 8-CTA cluster and exchange two words per expert across it withst.asyncinto a peer CTA's shared memory (_compat48.store_async,st.async.shared::cluster.mbarrier::complete_tx::bytes):tidx < EXPERTSstore their count into rank 0'sall_counts, completing rank 0'scount_barprims.mbarrier_try_wait_parity(count_bar, 0)all_counts[r * EXPERTS + tidx]for every rankr(the expert totals, tile count andmn_limit)base[tidx], completing that rank'sbase_barprims.mbarrier_try_wait_parity(base_bar, 0)base[my_expert](the permuted row index of each token's top-k slot)Both waits are the default
mbarrier.try_wait.parity, which acquires at CTA scope (the PTX ISA's default.scopeformbarrier.test_wait/mbarrier.try_wait). The completing operation is the peer's complete-tx, which the ISA defines as a release at cluster scope (st.async: "the complete-tx operation on the mbarrier has .release semantics at the .cluster scope"). Under the PTX memory consistency model a release and an acquire synchronize only when each specifies a scope that includes the thread executing the other; a CTA-scope acquire does not include a thread of another CTA. So no synchronizes-with edge exists between the peer's stores and this CTA's reads ofall_counts/base, and the reads are not ordered after the stores. A staleall_countsentry gives a wrong expert total (a wrong tile count ormn_limit), a stalebasea wrong permuted index (two tokens in one slot, or a hole).Change (the eight waits, nothing else): each wait becomes a relaxed cluster-scope try-wait followed by an acquire fence restricted to
shared::cluster, through the DSL's own primitives (prims.mbarrier_try_wait_parity(..., scope=MBarrierScope.CLUSTER, order=MemOrder.RELAXED)andprims.fence_sync_restrict(MemOrder.ACQUIRE)), which lower tombarrier.try_wait.parity.relaxed.cluster.shared::cta.b64andfence.acquire.sync_restrict::shared::cluster.cluster. This is the idiom of #21843 and of the sibling split-K kernels of this folder in #21846, and the ISA's own example for acquiring shared memory a peer CTA wrote through the generic proxy; the restricted fence adds no SASS instruction, unlike an.acquire.clusterwait, which invalidates L1 after every poll. The same defect and fix: flashinfer-ai/flashinfer#7443, #8853, #8854, #9224, NVIDIA/TensorRT-LLM #21843, #21846, #21847, lightseekorg/tokenspeed#3261.Hardware verification
The patched kernels were compiled for sm_103a at the shipped configurations (rep T=64 nrep=8, push T=64, wide T=128 cluster 8, wide_rep T=128 nrep=8 cluster 8) and the generated IR shows the relaxed cluster-scope wait and the restricted acquire fence at every changed site. They were not run on hardware this round. No wrong result has been observed with the unpatched kernels and none is expected on current parts: payload and complete-tx travel together on the DSMEM path. The ISA does not promise that, which is why the sibling kernels and FlashInfer made the same change; the code is non-conforming and the fix costs nothing measurable.
Test Coverage
Existing tests exercise the kernels unchanged:
tests/unittest/_torch/modeling_v2/models/glm_moe_dsa/glm_5_2_nvfp4__sm_103__tep4/ops/moe/test_modeling_v2_cute_dsl_moe_topk_routing.py,..._moe_topk_routing_rep.py,..._moe_topk_routing_wide_rep.pyand..._moe_prefill_topk_routing_rep.py. No new test: this is a memory-model conformance fix with no deterministic failure to test for. If a structural source check is wanted, the one of #21846 (gemm/test_modeling_v2_cute_dsl_tgv_gemm_sync.py) can be extended with the four files.PR Checklist
Please review the following before submitting your PR:
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Dev Engineer Review
shared::clusteracquire fences. This fixes a memory-ordering gap for peerst.asyncstores.QA Engineer Review
No test changes.
Per-File QA Perspective
moe_decode_topk_routing_rep.py: Verify routing results match the baseline for decode shapes. Waits now cover the expert-count and base-map transfers.moe_topk_routing_push.py: Verify routing results match the baseline. Waits now cover remote histogram and base writes beforeall_countsandbasereads.moe_topk_routing_push_wide.py: Verify routing results match the baseline for wide configurations. Both waits changed.moe_topk_routing_push_wide_rep.py: Verify routing results match the baseline for wide repeated configurations. Histogram and base waits changed.