Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Symmetric memory | A buffer allocated at the same offset on every GPU of a group, so a kernel on GPU 3 can compute the address of “the same buffer on GPU 5” and read or write it directly. |
| One-sided communication | A GPU writes into (put) or reads from (get) a peer’s memory without the peer running any code. |
| Device-initiated (GPU-initiated) communication | The kernel itself issues the transfer — over NVLink with ordinary stores, or over the network by building RDMA requests on the GPU — instead of the CPU or a separate collective launch. |
| NVSHMEM | NVIDIA’s library for symmetric memory and device-initiated put/get/signal across GPUs and nodes (an implementation of OpenSHMEM). |
| NCCL device API / GIN | Since NCCL 2.28, kernels can call NCCL directly: load/store access (LSA) over NVLink, multicast (Multimem, NVLink SHARP) and GPU-Initiated Networking (GIN) over RDMA. |
| Multimem / NVLS | NVSwitch-based multicast and in-switch reduction: one multimem.ld_reduce returns the sum of a value across all GPUs (9.c, 9.f). |
| Lamport-style flags | Using the data itself as the “ready” signal: buffers are pre-filled with an impossible value, and a reader spins until the value changes. No separate barrier. |
| SM budget | How many SMs a communication kernel occupies. Every SM spent on communication is not computing. |
1. What is it?#
Lessons 9.f and 9.g covered what collectives cost and how NCCL picks algorithms. This lesson is about the kernels that serving engines write themselves when NCCL’s general-purpose collectives are too slow or too separate from the compute:
- Fused all-reduce kernels for tensor parallelism: one kernel that all-reduces the attention or MLP output and does the residual add, RMSNorm and quantisation that follow.
- All-to-all kernels for expert parallelism: DeepEP, pplx-kernels, NCCL EP, FlashInfer’s MNNVL all-to-all — dispatch and combine written as custom kernels over symmetric memory and RDMA (14.e).
- The device-side communication layers they are built on: CUDA IPC and peer access, PyTorch symmetric memory, NVSHMEM, and the NCCL device API.
- Overlap techniques: SM partitioning, copy engines, and fusing communication into GEMM epilogues or whole layers (25.h’s Mega MoE).
Facts checked on 13 November 2026: NCCL 2.32.6, NVSHMEM 3.8.0, DeepEP V2.5, FlashInfer 0.7.4, vLLM v0.32.0.
2. Why does it matter?#
At decode, communication is latency-bound (9.f): a tensor-parallel all-reduce of 16 KB costs a few microseconds of synchronisation regardless of bandwidth, twice per layer, 80+ layers per token. Each of those microseconds is on the critical path. For MoE with wide EP, dispatch and combine are two all-to-alls per layer and can be the biggest item in the step (14.e, 14.h).
Three costs dominate, and general collectives cannot remove them:
- Kernel boundaries: a collective is its own launch, followed by more launches for the elementwise work that uses its result, each with a fixed cost and a full HBM round trip.
- Synchronisation: barrier rounds between GPUs before and after each transfer.
- Serialisation with compute: the GPU waits while data moves, unless something overlaps it.
3. Simple analogy#
Eight cooks each make part of a sauce, and the parts must be combined before plating.
- NCCL as a separate step: everyone stops, a runner collects and combines the parts, delivers the sauce back, then each cook separately salts it, stirs it and plates it, washing the bowl between steps.
- Fused all-reduce: each cook pours their part straight into everyone else’s bowl (symmetric memory), and whoever’s bowl is complete immediately salts, stirs and plates without washing up in between.
- Lamport flags: instead of shouting “done!”, each cook knows a bowl is ready because it is no longer empty — the content is the signal.
4. Tiny example: what fusion saves in tensor-parallel decode#
A cost model of the sequence after each attention and MLP block in a TP-8 H100 deployment (hidden 8,192, BF16): all-reduce, residual add, RMSNorm, FP8 quantise. Unfused = four kernels; fused = one. The fixed costs (4 µs per all-reduce, 2 µs per extra kernel inside a CUDA graph) are assumptions in the range engines measure.
// arfusion.go — a cost model of "all-reduce, then residual add, RMSNorm and FP8 quantise"
// as four kernels versus one fused kernel, for tensor-parallel decode and prefill on 8 GPUs.
package main
import "fmt"
const (
gpus = 8
hidden = 8192
nvlinkGBs = 450.0 // per-GPU NVLink bandwidth one way (H100 class), GB/s
hbmGBs = 3350.0 // HBM bandwidth, GB/s
arLatUs = 4.0 // fixed cost of a one-shot NVLink all-reduce kernel (sync + launch), µs
kernelUs = 2.0 // fixed cost of each extra small kernel inside a CUDA graph, µs
allReduce = 2 // all-reduces per transformer layer (after attention and after the MLP)
layers = 80
)
func us(bytes, gbs float64) float64 { return bytes / (gbs * 1e3) } // bytes / (GB/s) in µs
func main() {
fmt.Println("tokens activation 4 kernels fused saved per step (80 layers)")
for _, tokens := range []int{1, 64, 512, 4096} {
s := float64(tokens * hidden * 2) // BF16 activation bytes on each GPU
// One-shot all-reduce: each GPU reads the other 7 GPUs' copies over NVLink.
ar := arLatUs + us(float64(gpus-1)*s, nvlinkGBs)
// Unfused: AR writes S; add reads 2S writes S; RMSNorm reads S writes S; quant reads S writes S/2.
unfused := ar + us(s, hbmGBs) +
kernelUs + us(3*s, hbmGBs) +
kernelUs + us(2*s, hbmGBs) +
kernelUs + us(1.5*s, hbmGBs)
// Fused: the reduction result never leaves registers; read residual, write residual + FP8 output.
fused := ar + us(2.5*s, hbmGBs)
saved := (unfused - fused) * allReduce * layers / 1000
fmt.Printf("%6d %7.0f KB %7.1f µs %5.1f µs %6.2f ms\n", tokens, s/1024, unfused, fused, saved)
}
}tokens activation 4 kernels fused saved per step (80 layers)
1 16 KB 10.3 µs 4.3 µs 0.96 ms
64 1024 KB 28.7 µs 21.1 µs 1.21 ms
512 8192 KB 159.3 µs 140.7 µs 2.96 ms
4096 65536 KB 1204.2 µs 1098.0 µs 16.99 ms- At batch 1, fusion removes more than half of the post-attention/MLP time, about 1 ms on a decode step that may take 10–15 ms: 7–10 % end to end from one kernel.
- At large token counts the one-shot algorithm itself is the wrong choice (it moves 7× the data); engines switch to two-shot, NVLS or NCCL there (9.f). Fusion still saves the HBM round trips.
5. Technical explanation#
Building blocks for device-side communication#
| Layer | What a kernel can do | Scope | Used by |
|---|---|---|---|
| CUDA IPC + peer access | plain loads/stores to a peer’s buffer over NVLink | one node (or one NVL72 via MNNVL fabric handles) | vLLM custom_all_reduce, TRT-LLM all-reduce |
PyTorch symmetric memory (torch.distributed._symmetric_memory) | empty + rendezvous give peer pointers and signal pads; ops such as multimem_all_reduce_, two_shot_all_reduce_ | NVLink domain | vLLM symm_mem.py, DeepGEMM Mega MoE (PyTorch ≥ 2.9) |
| NVSHMEM 3.8 | nvshmem_malloc symmetric heap; device put/get/signal/wait_until; IBGDA (the GPU writes RDMA work requests itself) | NVLink and RDMA, multi-node | FlashInfer, Triton-distributed, older DeepEP |
| NCCL device API (2.28+) | LSA (load/store over NVLink), Multimem (NVLS multicast and reduce), GIN (put/signal over RDMA) from inside a kernel | NVLink and RDMA | DeepEP V2, NCCL EP, NCCL’s own symmetric kernels |
PTX multimem.* | multimem.ld_reduce, multimem.st, multimem.red on an NVLS multicast address | NVSwitch systems | NVLS all-reduce kernels, CUTLASS distributed examples |
The trend in 2025–2026 is consolidation onto NCCL’s device API: NCCL 2.28 (October 2025) introduced it, later releases added GIN transports (DOCA GPUNetIO, sockets, EFA), and DeepEP V2.5 removed its NVSHMEM backend entirely in favour of NCCL GIN.
Fused all-reduce kernels#
The design that FlashInfer’s trtllm_allreduce_fusion (from TensorRT-LLM) and vLLM’s fused paths
follow:
setup (once): symmetric workspace on every rank, pre-filled with a sentinel (e.g. -0.0) — "Lamport init"
per call, every rank, one kernel:
1. write my partial sum into slot[my_rank] of every peer's buffer (one-shot)
or into the owner of each chunk (two-shot: reduce-scatter half)
2. spin on my buffer until no element equals the sentinel (data = flag; no barrier)
3. sum the N slots in registers (FP32), add the residual, RMSNorm,
quantise to FP8/FP4 with block scales in the GEMM's layout (25.g)
4. write the normalised output and the new residual; reset the slots to the sentinel
(three rotating buffers so resetting never races with the next call)FlashInfer exposes the fused patterns as an enum (kARResidualRMSNorm, kARResidualRMSNormFP8Quant,
kARResidualRMSNormFP4Quant, MXFP8 and per-token-group FP8 variants), and MoE variants that fold
the expert-output reduction in (trtllm_moe_allreduce_fusion). On NVSwitch systems, an NVLS version
replaces steps 1–3’s N reads with one multimem.ld_reduce per element: the switch does the sum.
The Lamport trick, carefully. It requires a sentinel that the real data can never produce (−0.0 works because the producer canonicalises it to +0.0), stores that are not torn (16-byte vector stores), and memory ordering such that the reader cannot see the sentinel overwritten before the rest of the 16-byte element. It saves one or two cross-GPU barrier round trips per call — microseconds, which at decode is the whole game.
Expert-parallel all-to-all: DeepEP and friends#
DeepEP’s history illustrates the design space (14.e has the serving view):
- V1 (2025): two kernel families on NVSHMEM. Normal (high-throughput) kernels for prefill: hierarchical (RDMA to the destination node once, then NVLink fan-out), FP8 dispatch, and a configurable number of SMs. Low-latency kernels for decode: pure RDMA with IBGDA, CUDA-graph compatible, and a “hook” mode in which the receive completes without occupying SMs, so the GPU can compute while data lands.
- V2 (2026): one
EPBufferinterface for both, an expanded layout ready for grouped expert GEMMs (25.h), larger scale-up and scale-out domains, analytical SM and queue-pair counts (no auto-tuning), JIT-compiled kernels (DeepJIT), and the NCCL GIN backend. - V2.5: V1 and its NVSHMEM backend removed; requires NCCL ≥ 2.32.3 and PyTorch ≥ 2.10. Its README now states that EP dispatch and combine require SMs (“zero-SM RDMA EP is not supported”), so budget SMs for it.
Alternatives in engines (14.e): pplx-kernels, NCCL EP (an NCCL API extension released in June 2026, built on LSA and GIN, CUDA-graph compatible), FlashInfer MNNVL all-to-all (one-sided and two-sided across an NVL72), MoRI on AMD, and Mooncake EP / NIXL EP.
What all of them do inside the kernel:
dispatch: read topk_ids → per-destination counts (and a layout handshake) →
quantise rows to FP8 while packing → put rows into the destination's symmetric
receive buffer, already in expert-major order → signal
combine: put expert outputs back to the token's home rank → wait →
weighted sum of the k results (optionally fused with the shared expert and the residual)Overlap: three ways to hide communication#
- Spatial partitioning (SM budget). A communication kernel runs on 8–24 SMs while compute kernels use the rest, on separate streams. Simple, but the compute loses those SMs for the whole step. DeepEP’s and NCCL’s SM counts are exactly this knob.
- Copy engines. DMA engines move data with zero SMs. NCCL 2.28 added CE collectives for
all-gather and all-to-all within an NVLink domain (
NCCL_CTA_POLICY_ZEROwith symmetric windows). Good for large transfers; higher fixed latency than an SM kernel. - Fusion into compute. Communication becomes part of a compute kernel’s tile loop: a GEMM whose
epilogue writes each finished output tile straight into peers’ memory (GEMM + reduce-scatter or
all-reduce), or whose producer warp pulls remote tiles (all-gather + GEMM). CUTLASS 4.8’s CuTe DSL
ships Blackwell examples (
distributed_gemm_all_reduce_blackwell.py,distributed_all_gather_gemm_blackwell.py,all_reduce_one_shot_lamport.py,all_reduce_two_shot_multimem.py); DeepGEMM’s Mega MoE and FlashInfer’scake_gemm_allreduceare production examples. Micro-batch overlap (two-batch overlap, 14.h) is the coarse-grained version of the same idea at the scheduler level.
6. Under the hood: a one-shot NVLink all-reduce kernel#
grid: a few CTAs per GPU; each CTA owns a slice of the vector
1. (optional) wait until every peer has finished the *previous* call on this buffer
-> avoided with rotating buffers + Lamport sentinels
2. st.global.v4 peer[r].buf[my_rank][slice] = my_partial[slice] for r in peers (NVLink stores)
3. ld.volatile.v4 spin on my.buf[*][slice] until != sentinel (polling)
4. sum in FP32, add residual, RMSNorm (needs the full row: a CTA owns whole rows), quantise
5. st my.buf[*][slice] = sentinel (into the buffer that will be reused two calls later)Step 4’s “a CTA owns whole rows” is the catch for RMSNorm fusion: the normalisation needs the sum of squares over the hidden dimension, so the reduction is partitioned by tokens, not by arbitrary slices. For two-shot, the reduce-scatter half gives each rank whole rows, which is why two-shot + norm is natural: reduce-scatter, normalise your rows, all-gather the normalised (and already quantised, so smaller) rows.
7. Performance implications#
- Decode TP: fusion first, algorithm second. The model above shows fixed costs dominate below ~1 MB. Removing launches and barriers beats faster wires.
- SM budgets are a hidden tax. 20 SMs of 132 for a communication kernel is 15 % of the GPU’s compute for as long as it runs. Prefer zero-SM paths (copy engines) for big transfers and fused designs for small ones.
- Overlap only helps if there is independent work. A single decode micro-batch has none; that is why engines split batches (two-batch overlap) or fuse communication into the GEMM.
- Topology decides. One-shot and Lamport tricks need full NVLink connectivity. On PCIe-only
servers engines use different kernels (FlashInfer’s
pcie_ipccollectives, vLLM’sflashinfer_pcie_ipc_all_reduce.py) or NCCL.
8. Production implications#
- Know which all-reduce your engine uses. vLLM v0.32.0 has custom all-reduce, a “quick”
quantised all-reduce on ROCm, PyTorch symmetric memory, FlashInfer fused all-reduce and NCCL paths
(
vllm/distributed/device_communicators/); the start-up log says which is active (9.f). - Version coupling is tight. DeepEP V2.5 pins NCCL ≥ 2.32.3; PyTorch and DeepEP must load the same NCCL library; NVSHMEM-based components need matching transports and drivers (nvidia-peermem or DMA-BUF). Upgrade them together and re-run multi-node tests.
- Failures look like hangs. A rank that never writes its slot leaves every peer spinning. Use NCCL RAS and timeouts (9.f, 23.e); some kernels expose an abort flag in their workspace.
- Workspace memory. Symmetric buffers, Lamport triple buffers and EP receive buffers sized for the maximum tokens per rank cost GPU memory that comes out of the KV cache budget.
- Security and isolation. Peer-mapped memory crosses process boundaries; multi-tenant setups must not share NVLink peer groups between tenants (21.f).
9. Common mistakes#
- Using NCCL for a 16 KB decode all-reduce on NVLink when a fused custom kernel is available.
- Fusing RMSNorm with a partition that splits rows across CTAs or ranks.
- Reusing a Lamport buffer too early (no rotation), so a fast rank overwrites data a slow rank has not read.
- Ignoring the SM budget of communication kernels when computing expected compute throughput.
- Mismatched NCCL libraries between PyTorch and DeepEP or other extensions.
- Assuming V1-era DeepEP behaviour (zero-SM receive hooks) on V2.5.
- Benchmarking communication alone. The question is how much of it hides under compute in a real step, not its standalone latency.
10. Hands-on exercise#
- Change the Go model to two-shot (two fixed costs, 2 × (N − 1)/N × S over NVLink) and find the message size where it beats one-shot. Compare with the crossover vLLM’s custom all-reduce uses.
- On an 8-GPU NVLink node, time vLLM decode of a 70B model at TP 8 with
--disable-custom-all-reduceand without. Then enable FlashInfer’s fused all-reduce path if your build supports it. - Run CUTLASS’s
all_reduce_one_shot_lamport.pyandall_reduce_two_shot_multimem.pyexamples and compare their latency at 16 KB and 16 MB. - With DeepEP V2.5 on two nodes, run
tests/ep/test_ep.pyand record dispatch and combine latency and SM count at 128 tokens per rank.
11. Interview questions#
- Why do inference engines write their own all-reduce kernels instead of always calling NCCL?
- Explain Lamport-style synchronisation. What makes it correct, and what can break it?
- What does fusing all-reduce with residual add, RMSNorm and quantisation save, and why does RMSNorm constrain how the reduction is partitioned?
- Compare symmetric memory via CUDA IPC, NVSHMEM and the NCCL device API.
- What are the three ways to overlap communication with compute, and the cost of each?
- How did DeepEP change between V1 and V2.5, and what does that mean for SM budgeting?
- A TP-8 decode step got 8 % slower after a driver and NCCL upgrade. How do you find out why?
12. Further reading#
Checked on 13 November 2026.
- [REFERENCE] NCCL release notes — device API (2.28), GIN, CE collectives, NCCL EP
- [REFERENCE] NCCL device API documentation
- [REFERENCE] NVSHMEM (3.8.0) and documentation
- [REFERENCE] DeepEP (V2.5)
- [REFERENCE] FlashInfer communication module —
trtllm_allreduce_fusionand MNNVL all-to-all - [REFERENCE] CuTe DSL distributed examples
- [REFERENCE] PyTorch symmetric memory
- Related lessons: interconnects (9.c), NCCL (9.f), communication cost (9.g), tensor parallelism (14.c), expert parallelism (14.e)