Skip to content

PortChannel: make CPU owners non-template - #975

Open
Changho Hwang (chhwang) wants to merge 11 commits into
microsoft:mainfrom
chhwang:chhwang/non-template-portchannel-owner
Open

Changho Hwang (chhwang) wants to merge 11 commits into
microsoft:mainfrom
chhwang:chhwang/non-template-portchannel-owner

Conversation

@chhwang

@chhwang Changho Hwang (chhwang) commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Make BasePortChannel and PortChannel non-template CPU owners so setup code can name, store, and pass either backend through one owner type. Keep backend-specific GPU handles and static GPU dispatch.

This follows merged #910 and #963 on main 4dab9f5033b718f55a2892da5399cb359c3b211e. It is not a Git revert of #910: GPUNetIO, GPU operations, concurrency/scratch policies, and current-main features remain intact, including EP #962 and FP8 behavior.

API and behavior

using Backend = mscclpp::PortChannelBackend;
mscclpp::PortChannel host = proxy.portChannel(semaphoreId, dstId, srcId);
auto hostHandle = host.deviceHandle<Backend::Host>();
mscclpp::PortChannel device(portSemaphore, remoteMemory, localMemory);
auto deviceHandle = device.deviceHandle<Backend::Device>();
  • GPU types remain BasePortChannelDeviceHandle<B> and PortChannelDeviceHandle<B>. Owners expose BasePortChannel::DeviceHandle<B> and PortChannel::DeviceHandle<B> alias templates; Port extraction requires an explicit backend.
  • Fixed extractors use mscclpp::DeviceHandle<mscclpp::MemoryChannel> and mscclpp::deviceHandle(owner). Port uses mscclpp::DeviceHandle<mscclpp::PortChannel, B> and mscclpp::deviceHandle<B>(owner); Base owners follow the same fixed/selected forms. The alias derives the actual chosen member expression, not a nested-type mapping or owner registry. Both helpers access the argument as a named lvalue, preserving cv/ref results without moving the owner or extending its lifetime. No Port default or ignored fixed-owner selector is provided; omitted, irrelevant, wrong-kind/out-of-domain and multiple selectors are rejected through requires/SFINAE-safe availability checks.
  • Type-only result deduction avoids host-only probe calls in kernel-scope aliases; the shared-storage regression remains covered. Documentation/comments are kept focused on usage.
  • Inline synchronization and independent binding variants retain shared owners/counters and registered-memory references. Wrong-backend, default/unbound, and mismatched binding extraction throws InvalidUsage; Host ID0 remains valid. Lifetime and moved-semaphore checks remain, including checking the Port semaphore handle before connection access.
  • Whole-owner copy/assignment carries synchronization and bindings together, including across backends. Both owners have defaulted noexcept move construction/assignment; moved-from owners reject extraction. Base-only assignment is not a rebind guarantee: same-backend replacement still requires compatible connection/proxy/regions. Prefer whole-owner replacement.
  • Raw initialized Semaphore construction creates a new synchronization wrapper and its expected/outbound counters. Channel copies share that wrapper; independently constructed owners do not share those counters merely because they use the same raw Semaphore. Default/moved-from raw inputs do not satisfy the documented precondition and are not guaranteed to throw InvalidUsage.
  • Current callers, factories, examples, tests, and public Doxygen/guides are adapted. Python Host names/properties/constructors and device_handle() remain unchanged. Device-backed Python construction uses PortDevice2DeviceSemaphore(raw_semaphore) or (communicator, connection), then PortChannel(semaphore, dst, src) (or the Base constructor) and explicit device_backend_handle().raw. Device handles have distinct types; no Python runtime return-type dispatcher is introduced. Keep the CPU owner and buffers alive during GPU use.
  • All 14 public GPU/device headers and all EP source files are byte-exact to main. No new T/View aliases, public configuration, probe targets, stdio/failure framework, backend/policy changes, semaphore implementation changes, or EP changes.

Source migration and tradeoffs

For Port owners only:

