Skip to content

feat: support NCCL AllReduce#47

Merged
Ziminli merged 19 commits into
masterfrom
feat/support-nccl-allreduce
Jul 6, 2026
Merged

feat: support NCCL AllReduce#47
Ziminli merged 19 commits into
masterfrom
feat/support-nccl-allreduce

Conversation

@Ziminli

@Ziminli Ziminli commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds NVIDIA NCCL support for AllReduce, including the public unique-ID and rank-based communicator initialization APIs needed for NCCL-style bootstrap flows. It also teaches the generated C bridge to return infinicclNotSupported for unavailable operations, adds backend/device combination filtering, includes CCL-only plus OpenMPI-assisted NCCL example programs, and documents NCCL as a partial backend option.

Changes

  • Public API and Dispatch

    • Add infinicclUniqueId, infinicclGetUniqueId(), and infinicclCommInitRank() to the public communication API.
    • Add infinicclNotSupported / ReturnStatus::kNotSupported.
    • Add IsSupportedCombination so unsupported backend/device pairs do not instantiate invalid operation implementations.
    • Update bridge generation so operations missing from the selected backend configuration return NotSupported instead of failing to compile.
  • NCCL Backend

    • Add NCCL checks, communicator instance handling, data type mapping, and reduction-op mapping.
    • Add NCCL implementations for GetUniqueId, CommInitRank, CommDestroy, and AllReduce.
    • Add runtime GetDevice aliases needed by rank-based communicator initialization.
  • Hybrid Communicator Ownership

    • Allow CommInitAll and CommInitRank to populate separate inter_comm and intra_comm slots on one Communicator.
    • Add RAII cleanup for OpenMPI and NCCL communicator instances so mixed communicators release all backend handles on destroy.
  • Examples and Runner Tooling

    • Add a thread-per-GPU single-node CCL AllReduce example.
    • Add an OpenMPI-assisted NCCL AllReduce example that uses MPI for rank discovery and unique-ID broadcast, then initializes an NCCL communicator.
    • Update scripts/run_examples.py to forward executable arguments after --.
  • Documentation and PR Template

    • Add NCCL to the README supported-backends table as a partial NVIDIA-only backend.
    • Add NCCL to the PR template affected/tested backend checklists.

Platform and Backend Affected

Platform

  • CPU
  • NVIDIA GPU
  • Iluvatar GPU
  • MetaX GPU
  • Moore Threads GPU
  • Cambricon MLU

Backend

  • OpenMPI
  • MPICH
  • NCCL

Performance Impact

  • No performance impact
  • Performance improved
  • Performance regression possible

This adds a GPU-native NCCL path for NVIDIA AllReduce, avoiding the existing MPI host-staging path when the NCCL backend is available. Existing MPI collectives are intended to remain unchanged.

Known Issues & Future Work

  • The NCCL backend added here currently covers GetUniqueId, CommInitRank, CommDestroy, and AllReduce; other NCCL collective operations remain future work.

Test Results

Test Involved Platform

  • CPU
  • NVIDIA GPU
  • Iluvatar GPU
  • MetaX GPU
  • Moore Threads GPU
  • Cambricon MLU

Test Involved Backend

  • OpenMPI
  • MPICH
  • NCCL

Pure CCL (NCCL) on single-node NVIDIA:
ccl_all_reduce.log

CCL + MPI on single-node NVIDIA:
ccl_mpi_hybrid_all_reduce.log

MPI on Heterogeneous Cluster:
mpi_all_gather.log
mpi_all_reduce.log
mpi_all_to_all.log
mpi_broadcast.log
mpi_gather.log
mpi_reduce.log
mpi_reduce_scatter.log
mpi_scatter.log
mpi_send_recv.log


Checklist

Every contributor must verify every item below before requesting
review. Tick each box only after the check has actually been performed —
do not tick speculatively. If an item truly does not apply, replace the
checkbox with N/A and briefly explain why in an inline comment.

Title, Branch, and Commits

  • PR title follows Conventional Commits (e.g. feat: …, fix(nccl): …).
  • Branch name follows <type>/xxx-yyyy-zzzz where <type> matches the PR title's Conventional Commits type and words are joined with hyphens (see CONTRIBUTING.md §Branches).
  • Each commit message follows Conventional Commits.
  • Small PR is a single squashable commit; or, for a large PR, every commit is meaningful, well-formed, and independently reviewable (see CONTRIBUTING.md §Pull Requests).
  • No stray merge commits from master — the branch is rebased cleanly on top of the current master.
  • No fixup! / squash! / wip commits remain.

Scope and Design

  • Changes are minimal — no unrelated modifications were introduced (CONTRIBUTING.md §Code/General).
  • No dead code, commented-out blocks, debug prints, printf/std::cout/print(...) left behind, or TODO without an owner and issue link.
  • No unrelated formatting churn that would obscure the diff.
  • Public API changes (if any) are intentional, documented, and reflected in affected callers/tests.

