When a model is trained not on a single GPU but on dozens, the GPUs must constantly exchange data: summing gradients from all cards, gathering tensor fragments, broadcasting weights. This work is handled by NCCL (pronounced “nickel”), a low-level library that frameworks such as PyTorch and TensorFlow call automatically.
What it does
NCCL implements collective operations — calls that involve every GPU in a group at once:
all-reduce— sums a tensor across all GPUs and hands the result to every card; the main call for gradient synchronisationall-gather— gathers tensor fragments from all GPUs into a full tensor on every cardreduce-scatter— sums the data and splits the result between GPUs, saving memorybroadcast,reduce,all-to-all— sending from one GPU to all, gathering to one, full exchange
NCCL has a simple C interface modelled on MPI collective operations: communicator initialisation via ncclCommInitRank, calls such as ncclAllReduce and ncclBroadcast, plus a stream argument for integration with CUDA. In practice developers rarely write it by hand: PyTorch wraps the collectives in torch.distributed (backend nccl), while TensorFlow and Horovod call the same operations under the hood.
How it picks the data path
NCCL’s defining feature is topology awareness. At startup the library probes the environment and picks a route for the data: within a single server GPUs talk over NVLink and NVSwitch, between servers over InfiniBand or Ethernet (RDMA over Ethernet), with a plain IP-network mode also available. For each operation NCCL selects an algorithm (“ring”, “tree” and others) and a protocol on its own; they can be pinned down with the NCCL_ALGO and NCCL_PROTO variables.
| Link | When it is used |
|---|---|
| NVLink, NVSwitch | GPUs within a single server — the highest speed |
| InfiniBand, RoCE | cluster nodes over the data centre network, RDMA without loading the CPU |
| PCIe, TCP | GPUs without NVLink and plain IP networks — slower, but found in almost any system |
Example: PyTorch
import torch.distributed as distdist.init_process_group(backend='nccl')dist.all_reduce(tensor) # sum of tensors from all GPUsA typical problem is NCCL failing to see the network inside a container: verbose logging (NCCL_DEBUG=INFO) and the NCCL_SOCKET_IFNAME variable set to the interface name help here.
Sources
the term is written from these pagesVerified 9 Nov