Old spelling New spelling
PortChannel<B> / BasePortChannel<B> PortChannel / BasePortChannel
Channel::DeviceHandle PortChannel::DeviceHandle<B> or BasePortChannel::DeviceHandle<B>
owner.deviceHandle() / mscclpp::deviceHandle(owner) owner.deviceHandle<B>() or mscclpp::deviceHandle<B>(owner)

The no-selector form mscclpp::DeviceHandle<PortChannel> remains unsupported; use mscclpp::DeviceHandle<PortChannel, B>. Generic Port callers carry the backend explicitly. Fixed Memory/Switch extractors retain their no-selector syntax, with result types derived from the actual member call. The namespace helper now has fixed and backend-selected cases, delegating runtime validation to the owner. Host and Device GPU handles remain distinct and nonassignable across backends.

Simpler CPU naming/storage costs explicit backend annotations and runtime owner/binding validation instead of backend guarantees in the owner type. Earlier aarch64/GCC 13.3 measurements at 8760e26 in both IB configurations showed Base owners 40 → 48 bytes and bound owners 80 → 88 bytes, all aligned to 8 bytes, with equal GPU handle sizes/alignment. This affected-utility gate does not remeasure layout: owner fields and public GPU headers remain unchanged. No transparent old C++ API/binary compatibility, performance gain, or unconditional LoC reduction is claimed.

Validation

Final head bacf7664ebb5349795b94d15b62ff207ce13f3f4 contains test-only corrections after production/binding pin ed51d471d52945f26e101c6833381ddfd102d4e4: integer enum comparisons and collective CUDA/IB/SM90+ admission before the two-rank Device test creates connections. All 553 other files are identical to ED51. Python test cleanup also clears retained exception frames and synchronizes reciprocal IPC imports before local assertions; the reported A100 CUDA12 95-minute pytest stall has not been reproduced or attributed.

Fresh ED51 validation: GB200/aarch64, CUDA 13.0.88, GCC 13.3, CMake 3.28.3; Release C++20, IB ON/OFF:

Gate Result
Core shared/static and unit/mp builds; sm100/sm90 compile coverage PASS both configurations
Selected real GPU units, including Host/Device Base/bound move and moved-from rejection cases 55/55 each, 110 total; zero failures/runtime skips
Collectives/EP/core Python/EP extension, actual fullmesh, legacy consumers and examples Build/compile PASS; non-unit binaries/kernels not executed
Corrected direct actual-extension smoke PASS distinct Device handle types/raw/defaults, constructor signatures, single exports, unchanged Host properties; four default-owner rejections and actual int(CppErrorCode.InvalidUsage) conversion
Final revision CUDA/ROCm CI Pending after this update; prior c8 CUDA/ROCm checks passed, not a new-revision HIP result

Unit selection: unit_tests --exclude-perf-tests --filter=-GpuIpcMemTest; four IPC/fabric cases and one performance case filtered, not runtime-skipped. Counter/storage tests use real GPU allocations with metadata-only connections, not GPUNetIO transport. The corrected smoke reused the unchanged actual ED51 extension; it did not execute the original pytest functions or real connection-backed Python Device constructors/lifetimes. Initial missing-enum-.value failure receipts were retained; comparisons now use integer conversion.

Original pytest/full-package imports/exports and two-rank Python Host NVLink/Device GPUNetIO tests remain unrun because generated _version.py and test/framework dependencies (including pytest/mpi4py/CUDA bindings and optional Torch/pybind11) are missing. No installs, fake packages or mocked connections bypassed them. Real Python Device construction/extraction and RDMA payloads remain unqualified. MP/non-unit consumers are compile-only. No inter-node/multi-rank transport, performance, new-revision HIP, installed-package or rendered-doc qualification is claimed. Layout figures above remain earlier 8760 measurements, not a fresh layout/ABI result.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Comment thread python/csrc/port_channel_py.cpp Resolved
@Binyang2014

Copy link
Copy Markdown
Contributor

Thanks for this PR, it looks good to me, just some minor comments

@chhwang
Changho Hwang (chhwang) marked this pull request as ready for review November 24, 2026 15:54
Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The HIP-specific handle-deduction fix lacks actual ROCm toolchain validation and final-head runtime qualification, requiring human review of pending CI and runtime evidence.

No open issues 🎉

What changed in this PR

This PR unifies BasePortChannel and PortChannel into non-template CPU owners while preserving backend-specific GPU handles and static GPU dispatch. It builds on #910 and #963 without changing GPU operations or EP behavior.

Changes:

  • Store Host or Device ownership and bindings in one owner type, with explicit backend selection and runtime validation during handle extraction.
  • Update generic handle deduction, callers, examples, and Python bindings while preserving Python public names.
  • Add selector, ownership, binding, and kernel-scope compile regressions; document source migration and lifetime requirements.

Reported CUDA compilation passed; final runtime and ROCm validation remain outstanding.

File Description
test/​unit/​semaphore_tests.cc Tests unified ownership, backend selection, and binding validation.
test/​unit/​proxy_service_tests.cu Updates proxy lifecycle and unassigned-owner tests.
test/​unit/​local_channel_tests.cu Selects Host handles explicitly.
test/​unit/​compile_tests.cu Adds selector, cv/ref, and kernel-scope deduction regressions.
test/​mscclpp-test/​common.hpp Updates mesh setup declarations to explicit Host handles.
test/​mscclpp-test/​common.cc Migrates mesh setup handle extraction.
test/​mscclpp-test/​alltoall_test.cu Migrates all-to-all handle types and storage.
test/​mscclpp-test/​allreduce_test.cu Migrates all-reduce handle types and storage.
test/​mscclpp-test/​allgather_test.cu Migrates all-gather handles and proxy extraction.
test/​mp_unit/​port_channel_tests.cu Selects handles by runtime IB mode.
test/​mp_unit/​mp_unit_tests.hpp Replaces the test owner variant with PortChannel.
test/​allgather_test_cpp.cu Migrates standalone all-gather handles and extraction.
src/​ext/​collectives/​include/​collective_utils.hpp Updates collective owner and handle storage.
src/​core/​port_channel.cc Implements unified state, bindings, and validated extraction.
src/​core/​include/​execution_kernel.hpp Uses explicit Host handles in kernel shared storage.
src/​core/​include/​execution_common.hpp Updates execution-plan Port handle arrays.
src/​core/​executor/​executor.cc Stores unified owners and extracts Host handles.
README.md Updates the introductory GPU handle example.
python/​csrc/​port_channel_py.cpp Adapts bindings while retaining public Python names.
include/​mscclpp/​port_channel.hpp Defines non-template owners and explicit backend extractors.
include/​mscclpp/​core.hpp Derives handle types from fixed or selected member expressions.
examples/​tutorials/​04-port-channel/​bidir_port_channel.cu Updates tutorial handle extraction.
examples/​torch-integration/​customized_allgather.cu Migrates Torch example handles and setup.
examples/​customized-collective-algorithm/​customized_allgather.cu Migrates native collective example handles and setup.
docs/​tutorials/​04-port-channel.md Explains Host extraction and owner lifetime.
docs/​guide/​mscclpp-torch-integration.md Updates the documented kernel handle type.
docs/​guide/​gpunetio.md Documents unified owners and explicit Device extraction.
docs/​cpp_api.rst Documents selectors, validation, ownership, and source migration.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 24, 2026 16:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The new connection-backed Python Device constructors and ownership lifetimes require human runtime qualification on real GPUNetIO/RDMA hardware, and final-revision HIP validation remains pending.

No open issues 🎉

Review effort: Balanced

@Binyang2014

Copy link
Copy Markdown
Contributor

/azp run mscclpp-ut

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@Binyang2014 Binyang Li (Binyang2014) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Copilot AI balanced review requested due to automatic review settings November 25, 2026 00:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The ownership-sensitive Python Device constructors and registration lifetimes require human review and real multi-rank GPUNetIO validation, while final-revision HIP qualification remains pending.

No open issues 🎉

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 26, 2026 13:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Python GPUNetIO/Device construction and ownership lifetimes lack real connection-backed two-rank validation, while final-revision HIP checks remain unexecuted and the pytest stall unresolved, requiring qualified runtime and portability review.

No open issues 🎉

Review effort: Balanced

This branch has not been deployed

No deployments
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