Bookmarks

NCCL — NCCL library

NVIDIA Collective Communications Library

An NVIDIA software library for collective operations between GPUs: all-reduce, all-gather and other data exchanges in distributed training.

Also: collective operations, nickel

checked 9 Nov

All terms

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 synchronisation
  • all-gather — gathers tensor fragments from all GPUs into a full tensor on every card
  • reduce-scatter — sums the data and splits the result between GPUs, saving memory
  • broadcast, 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.

LinkWhen it is used
NVLink, NVSwitchGPUs within a single server — the highest speed
InfiniBand, RoCEcluster nodes over the data centre network, RDMA without loading the CPU
PCIe, TCPGPUs without NVLink and plain IP networks — slower, but found in almost any system

Example: PyTorch

pythonAfter this call every card will hold the same tensor
import torch.distributed as distdist.init_process_group(backend='nccl')dist.all_reduce(tensor)  # sum of tensors from all GPUs

A 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 pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • CUDACUDA platform

    CUDA is a GPU computing platform: kernels, memory, drivers. NCCL runs on top of it and handles only communication between GPUs.

In depth in the references

where the topic is covered in detail