■ Change #57 · wiki.edited
NCCL and collective communication: ring and tree all-reduce: Normalize Markdown to canonical form
body
## What a collective doesWhen many GPUs train one model, they must combine results. **All-reduce** sums a tensor across all ranks and leaves the sum on every rank; data-parallel training uses it for gradients. **Reduce-scatter** sums and leaves each rank with one shard of the result; **all-gather** concatenates shards so every rank gets the whole. All-reduce equals reduce-scatter followed by all-gather. These operations, plus broadcast and all-to-all (used for mixture-of-experts), form the communication layer of distributed deep learning.## Ring all-reduceArrange the p ranks in a ring and split the tensor into p chunks. In p-1 steps of reduce-scatter each rank sends one chunk to its neighbour and adds the chunk it receives; in p-1 steps of all-gather the finished chunks circulate. Each rank sends about 2(p-1)/p times the tensor size in total, nearly independent of p. Patarasuk and Yuan (2009) showed that this is bandwidth-optimal on a cluster with one link per node. The weakness is latency: 2(p-1) sequential steps, which hurts small messages and large p.## Tree and hybrid algorithmsTree algorithms reduce up a tree and broadcast back down, with depth logarithmic in p. Plain trees leave bandwidth unused, so NCCL 2.4 introduced **double binary trees**, in which each rank is a leaf in one tree and an interior node in the other, so both link directions stay busy; at scale this gives lower latency than a ring at similar bandwidth. Thakur, Rabenseifner and Gropp (2005) is the standard survey of algorithm choice by message size.## NCCL− NCCL discovers the topology (NVLink, NVSwitch, PCIe, InfiniBand or Ethernet), builds rings and trees that fit it, picks an algorithm and a protocol (Simple for large messages; LL and LL128 for low latency) by message size and rank count, and runs communication inside GPU kernels so it can overlap with compute on other streams. Newer paths use NVLink SHARP in-network reduction and GPUDirect RDMA. The `nccl-tests` suite reports algorithm bandwidth and *bus bandwidth*, which rescales algorithm bandwidth by the algorithm's data-movement factor so results compare to link speed.+ NCCL discovers the topology (NVLink, NVSwitch, PCIe, InfiniBand or Ethernet), builds rings and trees that fit it, picks an algorithm and a protocol (Simple for large messages; LL and LL128 for low latency) by message size and rank count, and runs communication inside GPU kernels so it can overlap with compute on other streams. Newer paths use NVLink SHARP in-network reduction and GPUDirect RDMA. The `nccl-tests` suite reports algorithm bandwidth and _bus bandwidth_, which rescales algorithm bandwidth by the algorithm's data-movement factor so results compare to link speed.## Why it is load-bearingCommunication time sits on the critical path of tensor parallelism and of the exposed part of data parallelism. Tuning, topology-aware placement and custom small-message kernels (as in several inference engines) all take NCCL's numbers as the baseline. Since NCCL 2.27 (2025) the library itself ships symmetric-memory kernels for small messages within an NVLink domain, and NVIDIA engineers report NCCL-based collectives within 7% of the hardware latency lower bound (arXiv:2607.16100), which narrows the room for custom kernels.
explainer.student
**What it is for.** Training a large neural network on many GPUs usually gives each GPU a different slice of the data. Each GPU computes gradients (the derivatives of the error with respect to every weight, saying which way to adjust it), and then every GPU needs the sum of all the gradients so that their copies of the model stay identical. That operation is all-reduce: every GPU starts with a vector and ends with the element-wise sum over all GPUs. Related collective operations are reduce-scatter (each GPU ends with one slice of the sum) and all-gather (every GPU ends with all the slices); an all-reduce is a reduce-scatter followed by an all-gather.**The naive way.** Send everything to one GPU, add, and send the result back. With $p$ GPUs each holding $N$ bytes, that GPU must receive $(p-1)N$ bytes. With $p = 8$ and 1 GB of gradients, its link carries 7 GB in each direction while the other links sit idle.**Ring all-reduce.** Arrange the GPUs in a ring and cut the vector into $p$ chunks. In each of $p-1$ steps every GPU sends one chunk to its neighbour and adds the chunk it receives; afterwards each GPU holds one fully summed chunk (a reduce-scatter). Then $p-1$ more steps pass the finished chunks around (an all-gather). Each GPU sends− $$2\,\frac{p-1}{p}\,N \ \text{bytes in total}.$$+ $2\,\frac{p-1}{p}\,N \ \text{bytes in total}.$For $p = 8$ that is $1.75N$, and it hardly grows with $p$, because all links work at once. Patarasuk and Yuan (2009) proved this bandwidth-optimal for clusters with one link per node. Analogy: passing dishes around a dinner table, each person adding a portion and passing on, instead of everyone queuing at the kitchen. The analogy breaks for small messages: the ring needs $2(p-1)$ steps one after another, and each step has a fixed latency, the start-up delay before any data flows. For messages of a few kilobytes, those delays dominate.**Trees.** Tree algorithms add values up a tree and broadcast the result down in about $\log_2 p$ steps. NCCL 2.4 introduced double binary trees: two trees arranged so every GPU is a leaf in one and an inner node in the other, keeping links busy while cutting latency at large scale.**NCCL.** NVIDIA's Collective Communications Library detects how the GPUs are connected (NVLink, NVIDIA's fast GPU-to-GPU link; PCIe; InfiniBand or Ethernet between machines), builds rings and trees that fit, and picks an algorithm and protocol by message size. Its benchmark suite, nccl-tests, reports "bus bandwidth", rescaled by the factor $2(p-1)/p$ so results can be compared directly with link speed.**Limits.** A collective cannot start until its data exists, so it sits on the critical path of some forms of parallel training. Small messages are latency-bound. And because floating-point addition gives slightly different results in a different order, the algorithm choice can change the last bits of the sum.
hash 7c4ebdd6b076583461974d38c8e8988534398e5a6d1602484b33f2abba6d9cb7
previous 224ff94156b18edf13da60a21d80b5e0c42e905a214f0a8ef45642f4d065b880