Skip to content

feat: support broadcast with OpenMPI backend implementation#11

Merged
halfman510 merged 6 commits into
InfiniTensor:masterfrom
GordonYang1:feat/ompi-broadcast
May 19, 2026
Merged

feat: support broadcast with OpenMPI backend implementation#11
halfman510 merged 6 commits into
InfiniTensor:masterfrom
GordonYang1:feat/ompi-broadcast

Conversation

@GordonYang1
Copy link
Copy Markdown
Collaborator

@GordonYang1 GordonYang1 commented May 18, 2026

Summary

This PR adds two new collective communication operators: infiniBroadcast and infiniBcast() along with its OpenMPI backend implementation, plus the corresponding example program examples/broadcast.cc.

Public API

infiniResult_t infiniBroadcast(const void *sendbuff, void *recvbuff,
                               size_t count, infiniDataType_t datatype,
                               int root, infiniComm_t comm, void *stream);

infiniResult_t infiniBcast(void *buff, size_t count, infiniDataType_t datatype,
                           int root, infiniComm_t comm, void *stream);

Parameter order matches ncclBroadcast exactly, per the C++ rule in CONTRIBUTING.md ("For functions that correspond to NCCL, parameter order must match the NCCL interface exactly").

Changes

  • Broadcast Operator Support

    • add the Broadcast base class in src/base/broadcast.h with
      parameter validation (root range, null pointer, count = 0
      short-circuit);
    • add the OpenMPI backend implementation in src/ompi/impl/broadcast.h,
      using a host-staging path (consistent with the existing AllReduce
      implementation);
    • chunk the buffer by INT_MAX bytes and call MPI_Bcast repeatedly,
      so that arbitrarily large count values are supported;
    • support both in-place (sendbuff == recvbuff) and out-of-place
      calling conventions;
    • in out-of-place mode, allow non-root ranks to pass nullptr as
      sendbuff (this convention is exercised by the test suite).
    • add Bcast which corresponding to the deprecated API in NCCL, but here it is simply an in-place alias for Broadcast.
  • Broadcast Example

    • add examples/broadcast.cc covering 3 scenarios:
      • out-of-place infiniBroadcast()
      • in-place infiniBroadcast()
      • legacy in-place infiniBcast()

Known Issues & Future Work

  • The OMPI backend uses the host-staging path. This PR does not cover GPU-direct or NCCL paths; an NCCL-based Broadcast backend can be added in a follow-up PR.
  • The INT_MAX-byte chunking pattern currently only lives in Broadcast. AllReduce could benefit from the same treatment in the future.
  • Broadcast::Execute's argument-validation style is kept consistent with AllReduce::Execute — invalid input returns kInvalidArgument and emits a LOG line. The "invalid root" test case intentionally triggers these log lines, which is expected output, not a failure.

Test Environment & Results

all_gather.log
all_reduce.log
reduce_scatter.log
broadcast.log

@GordonYang1 GordonYang1 changed the title Feat/ompi broadcast feat: support broadcast with OpenMPI backend implementation May 18, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a129ea4e4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/ompi/impl/broadcast.h
Comment on lines +47 to +49
CHECK_STATUS(Rt, Rt::Memcpy(host_buf, send_buff, total_bytes,
Rt::MemcpyDeviceToHost));
CHECK_STATUS(Rt, Rt::StreamSynchronize(static_cast<Rt::Stream>(stream)));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent root-only early exit before collective

In the root branch, CHECK_STATUS can return immediately when the D2H copy or stream sync fails, but non-root ranks still proceed to MPI_Bcast; this mismatched collective participation can hang the whole communicator. This shows up whenever root hits a runtime error (e.g., bad device pointer or prior sticky CUDA error) while other ranks are healthy.

Useful? React with 👍 / 👎.

Comment thread src/ompi/impl/broadcast.h
Comment on lines +66 to +67
CHECK_STATUS(Rt, Rt::Memcpy(recv_buff, host_buf, total_bytes,
Rt::MemcpyHostToDevice));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Free staging buffer on error returns

If the final host-to-device copy fails, CHECK_STATUS returns before host_buf is freed, leaking total_bytes on each failed call. With large broadcasts this can consume significant host memory quickly under repeated error conditions.

Useful? React with 👍 / 👎.

GordonYang1 and others added 4 commits May 19, 2026 12:57
…ram instead of a test program

 - refactor `examples/broadcast.cc`
 - fix the formatting issues in `src/ompi/impl/broadcast.h`
 - support `infiniBcast()` which in some CCLs are labeled as deprecated, but here it is simply an alias for `infiniBroadcast()`
 - update `examples/broadcast.cc` to also illustrate and test out `infiniBcast()`
@Ziminli Ziminli force-pushed the feat/ompi-broadcast branch from 1a129ea to 9d190e2 Compare May 19, 2026 14:07
@Ziminli Ziminli requested a review from halfman510 May 19, 2026 14:32
Comment thread src/base/broadcast.h Outdated
Comment thread src/ompi/impl/broadcast.h Outdated
Comment thread src/base/broadcast.h Outdated
Comment thread src/base/broadcast.h
@Ziminli Ziminli requested a review from halfman510 May 19, 2026 15:05
@halfman510 halfman510 merged commit d507fdd into InfiniTensor:master May 19, 2026
@GordonYang1 GordonYang1 deleted the feat/ompi-broadcast branch May 20, 2026 01:30
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.

3 participants