Unit 4 of 9 · about 4 hours · explain, measure
NCCL algorithms, protocols, channels and rank placement
NCCL usually picks well, but small-message stalls and cross-socket surprises come from its defaults meeting your topology. This unit teaches when to trust auto-selection and which knob fixes each failure.
You'll be able to
- Explain how NCCL picks Ring, Tree, NVLS, NVLSTree, CollNet and PAT by message size and topology, and what LL, LL128 and Simple change about a transfer.
- Select algorithm, protocol and channel settings for a stated workload, and place ranks and shards so fast links carry the most bytes.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Algorithm and protocol selectionNCCL
NCCL_ALGOwith Ring, Tree, CollNet variants, NVLS, NVLSTree and PAT plus per-collective syntax;NCCL_PROTOwith LL, LL128 and Simple; set before communicator creation - Topology-aware selection in practiceAI Systems Performance Engineering - Chapters 4, 15, 17 and 18
Chapter 4, Topology Awareness in NCCL; NCCL Communication Algorithms: messages in the tens of MB favour tree, large messages favour ring, NVLSTree enables NVLink SHARP offload
- How NCCL works under the hoodGPU MODE - Collective Communication
Lecture 17, GPU Collective Communication (NCCL): what NCCL is, why data-parallel training needs it, and how it moves data;
ddp_simple.pyandddp_example.py - Topology bring-up benchmarkAI Systems Performance Engineering companion code - Chapters 4, 15 and 17
nccl_benchmark.pywithbaseline_nvlink_topology_aware.py: naive versus topology-aware placement on the same collective
Focus on
- Channels split one collective across parallel rings, one CUDA block per channel. Size them with
NCCL_MIN_CTASandNCCL_MAX_CTASfrom the versioned env page for your NCCL; older guides name NCHANNELS variables that your version may not read. - Protocols trade startup against throughput: LL and LL128 cut small-message latency while Simple wins large transfers. Pair them with the algorithm (a low-latency protocol, with tree at larger rank counts, for small messages; ring with Simple for large) rather than setting one knob.
- Overrides apply before
ncclCommInitRankand read as research or troubleshooting tools, not production defaults. Quote the NCCL version with every override because algorithm and default changes land per release. - Placement keeps tensor-parallel exchanges inside one NVSwitch domain and reduces across fast pairs before touching slow links. Rank order decides AllGather layout and root identity, so placement and mapping are one decision.
Common mistakes · 3
- Setting NCCL_ALGO after the communicator exists and concluding selection does nothing. The tuner reads it at init time; a late export only affects the next communicator.
- Copying
NCCL_MIN_NCHANNELSfrom an old guide into a new NCCL. Read the env page for the installed version and set the CTAS pair it documents, then confirm with the topology dump that channels changed. - Forcing Ring with Simple for every size because ring is bandwidth-optimal. Optimality is about bytes per link; at small sizes startup dominates. On two RTX A5000s joined by PCIe, Ring with Simple took 23 us for an 8-byte all-reduce against 8 us for NCCL's default choice.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.An 8-GPU all-reduce of 16 KB is slow under Ring with Simple. What do you change?Answer
Remove the override first: the tuner picks a low-latency protocol for small sizes. If you must force a setting, try LL or LL128 with Tree; the message is latency-dominated, so startup and step count beat balanced links.
2.What does adding channels do, and what limits it?Answer
It stripes the collective across parallel rings with one CUDA block per channel, raising link use. Limits are SM occupancy for those blocks and the CTAS bounds for the installed NCCL version.
3.Where do NVLS and NVLSTree apply?Answer
Inside an NVSwitch domain, where NVLink SHARP can offload the reduction instead of circulating every byte through SMs. Outside such a domain they do not apply.
4.Two runs of the same script place the broadcast root on different GPUs. What changed?Answer
The rank-to-device mapping. The root argument names a rank, so the same root rank lands on a different device after remapping.
Practice
- nccl-tests
all_reduce_perfalgorithm and protocol sweepRun
build/all_reduce_perf -b 8 -e 256M -f 2 -g 2with two GPUs under Tree, Ring and defaultNCCL_ALGOwith LL128 and Simple protocolsRecord the NCCL version and
NCCL_TOPO_DUMP_FILEwith every number, and predict the winners before running. On two RTX A5000s joined across sockets by PCIe (no NVLink), with NCCL 2.27.5 and CUDA 12.6, an 8-byte all-reduce took about 8 us with LL, 16 to 17 us with LL128 and 23 us with Simple under either algorithm, so with two ranks the protocol mattered and ring against tree did not. At 256 MB, Ring with Simple took 19.9 ms (13.5 GB/s bus bandwidth), the same as the default, against 21.9 ms for Tree with Simple and 30 to 81 ms for the LL protocols. Explain any difference on your hardware. With one GPU, build the analytical latency-bandwidth model checked against published nccl-tests results and label it simulation.
You're done when
Your predicted winner matches the bounded sweep at both ends of the size range, and every override you keep is version-pinned with a measured reason.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 9 more in the section
- AI Systems Performance Engineering - Chapters 4, 15, 17 and 18Chris Fregly · primary
Read Chapter 4 on distributed networking communication, the parallelism parts of Chapter 15, and Chapters 17 and 18 on disaggregated prefill and decode and KV-cache transfer. Re-derive every volume and crossover for the hardware you actually have.
- AI Systems Performance Engineering companion code - Chapters 4, 15 and 17Chris Fregly · support
Use compatible examples from
code/ch04,code/ch15andcode/ch17for NCCL, topology, overlap and disaggregated inference. Run preflight checks, lock and record clocks through the harness, and mark unsupported transport or topology paths as explicit blockers. - NCCLNVIDIA · required
Study the collective API, communicator and topology behavior, then run a bounded nccl-tests message-size sweep when multiple GPUs are available. Correlate algorithm bandwidth, bus bandwidth and rank timelines with the - model.
- GPU MODE - Collective CommunicationGPU MODE · support
Use Lectures 17, 67, 70 and 78 for NCCL, NVSHMEM, fault-tolerant collectives and multi-GPU Triton. Implement or inspect one communication mechanism only after the volume and topology model is written.
Also in this section
- AI Performance Engineering - Distributed InferenceWafer · reference
A curated index. Use Section 5 only to find primary papers for a communication mechanism you are measuring.
- UCSD CSE 291A/DSC 291 (Spring 2026) PA2 Part 2 - Tensor Parallel CommunicationUC San Diego · required
Build all-reduce and all-to-all from point-to-point MPI calls (Section 2.1), then the data split, layer initialization and naive model-parallel forward and backward communication (Sections 2.2 to 2.5) against the provided
mpi-test.pycases and pytest files. It runs on CPU processes with Open MPI andmpi4py. - CS336 Assignment 2 - Section 8.1 Communication PrimitivesStanford University · support
Work
alternate_ring_all_reduceand the communication-volume reasoning in Section 8.1 as a written check on your cost model. - TensorTonic Language Modeling from Scratch - collective problemsTensorTonic · support
Solve Simulate Distributed Collectives, Calculate Collective Effective Bandwidth, Synchronize Data-Parallel Gradients and Reconstruct a Column-Parallel MLP Layer after the collective units.
- DistServeDistServe Authors · required
Study prefill-decode interference, phase-specific parallelism and goodput optimization. Build a small simulator or measured two-pool experiment and test the key-value transfer crossover rather than reproducing the complete serving system.
- NVIDIA Inference Xfer LibraryNVIDIA · support
Inspect memory registration, transfer backends and metadata APIs as the state-movement layer for disaggregation. Run only supported local transports and compare measured transfer setup and steady-state cost with the model.
- DeepEPDeepSeek · depth
Reconstruct expert dispatch and combine paths, low-latency versus high-throughput modes and hardware assumptions. Test a small supported path only after a standard collective baseline and load-skew model exist.
- Splitwise: Efficient Generative LLM Inference Using Phase SplittingMicrosoft Research · support
Read arXiv:2311.18677v2 (ISCA 2024) for the phase characterization and the homogeneous and heterogeneous cluster designs. Test the throughput, cost and power claims as hardware-specific results, and compare its placement with DistServe on your workload.
- Mooncake: Trading More Storage for Less ComputationUSENIX FAST 25 · support
Study the KVCache-centric disaggregated architecture, the global cache with its transfer engine, and the prefill scheduling with early rejection. Test the effective-capacity claims as trace-specific results.