Skip to content

fix(ompi): handle large counts in AllReduce and AllGather - #96

Open
xingjiangjun wants to merge 1 commit into
InfiniTensor:masterfrom
xingjiangjun:fix/mpi-large-count
Open

xingjiangjun wants to merge 1 commit into
InfiniTensor:masterfrom
xingjiangjun:fix/mpi-large-count

Conversation

@xingjiangjun

@xingjiangjun xingjiangjun commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix MPI_ERR_COUNT in the MPI implementations of AllReduce and AllGather when the per-rank element count exceeds INT_MAX. Each MPI call now receives a representable count.

Changes

  • Collectives
    • Split AllReduce by element count and place each AllGather chunk in its source rank’s output block.
  • Size checks
    • Return infinicclInvalidArgument before staging if the required buffer size overflows size_t.

Platform and Backend Affected

The implementation is shared by the MPI backends across device types.

Platform

  • CPU
  • NVIDIA GPU
  • Iluvatar GPU
  • MetaX GPU
  • Moore Threads GPU
  • Cambricon MLU
  • HYGON DCU
  • T-Head PPU
  • Ascend NPU

Backend

  • OpenMPI
  • MPICH
  • NCCL/RCCL
  • MCCL
  • CNCL
  • HCCL

Performance Impact

N/A — Counts up to INT_MAX still use one MPI collective call. No performance comparison was run.

Known Issues & Future Work

  • MPICH was not tested.

Test Results

OpenMPI 4.1.6. Both original Float32 examples passed on each setup. The large-count tests checked every output element on both ranks.

Setup Example results Two-rank UInt8 counts passed by both operations
NVIDIA A100 2/2 on 2 GPUs and 2/2 on 8 GPUs INT_MAX, INT_MAX + 1, INT_MAX + 257
MetaX C550 2/2 on 2 GPUs and 2/2 on 8 GPUs INT_MAX + 1, INT_MAX + 257
NVIDIA + MetaX, 1+1 GPUs over UCX/TCP 2/2 INT_MAX + 1

Both ranks returned infinicclInvalidArgument for overflowing byte sizes on all three setups. The NVIDIA Int32 and Float32 regression cases passed (8/8).

Heterogeneous MPI example logs and large-count results

mpi/all_reduce

[COMMAND]: icclrun --config <cluster.yaml> --launcher ompi mpi/all_reduce
================================================================================

[Rank 0] GPU: nvidia  | Device 0
[Rank 1] GPU: metax  | Device 0

=== Performing AllReduce on GPU Memory ===
Data size: 1048576 floats (4 MB)
Operation: Sum
Warm-up iterations: 2
Profile iterations: 20

=== AllReduce Results ===
Correct: YES
Expect:  3.00
Actual:  3.00
Time:           86.731 ms
Throughput:     0.05 GB/s (Bus BW)
Alg Bandwidth:  0.05 GB/s
InfiniCCL finalized.

mpi/all_gather

[COMMAND]: icclrun --config <cluster.yaml> --launcher ompi mpi/all_gather
================================================================================

[Rank 0] GPU: nvidia  | Device 0
[Rank 1] GPU: metax  | Device 0

=== Performing AllGather on GPU Memory ===
Data size: 1048576 floats (4 MB)
Operation: AllGather
Warm-up iterations: 2
Profile iterations: 20

=== AllGather Results ===
Correct: YES
Sample blocks: [r0: 1] [r1: 2]
Time:           98.602 ms
Throughput:     0.08 GB/s (Bus BW)
Alg Bandwidth:  0.08 GB/s
InfiniCCL finalized.

UInt8, per-rank count 2147483648

[Rank 1] all_reduce UInt8 count=2147483648 status=0 checked=2147483648 errors=0
[Rank 0] all_reduce UInt8 count=2147483648 status=0 checked=2147483648 errors=0
[Rank 0] Correct: YES
[Rank 1] Correct: YES
EXIT_CODE=0

[Rank 1] all_gather UInt8 count=2147483648 status=0 checked=4294967296 errors=0
[Rank 0] all_gather UInt8 count=2147483648 status=0 checked=4294967296 errors=0
[Rank 0] Correct: YES
[Rank 1] Correct: YES
EXIT_CODE=0

Test Involved Platform

  • CPU
  • NVIDIA GPU
  • Iluvatar GPU
  • MetaX GPU
  • Moore Threads GPU
  • Cambricon MLU
  • HYGON DCU
  • T-Head PPU
  • Ascend NPU

Test Involved Backend

  • OpenMPI
  • MPICH
  • NCCL/RCCL
  • MCCL
  • CNCL
  • HCCL

Checklist

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.
  • N/A — Public API changes (if any) are intentional, documented, and reflected in affected callers/tests. No public API change.

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.
  • N/A — The new diagnostics use collective operation names in prose. The layout comment references no code identifiers.
  • 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.
  • N/A — No exceptions are thrown. Error paths use assert with messages that include at least __FILE__, __LINE__, and __func__ (CONTRIBUTING.md §C++). The MPI backend reports invalid input with ReturnStatus::kInvalidArgument.
  • Error and warning message wording follows the LLVM Coding Standards (CONTRIBUTING.md §C++).
  • N/A — Constructor initializer list order matches member declaration order (CONTRIBUTING.md §C++). No constructors changed.
  • 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)

N/A — No Python files changed.

Testing

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

Build, CI, and Tooling

  • N/A — 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. No new backend or device.
  • 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.
  • N/A — Any user-visible breaking change is called out explicitly under "Summary" and in the commit/PR title with a ! or BREAKING CHANGE: footer. No breaking API change.

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 third-party code added.
  • For matching MPI and InfiniCCL element widths, the chunk and rank offsets stay within the checked buffer sizes and the copies read only bytes written by MPI.

@xingjiangjun
xingjiangjun requested a review from Ziminli November 27, 2026 08:27
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