Skip to content

feat: add mpi device-aware send-recv implementation - #93

Draft
Jinyao618 wants to merge 2 commits into
InfiniTensor:masterfrom
Jinyao618:feat/mpi-device-aware-send-recv
Draft

Jinyao618 wants to merge 2 commits into
InfiniTensor:masterfrom
Jinyao618:feat/mpi-device-aware-send-recv

Conversation

@Jinyao618

@Jinyao618 Jinyao618 commented Nov 20, 2026 •

Copy link
Copy Markdown

Summary

This PR adds a device-aware transport path for OpenMPI Send/Recv. When the local MPI stack can consume device memory, the new MpiBufferPlan passes device pointers directly to MPI_Send/MPI_Recv; otherwise it falls back to the existing host-staging path. The public API is unchanged, and only Send/Recv are adapted in this PR.

Capability is resolved once per communicator and stored in OmpiInstance::device_support. Each rank keeps its own decision, so a heterogeneous job can mix one device-aware rank with another host-staged rank without a global capability agreement.

Changes

  • MPI device-aware capability

    • Added MpiDeviceTraits and MpiDeviceSupport in src/backends/mpi/ompi/device_support.h.
    • Added INFINICCL_MPI_DEVICE_AWARE modes:
      • auto: query the available MPI extension.
      • 0: force host staging.
      • 1: force device-direct on an operator-validated stack.
    • Added a CMake compile/link probe for MPIX_Query_cuda_support in cmake/backends/MPI.cmake.
    • The probe result is emitted into a generated device_support_config.h and consumed as a constexpr value, avoiding preprocessor conditionals in runtime code.
  • Unified buffer plan

    • Added MpiBufferPlan in src/backends/mpi/ompi/buffer_plan.h.
    • It classifies send/receive buffers as host or device memory.
    • It selects device-direct, host-alias, or staged buffers.
    • It synchronizes the caller stream before D2H staging or direct MPI reads.
    • It owns staging buffers with RAII and performs receive-side H2D writeback in Commit().
    • Mode::kPair is used explicitly by Send/Recv; Mode::kAlias is reserved for future single-buffer collectives.
  • Send/Recv integration

    • Reworked src/backends/mpi/ompi/impl/send.h and src/backends/mpi/ompi/impl/recv.h as:
      Prepare plan -> MPI_Send/MPI_Recv -> Commit
    • Updated src/backends/mpi/ompi/impl/comm_init_all.h to resolve and log the actual per-rank transport mode.
    • Hardened host-pointer classification in src/devices/nvidia/device_.h and src/devices/metax/device_.h so ordinary host pointers are classified as host instead of aborting.

Platform and Backend Affected

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

  • No performance impact
  • Performance improved
  • Performance regression possible

Benchmark: examples/mpi/send_recv, float32, 4 MB message, 2 warm-up iterations, 20 profile iterations.

Configuration Rank 0 mode Rank 1 mode Correct Time Throughput
NVIDIA same-node device-direct device-direct YES 0.035 ms 111.09 GB/s
NVIDIA same-node host-staged host-staged YES 0.599 ms 6.52 GB/s
MetaX same-node host-staged host-staged YES 0.478 ms 8.17 GB/s
NVIDIA + MetaX heterogeneous host-staged host-staged YES 0.509 ms 7.68 GB/s
NVIDIA + MetaX heterogeneous device-direct host-staged YES 0.437 ms 8.94 GB/s

The same-node NVIDIA direct path improves average latency from 0.599 ms to 0.035 ms, about 17x compared with host staging. The mixed NVIDIA/MetaX run improves latency from 0.509 ms to 0.437 ms, about 1.16x.

Known Issues & Future Work

  • Only MPI Send/Recv are adapted; other MPI collectives are unchanged.
  • MetaX remains host-staged under auto because no stable vendor query interface is currently available.
  • The mixed NVIDIA/MetaX result is NVIDIA direct plus MetaX staging, not full end-to-end GPUDirect RDMA.
  • Device-aware means device pointers are passed directly to MPI; the final transport is still selected by MPI/UCX and may be CUDA IPC, shared memory, RDMA zero-copy, or an internal copy path.
  • Protocol-level confirmation with UCX logs is still outstanding.
  • Future work:
    • Add the MetaX vendor query once available.
    • Extend MpiBufferPlan to additional MPI collectives.

Test Results

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

metax-host-staged-mpi-send-recv.log
nvidia-device-direct-mpi-send-recv.log
nvidia-host-staged-mpi-send-recv.log
nvidia-metax-device-aware-mpi-send-recv.log
nvidia-metax-host-staged-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.
  • Third-party code is license-compatible and attributed.
  • No unsafe pointer arithmetic, uninitialized reads, or missing bounds checks were introduced.

@Jinyao618
Jinyao618 force-pushed the feat/mpi-device-aware-send-recv branch from 8c2505b to aae6bee Compare November 24, 2026 10:29
@Jinyao618
Jinyao618 force-pushed the feat/mpi-device-aware-send-recv branch from aae6bee to f2dbc05 Compare November 25, 2026 06: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