NCCL (the NVIDIA Collective Communications Library, usually pronounced “nickel”) is an open-source library that implements multi-GPU and multi-node collective operations such as AllReduce, AllGather and Broadcast, optimized for NVIDIA GPUs and their interconnects. Among AI frameworks & tools, it is the communication layer underneath distributed training: when PyTorch, JAX, DeepSpeed or Megatron-LM synchronize gradients or shard parameters across many GPUs, the actual data movement is usually performed by NCCL.
NCCL does not train models or schedule jobs. Its single job is to move tensors between GPU memories as fast as the hardware allows, choosing communication algorithms and transports based on the detected topology of NVLink, PCIe and network links. In large clusters, its efficiency often decides whether adding GPUs actually shortens training time.
How NCCL moves data between GPUs
NCCL works by forming a communicator, a group of ranks in which each rank is usually one GPU, and then running collective kernels directly on the GPUs. A process creates a unique identifier with ncclGetUniqueId, shares it with all other processes through an external channel such as MPI or a TCP store, and each rank joins with ncclCommInitRank.
At initialization, NCCL detects the system topology: which GPUs share NVLink or NVSwitch, which sit behind the same PCIe switch, and which network adapters are closest to each GPU. From this graph it builds rings and trees of connections and assigns them to several parallel channels, each driven by a few GPU thread blocks, so that many links carry traffic at the same time.
Collectives are enqueued on CUDA streams, which means they run asynchronously and can overlap with computation. Frameworks exploit this by launching gradient AllReduce for finished layers while the backward pass continues on later layers, a technique known as communication and computation overlap.
The table below lists the main operations NCCL provides and where they appear in typical AI workloads.
| Operation | What it does | Typical use in AI |
|---|---|---|
| AllReduce | Combines buffers from all ranks and returns the result to every rank | Gradient averaging in data parallelism |
| AllGather | Concatenates a piece from each rank onto every rank | Rebuilding sharded parameters in FSDP or ZeRO |
| ReduceScatter | Reduces buffers and gives each rank one slice of the result | Sharded gradient reduction |
| Broadcast | Copies one rank’s buffer to all ranks | Distributing initial weights |
| Send and receive | Point-to-point transfer between two ranks | Pipeline parallelism and all-to-all for mixture of experts |
Algorithms, protocols and transports in NCCL
NCCL selects an algorithm, a protocol and a transport for every collective call, based on message size, rank count and topology. The ring algorithm sends data around a logical circle and achieves near-optimal bandwidth: in an AllReduce over N ranks, each rank transmits about 2(N-1)/N times the buffer size, which approaches twice the data regardless of cluster size. Its weakness is latency that grows linearly with the number of ranks.
The double binary tree algorithm reduces latency to a logarithmic number of steps and therefore helps with small and medium messages on large clusters. Newer versions add NVLink SHARP (NVLS) and CollNet, which offload reductions into NVSwitch or network switches, and the PAT algorithm for AllGather and ReduceScatter at scale.
| Algorithm | Strength | Limitation | Typical selection |
|---|---|---|---|
| Ring | Maximum bandwidth on large buffers | Latency scales with rank count | Large gradients, moderate cluster size |
| Tree | Logarithmic latency | Lower peak bandwidth within a node | Small and medium messages across many nodes |
| NVLS | In-switch reduction on NVSwitch systems | Requires recent NVSwitch hardware | Single-node and rack-scale AllReduce |
| CollNet | Network-side reduction | Requires SHARP-capable switches and plugins | Very large InfiniBand clusters |
Three wire protocols trade latency for bandwidth: Simple uses large chunks and memory fences for peak throughput, LL (low latency) uses 8-byte flag-and-data stores for tiny messages, and LL128 uses 128-byte units that keep most of the bandwidth with much lower latency. Transports include NVLink and NVSwitch, PCIe peer-to-peer, shared host memory, InfiniBand and RoCE with GPUDirect RDMA, and plain TCP sockets as a fallback. Network plugins, such as the one for AWS Elastic Fabric Adapter, extend NCCL to other fabrics.
NCCL compared with other communication libraries
NCCL is the default GPU backend in PyTorch distributed, but it is one of several collective libraries. The comparison below shows how it relates to the alternatives that practitioners most often meet.
| Library | Target hardware | Relation to NCCL |
|---|---|---|
| NCCL | NVIDIA GPUs | Reference implementation for CUDA collectives |
| RCCL | AMD GPUs through ROCm | Port with a largely compatible API |
| Gloo | CPUs, basic GPU support | PyTorch fallback for CPU tensors and coordination |
| MPI | General clusters | Often used only to bootstrap NCCL communicators |
| oneCCL | Intel CPUs and GPUs | Comparable role in the Intel ecosystem |
Higher-level tools sit above NCCL rather than competing with it. DeepSpeed, Megatron-LM and Hugging Face Accelerate decide which collectives to call and when, while XLA in JAX compiles collectives that are lowered to NCCL on NVIDIA hardware. Inference engines such as TensorRT-LLM and SGLang also rely on NCCL for tensor parallelism across GPUs.
Configuring and tuning NCCL in practice
Most users never call NCCL directly; they select it with a setting such as backend="nccl" in PyTorch. Tuning happens mostly through environment variables, and the defaults are usually correct, so changes should follow measurement with the nccl-tests benchmarks, which report algorithm bandwidth and bus bandwidth comparable with link speed.
| Variable | Purpose | When to set it |
|---|---|---|
NCCL_DEBUG=INFO | Prints topology, rings and chosen transports | First step in any diagnosis |
NCCL_SOCKET_IFNAME | Selects the network interface for bootstrap and sockets | Hosts with several interfaces |
NCCL_IB_HCA | Restricts which InfiniBand adapters are used | Multi-rail or mixed-adapter nodes |
NCCL_ALGO and NCCL_PROTO | Force or exclude algorithms and protocols | Controlled experiments only |
NCCL_P2P_DISABLE | Turns off direct GPU peer-to-peer transfers | Debugging suspected PCIe problems |
Good practice is to keep NCCL, the CUDA driver and the network stack versions consistent across all nodes, place each GPU process near its local network adapter, and verify that GPUDirect RDMA is active in the debug log when the fabric supports it.
Limitations and common failure modes
NCCL assumes that every rank calls the same collectives in the same order with matching sizes and data types. When this rule is broken, for example when one rank skips a step because of a data-dependent branch, the job typically hangs rather than failing with a clear error. PyTorch therefore wraps NCCL with a watchdog and timeout that aborts stalled communicators.
- Wrong network interface: bootstrap traffic tries an unreachable address, and initialization stalls.
- PCIe access control services enabled in a virtualized host can silently block peer-to-peer traffic and cut bandwidth.
- Mismatched library versions across nodes cause protocol errors or crashes at startup.
- Small messages on large clusters are latency bound, so bucketing gradients into larger buffers often helps.
- Memory overhead: each communicator and channel reserves GPU buffers, which matters when many communicators exist.
NCCL is also tied to NVIDIA hardware. Mixed-vendor clusters need different libraries per vendor, and NCCL does not provide fault tolerance: a single failed GPU or link usually requires restarting the job from a checkpoint.
A plain-language summary
Large AI models are trained on many graphics chips at once. Each chip works on its own share of data. After every step, the chips must share what they learned and agree on one result. NCCL is the software that handles this exchange.
Think of a team of accountants who each total part of a ledger. Someone must collect the subtotals and give everyone the final sum. NCCL does that job for GPUs. It finds the fastest cables between the chips and uses them all at once. When it works well, the chips spend their time computing instead of waiting.
An example from practice
A machine learning team fine-tunes a 13-billion-parameter language model on four servers, each with eight GPUs connected by NVLink and two 200 Gb/s InfiniBand adapters. Training uses PyTorch with fully sharded data parallelism, so every step runs AllGather and ReduceScatter through NCCL. The first run reaches only about half the expected throughput per GPU.
With NCCL_DEBUG=INFO, the engineers see that inter-node traffic uses TCP sockets instead of InfiniBand, because the container lacks the RDMA libraries. After they add the libraries and set NCCL_IB_HCA to the two adapters, the log shows GPUDirect RDMA in use, and nccl-tests reports bus bandwidth close to the link limit. Step time drops by roughly 40 percent, and the planned training run finishes days earlier on the same hardware.