nccl4py: Python Bindings for RCCL
Python bindings for the ROCm Communication Collectives Library (RCCL), AMD's drop-in replacement for NVIDIA NCCL on ROCm. This package is a fork of the upstream NVIDIA nccl4py v0.2.0 and provides both low-level Cython bindings and a high-level Pythonic API for RCCL collective operations.
Highlights
- Drop-in API: keeps the upstream
nccl.bindings/nccl.coreimport paths, so applications written against NCCL on CUDA work unchanged on RCCL on ROCm. - HIP-backed
cuda.coreshim: ROCm hosts getfrom cuda.core import ...resolved vianccl._hip_compat.cuda_core_shim(backed byhip-python) without pulling NVIDIAcuda-bindings/cuda-core. The shim is registered insys.modulesonimport nccl, sofrom cuda.core import ...resolves to the HIP backend afterimport ncclhas run; it is not shipped as a top-levelcudapackage on disk to avoid shadowing co-installed distributions that contribute to thecuda.*namespace (cuda-bindingspulled transitively by PyTorch / RAPIDS / Triton / nsight tooling). - RCCL-only collectives: wrappers for
ncclAllReduceWithBiasandncclAllToAllv(which exist inlibrccl.sobut have no upstream NCCL equivalent) are exposed vianccl.bindings.rocm_extensions. - No CUDA toolchain at build time: Cython extensions treat
cudaStream_tas an opaquevoid*;librccl.sois resolved at runtime viadlopen.pip install .works on a ROCm host withoutCUDA_HOME.
Requirements
- Runtime:
librccl.soresolved at first use. Discovery order:NCCL_LIBRARY=<path>(explicit override; path or SONAME).ctypes.util.find_library("rccl")(the loader'sldconfigcache).$ROCM_PATH/lib/librccl.so, then$HIP_PATH/lib/librccl.so.- Bare
librccl.so, resolved viaLD_LIBRARY_PATH/ the standard loader search paths.
- Python: 3.10 or later.
- Python deps:
hip-python,numpy,packaging(resolved automatically bypip).
Installation
pip install . is the supported install path on ROCm:
pip install .
Note: The
MakefileandCMakeLists.txtshipped in this directory are inherited from upstream NVIDIAnccl4pyand target NVIDIA hardware (they requireCUDA_HOME/nvccand pull CUDA-onlytorch/cupywheels). They are out of scope for the ROCm bring-up and tracked separately under release engineering; usepip installon ROCm hosts.
For a development environment with the test extras:
pip install -e .
pip install pytest pytest-mpi pytest-cov mpi4py ml-dtypes
Tests
The unit-style files (tests/test_loader_stubs.py,
tests/test_shim_surface.py, tests/test_rocm_extensions.py) run
under a single rank without any GPU and are useful as smoke tests:
pytest tests/test_loader_stubs.py tests/test_shim_surface.py tests/test_rocm_extensions.py
The collective-correctness and PyTorch / CuPy interop tests are
marked @pytest.mark.mpi and require mpirun -np N plus visible
GPUs:
mpirun -np 8 pytest -m mpi tests/
tests/conftest.py skips MPI-tests gracefully on hosts without
mpi4py, torch, or any visible GPU; the 8-rank tests xfail
when fewer than 8 GPUs are visible.
Examples
examples/01_basic/ contains minimal, self-contained scripts:
mpirun -np 4 python examples/01_basic/01_allreduce.py
mpirun -np 2 python examples/01_basic/02_send_recv.py
Layout
nccl/bindings/- Cython bindings to the RCCL/NCCL C ABI; vendored from upstreamnccl4pywith the patches needed to drop the CUDA driver-types include and to resolvelibrccl.soviadlopen.nccl/_hip_compat/- HIP/ROCm-only compatibility layer; not a public API. Hosts thecuda_core_shimpackage registered insys.modulesascuda.corebynccl/__init__.py.nccl/core/- the high-level Pythonic surface (Communicator, Buffer, Group, ...).