Skip to content

[None][perf] Size the one-shot AllReduce-fusion grid by occupancy - #18834

Open
kaiyux wants to merge 1 commit into
NVIDIA:mainfrom
kaiyux:perf/allreduce-oneshot-occupancy-grid
Open

kaiyux wants to merge 1 commit into
NVIDIA:mainfrom
kaiyux:perf/allreduce-oneshot-occupancy-grid

Conversation

@kaiyux

@kaiyux kaiyux commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Description

allreduce_fusion_kernel_launcher caps its grid at one cluster-group per SM:

grid_size = (std::min(sm_count, cluster_num * cluster_size) / cluster_size) * cluster_size;

For the two-shot kernel that cap is load-bearing. Its Barrier makes every block wait on the peer rank's block with the same blockIdx.x, and the flag array holds one entry per block up to kBarrierFlagCount, so a grid whose blocks are not all co-resident can deadlock.

The one-shot kernel has no such coupling — its Lamport handshake is per element and all of its loops are grid-strided — so the cap only costs it parallelism. One 256-thread block per SM occupies 8 of the 64 warps an SM holds on sm_100, which is too few to keep enough of the uncacheable peer loads it spins on in flight.

This PR sizes the one-shot path to the kernel's real occupancy, queried with cudaOccupancyMaxActiveBlocksPerMultiprocessor through a new get_max_blocks_per_sm helper placed next to the existing get_sm_count(). threads_per_block and cluster_size are computed by exactly the same code as before, the round-down is preserved, and the grid is still bounded by cluster_num * cluster_size. The two-shot path keeps the old budget.

At the shape measured below the grid goes (148,1,1) -> (592,1,1) at blockDim 256 — 148 SMs × 4 blocks, register-limited (REG 59, SHARED 1160 B on sm_100f) — so 8 → 32 warps/SM.

Measured effect

Serving Qwen3.6-35B-A3B-NVFP4 on 2×B200, attention TP2 + MoE EP2, ISL 1024 / OSL 6144, one-model MTP, against the same warmed server:

metric before after
AR-fusion kernel (per call) 30.74 µs 19.18 µs
exposed communication 2.147 ms/iter 1.374 ms/iter
decode iteration @ c=512 16.512 ms 15.501 ms (−6.12%)

Launch count and byte volume are unchanged; device idle is flat. Output throughput rises +2.30% on the mean of concurrency 64/128/256/512, tracking the grid multiplier across the band — weakest at c=64 (+0.88%, multiplier 1.30×), strongest at c=512 (+3.38%, multiplier 4.0×). TTFT, TPOT, ITL and E2EL all improved together at c=512; nothing was traded.

Below concurrency 32 the change is inert by construction: token_num there is smaller than sm_count, so cluster_num * cluster_size still selects the same grid.

Test Coverage

tests/unittest/_torch/multi_gpu/test_allreduce.py::test_allreduce_fusion_patterns — 42/42 passed on 2×B200 (all fusion patterns × hidden sizes × sequence lengths). This is a launch-geometry change with no new API surface, so it is covered by the existing pattern matrix rather than by new tests.

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.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • 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

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

🤖 Generated with Claude Code


Related PRs

Split out of a single branch; each one is cherry-picked onto main independently and can be reviewed and merged on its own — there are no ordering dependencies between them.

All five were measured on the same deployment (Qwen3.6-35B-A3B-NVFP4, 2×B200, attention TP2 + MoE EP2, ISL 1024 / OSL 6144, one-model MTP), so the per-PR numbers are not additive across the set.

Dev Engineer Review

  • Added get_max_blocks_per_sm using cudaOccupancyMaxActiveBlocksPerMultiprocessor.
  • One-shot grid sizing now uses kernel occupancy.
  • Two-shot grid sizing remains limited to one cluster per SM for barrier co-residency.
  • Existing block-size, cluster-size, round-down, and upper-bound logic remains unchanged.
  • The measured 2×B200 workload reduced AllReduce-fusion time by 37.6% and improved decode iteration time by 6.12%.
  • No configuration or test-list changes were found.

QA Engineer Review

No test changes. The existing AllReduce fusion pattern test passed 42/42 cases on 2×B200.

`allreduce_fusion_kernel_launcher` caps its grid at one cluster-group per SM:

    grid_size = (min(sm_count, cluster_num * cluster_size) / cluster_size) * cluster_size

For the two-shot kernel that cap is load-bearing. Its `Barrier` makes every
block wait on the peer rank's block with the same `blockIdx.x`, and the flag
array holds one entry per block up to `kBarrierFlagCount`, so a grid whose
blocks are not all co-resident can deadlock.