General Code Hygiene

  • The code is self-explanatory; comments were added only where the intent or rationale is non-obvious (CONTRIBUTING.md §Code/General).
  • Every modified or added file ends with a single trailing newline (CONTRIBUTING.md §Code/General).
  • No trailing whitespace, inconsistent indentation, or mixed formatting styles remain.
  • Identifiers referenced in comments or error messages are wrapped in Markdown backticks (e.g. the `AllReduce` implementation) (CONTRIBUTING.md §Code/General).
  • All comments and error messages are in English (CONTRIBUTING.md §Code/General).
  • Comments and error messages are complete sentences — capitalized first letter, terminal punctuation — unless the language/framework convention says otherwise (CONTRIBUTING.md §Code/General; §Python).

C++ Specific (if C++ files changed)

  • Code follows the Google C++ Style Guide strictly.
  • clang-format (version 16, per .github/workflows/clang-format.yml) has been run against all modified applicable files; the diff is clean.
  • No exceptions are thrown. Error paths use assert with messages that include at least __FILE__, __LINE__, and __func__ (CONTRIBUTING.md §C++).
  • Error and warning message wording follows the LLVM Coding Standards (CONTRIBUTING.md §C++).
  • Constructor initializer list order matches member declaration order (CONTRIBUTING.md §C++).
  • Exactly one blank line between classes, between classes and functions, and between functions (CONTRIBUTING.md §C++).
  • Exactly one blank line between members (functions and variables) within a class (CONTRIBUTING.md §C++).
  • Exactly one blank line before and after the contents of a namespace (CONTRIBUTING.md §C++).

Python Specific (if Python files changed)

  • Code is PEP 8 compliant; ruff check passes cleanly on CI (see .github/workflows/ruff.yml).
  • ruff format --check passes cleanly — if not, run ruff format and commit the result.
  • Comments are complete English sentences, starting with a capital letter and ending with punctuation; Markdown backticks are used for code references (CONTRIBUTING.md §Python).
  • Framework-specific conventions (e.g. lowercase pytest.skip messages without terminal period) are honored where applicable (CONTRIBUTING.md §Python).
  • No blank line between the function signature and the body when there is no docstring or comment (CONTRIBUTING.md §Python).
  • A blank line is present before and after if, for, and similar control-flow statements (CONTRIBUTING.md §Python).
  • A blank line appears before each return, except when it directly follows a control-flow statement (CONTRIBUTING.md §Python).
  • Docstrings (if any) follow PEP 257 (CONTRIBUTING.md §Python).
  • Type hints are added / kept consistent with the surrounding code.

Testing

  • All applicable example programs have been built and tested successfully on at least one supported heterogeneous cluster setup.

Build, CI, and Tooling

  • New backends or devices have been added to auto-detection in CMakeLists.txt under if(AUTO_DETECT_DEVICES) or to if(AUTO_DETECT_BACKENDS) if applicable.
  • Both CI workflows (clang-format.yml, ruff.yml) are green locally (or expected to be green on CI).

Documentation

  • README.md, CONTRIBUTING.md, or inline docs updated when behavior, build flags, or developer workflow changed.
  • Any user-visible breaking change is called out explicitly under "Summary" and in the commit/PR title with a ! or BREAKING CHANGE: footer.

Security and Safety

  • No secrets, access tokens, internal URLs, customer data, or personal hardware identifiers have been committed.
  • N/A- Third-party code is license-compatible and attributed.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.

Ziminli added 16 commits July 6, 2026 08:01
…ination` trait

 - add a new return status `infiniNotSupported` to indicate a functionality is not supported
 - add `IsSupportedCombination` trait to control valid combinations between different `BackendType`s and `Device::Type`s
 - update `Operation::Call()` to use `IsSupportedCombination` to ensure only valid combinations are instantiated and forwarded
…s well as NCCL checks

 - add `infiniGetUniqueId()` in `include/comm.h`
 - add `GetUniqueId` and its NCCL implementation
 - modify the nccl path in `BACKEND_PATH_MAP` in `scripts/gen_bridge.py`
 - add `src/nvidia/nccl/checks.h` which contains the error handling function and macro for NCCL
 - add `infiniCommInitRank()` and its NCCL backend implementation
 - fix a comment style issue in `src/ompi/impl/comm_init_all.h`
 - add `kNcclTypeMap` for converting `DataType` to `ncclDataType_t` and its runtime accessor `DataTypeToNcclType`
 - add `kNcclOpMap` for converting `ReductionOpType` to `ncclRedOp_t` and its runtime accessor `RedOpToNcclOp`
Resolve compilation errors in standalone backend builds (e.g., NCCL-only)
by checking the filesystem for implemented operations and generating
`ReturnStatus::kNotSupported` stubs for the missing ones.
- add a thread-per-GPU CCL AllReduce example for single-node runs in `examples/ccl/all_reduce.cc`
- add an OpenMPI-assisted hybrid AllReduce example for multi-node runs in `examples/ccl_mpi_hybrid/all_reduce.cc`
@Ziminli Ziminli self-assigned this Jul 6, 2026
@Ziminli Ziminli merged commit a89d426 into master Jul 6, 2026
2 checks passed
@Ziminli Ziminli deleted the feat/support-nccl-allreduce branch July 6, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant