Expand description
NCCL-based communication backend for expert parallelism.
Uses TCP bootstrap: rank 0 generates a unique ID and sends it to
all other ranks via a TCP listener. Then all ranks call
ncclCommInitRank with the shared ID.
Optimizations for 2-rank EP with small messages (4 KB):
- Pre-registers buffers with NCCL (
ncclCommRegister) to cache IB memory registration - Uses paired
ncclSend/ncclRecv+ local BF16 add instead ofncclAllReduce
Health monitoring and recovery:
- Checks
ncclCommGetAsyncErrorafter each collective - Detects broadcast timeouts (>30s) via stream sync + wall-clock check
- Aborts dead communicators via
ncclCommAbortand reconnects
§Safety contract for the unsafe { ... } calls below
All unsafe blocks in this file wrap a single FFI call into either
NCCL (nccl*) or the CUDA Driver API (cu*). The invariants are
uniform:
- NCCL handles:
NcclComminstances are constructed vianccl::comm_init_rankafter a successful TCP bootstrap and areDrop-cleaned viancclCommDestroy. They are never aliased across threads without aMutexguarding the comm. - CUDA buffers passed to NCCL come from a prior
cuMemAlloc_v2on the same device that owns the comm; size in bytes matches the allocation. - Streams referenced via
u64are owned by the caller and outlive the in-flight collective. extern "C"ABI: matches the NCCL 2.20+ headers and thecuMemAlloc_v2/cuLaunchKernel/etc. shapes declared just below.
Per-site // SAFETY: comments are omitted because the contract is
identical for every call. Deviations get a per-site comment.
Structs§
- Nccl
Backend - NCCL communication backend for multi-GPU / multi-node EP.
Constants§
- ALL_
REDUCE_ DTYPE_ BYTES - Element width, in bytes, of the dtype the 2-rank send/recv all-reduce moves.
Functions§
- required_
recv_ bytes - Bytes required for the 2-rank all-reduce receive buffer.