The one-shot kernel has no such coupling -- its Lamport handshake is per element
and all of its loops are grid-strided -- so the cap only costs it parallelism.
One 256-thread block per SM occupies 8 of the 64 warps an SM holds on sm_100,
which is too few to keep enough of the uncacheable peer loads it spins on in
flight.

Size the one-shot path to the kernel's real occupancy instead, queried with
`cudaOccupancyMaxActiveBlocksPerMultiprocessor` through a new
`get_max_blocks_per_sm` helper next to the existing `get_sm_count()`.
`threads_per_block` and `cluster_size` are computed by exactly the same code as
before, the round-down is preserved, and the grid is still bounded by
`cluster_num * cluster_size`. The two-shot path keeps the old budget.

At the shape below the grid goes (148,1,1) -> (592,1,1) at blockDim 256 --
148 SMs x 4 blocks, register-limited (REG 59, SHARED 1160 B on sm_100f) -- so
8 -> 32 warps/SM.

Measured serving Qwen3.6-35B-A3B-NVFP4 on 2xB200, attention TP2 + MoE EP2,
ISL 1024 / OSL 6144, one-model MTP, against the same warmed server:

    AR-fusion kernel        30.74 -> 19.18 us/call  (launch count and byte
                                                     volume unchanged)
    exposed communication   2.147 -> 1.374 ms/iter
    decode iteration       16.512 -> 15.501 ms      (-6.12%, device idle flat)

Output throughput rises 2.30% on the mean of concurrency 64/128/256/512,
tracking the grid multiplier across the band -- weakest at c=64 (+0.88%,
multiplier 1.30x), strongest at c=512 (+3.38%, multiplier 4.0x). TTFT, TPOT,
ITL and E2EL all improved together at c=512; nothing was traded.

Below concurrency 32 the change is inert by construction: `token_num` there is
smaller than `sm_count`, so `cluster_num * cluster_size` still selects the same
grid.

Tests: `tests/unittest/_torch/multi_gpu/test_allreduce.py::test_allreduce_fusion_patterns`
42/42 pass on 2xB200.

Signed-off-by: Kaiyu Xie <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a272828b-4fe2-40a6-b5b8-952d6a4238f3

📥 Commits

Reviewing files that changed from the base of the PR and between 4b9f3ae and 3b9a170.

📒 Files selected for processing (1)
  • cpp/tensorrt_llm/kernels/communicationKernels/allReduceFusionKernels.cu

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


Walkthrough

The change adds a CUDA occupancy helper and uses its result to size one-shot all-reduce fusion grids. Two-shot execution retains one cluster per SM. The copyright year is updated to 2026.

Changes

All-reduce launch sizing

Layer / File(s) Summary
Occupancy-based grid sizing
cpp/tensorrt_llm/kernels/communicationKernels/allReduceFusionKernels.cu
Adds get_max_blocks_per_sm and uses occupancy-derived sizing for one-shot Lamport kernels. Two-shot synchronized kernels continue to use one block cluster per SM. The copyright year changes to 2026.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 3b9a1

One-shot fused all-reduce launches now use available kernel occupancy to improve throughput, while synchronized two-shot launches retain their prior sizing behavior. No current merge-blocking risk remains.

Suggested reviewers: bowenfu

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description clearly explains the motivation, implementation, preserved two-shot behavior, measured impact, test coverage, and checklist status.
Title check ✅ Passed The title follows the repository format and clearly identifies the performance change to one-shot AllReduce-fusion grid sizing.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

auto kernel = params.trigger_completion_at_end
? &allreduce_fusion_kernel_oneshot_lamport<Pattern, DType, NRanks, Fp32Acc, true>
: &allreduce_fusion_kernel_oneshot_lamport<Pattern, DType, NRanks, Fp32Acc, false>;
block_budget = sm_count * get_max_blocks_per_sm(kernel, block_size);

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.

[P1] Preserve forward progress when increasing the one-shot grid. In the Lamport path, each CTA polls for peer data that may be published by a CTA that has yet to run, and CTA 0 waits for counter_ptr == gridDim.x. cudaOccupancyMaxActiveBlocksPerMultiprocessor estimates per-SM capacity. Multiplying it by SM count can overestimate residency for the actual cluster launch or when other work shares the GPU. If effective residency or block scheduling differs across ranks, polling CTAs can hold the slots needed by their peer producers. Can we keep the existing grid cap until the enlarged launch has a forward-progress argument, and cover cluster launches and concurrent GPU work with a multi-rank stress test?

This branch has not been deployed

No deployments
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.

2 participants