Skip to content

[EP] Support Hygon DCU platform for Mooncake EP and TransferEngine - #4810

Open
LiChangXin-KylinSoft wants to merge 3 commits into
kvcache-ai:mainfrom
LiChangXin-KylinSoft:feat/hygon-dcu-support
Open

LiChangXin-KylinSoft wants to merge 3 commits into
kvcache-ai:mainfrom
LiChangXin-KylinSoft:feat/hygon-dcu-support

Conversation

@LiChangXin-KylinSoft

@LiChangXin-KylinSoft LiChangXin-KylinSoft commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR introduces end-to-end support for the Hygon DCU (DTK/HIP) accelerator platform across Mooncake EP and TransferEngine:

  1. mooncake-common:
    • Added automatic detection for Hygon DTK installation root, include paths, library directories, compiler (
      vcc/hipcc wrapper), and DTK version in common.cmake.
  2. mooncake-ep:
    • Adapted 64-thread wavefront execution model (native hardware warp size for DCU) and logical 32-lane sub-warp mappings.
    • Provided warp shuffle primitives (__shfl_xor_sync, ep_shfl_xor, warp_reduce_sum) and CTA-wide barrier synchronization for split SEND/RECV paths.
    • Managed expert slot allocations via CTA shared memory to ensure safe inter-lane communication.
    • Bypasses JIT runtime in favor of ahead-of-time compiled kernels on DCU.
  3. mooncake-transfer-engine:
    • Added DMA-BUF memory region registration for Hygon DCU via HSA portable export (hsa_amd_portable_export_dmabuf).
    • Added hardware operation primitives (hygon_ops.cuh) and enabled P2P device transport for DCU.
    • Bypasses IBGDA initialization in native EP and uses intra-node P2P transport.
  4. mooncake-wheel & Python layer:
    • Decoupled EP from PG: mooncake-pg is not required on Hygon. Buffer automatically derives metadata device (cpu for Gloo backend, cuda for device backends) from the caller-supplied process group.
    • Added serialized IPC open sequence on DCU to prevent driver-side races during reciprocal IPC opens.

Suggested Merge Priority

  • P0 - Urgent
  • P1 - High
  • P2 - Normal
  • P3 - Low

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • Mooncake Conductor (mooncake-conductor)
  • Reshard (mooncake-reshard)
  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Integration (mooncake-integration)
  • P2P Store (mooncake-p2p-store)
  • Python Wheel (mooncake-wheel)
  • Common (mooncake-common)
  • Mooncake RL (mooncake-rl)
  • CI/CD
  • Docs
  • Other

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Breaking change
  • Documentation update
  • Performance improvement
  • Other

How Has This Been Tested?

Tested on Hygon DCU environment:
Test commands:
`�ash

1. Run EP grid tests

pytest python/tests/ep/test_ep_grid.py

2. TransferEngine memory registration & P2P test

Validated with local DMA-BUF MR registration and DCU P2P communication

`

Test results:

  • Unit tests pass
  • Integration tests pass (if applicable)
  • Manual testing done (describe below)

Checklist

  • I have performed a self-review of my own code
  • I have formatted my code using ./scripts/code_format.sh
  • I have run pre-commit on the files changed in this PR and all hooks pass
  • I have updated the documentation (if applicable)
  • I have added tests to prove my changes are effective
  • For changes >500 LOC: I have filed an RFC issue

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (specify below)

The implementation and adaptation in this PR were generated using Google Antigravity (Advanced Agentic Coding Assistant).

@UNIDY2002 UNIDY2002 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for your contribution.

I'm wondering what is blocking Hygon EP from using the GPU as the control plane.

Also, please fix the formatting issues as in the CI logs.

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Outdated
@@ -1,3 +1,4 @@
// Mooncake EP dispatch & combine kernels (Hygon Stage 19: glc slc L2 bypass)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Mooncake EP dispatch & combine kernels (Hygon Stage 19: glc slc L2 bypass)

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Outdated
EP_DEVICE_ASSERT(num_bytes_per_msg % sizeof(int4) == 0);

// Communication context — platform dispatch is inside comm_device.cuh
// Communication context �?platform dispatch is inside comm_device.cuh

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Communication context �?platform dispatch is inside comm_device.cuh
// Communication context — platform dispatch is inside comm_device.cuh

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Outdated
void* write_dst = mc_route_put(comm_ctx, dst_rank, dst_ptr);
if (write_dst != nullptr) {
// Local or P2P path — warp-cooperative copy
// Local or P2P path �?warp-cooperative copy

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Local or P2P path �?warp-cooperative copy
// Local or P2P path — warp-cooperative copy

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Outdated
#endif
} else {
// IBGDA path — send directly from source buffer
// IBGDA path �?send directly from source buffer

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// IBGDA path �?send directly from source buffer
// IBGDA path — send directly from source buffer

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Outdated
EP_STATIC_ASSERT(num_bytes_per_slot % sizeof(int4) == 0, "Invalid vectorization");

// Communication context — platform dispatch is inside comm_device.cuh
// Communication context �?platform dispatch is inside comm_device.cuh

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Communication context �?platform dispatch is inside comm_device.cuh
// Communication context — platform dispatch is inside comm_device.cuh

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Outdated
void* write_dst = mc_route_put(comm_ctx, dst_rank, dst_ptr);
if (write_dst != nullptr) {
// Local or P2P path — warp-cooperative copy
// Local or P2P path �?warp-cooperative copy

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Local or P2P path �?warp-cooperative copy
// Local or P2P path — warp-cooperative copy

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Outdated
#endif
} else {
// IBGDA path — stage to send buffer then RDMA write
// IBGDA path �?stage to send buffer then RDMA write

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// IBGDA path �?stage to send buffer then RDMA write
// IBGDA path — stage to send buffer then RDMA write

@@ -1,4 +1,4 @@
# Device transport sources — conditional on GPU vendor. mlx5gda.cpp (IBGDA QP
# Device transport sources �?conditional on GPU vendor. mlx5gda.cpp (IBGDA QP

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# Device transport sources �?conditional on GPU vendor. mlx5gda.cpp (IBGDA QP
# Device transport sources — conditional on GPU vendor. mlx5gda.cpp (IBGDA QP

return size;
}

at::Tensor MooncakeBackend::getActiveRanksTensor() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please explain in detail why we have to change the impl of getActiveRanksTensor().

@LiChangXin-KylinSoft

Copy link
Copy Markdown
Contributor Author

@UNIDY2002 Thank you very much for the thorough review and valuable suggestions!

I have pushed commit 8b771cf addressing all the points:

1. Comment formatting & Suggested changes

  • Applied all 8 suggested changes, removed the temporary header comment in mooncake_ep_kernel.cu, and cleaned up the non-ASCII / corrupted comment characters.
  • Formatted all touched files with ruff and verified codespell with zero warnings.

2. Platform-specific mode in p2p_device_transport.cpp

  • Wrapped the eager cudaDeviceEnablePeerAccess bypass strictly inside #if defined(USE_HYGON).
  • Restored the original eager cudaDeviceEnablePeerAccess logic for NVIDIA CUDA and other platforms under #else, ensuring non-Hygon platforms' behavior remains 100% unchanged.

3. Regarding getActiveRanksTensor()

  • Why it was changed: In the upstream implementation, getActiveRanksTensor() returns the caller-owned device mirror activeRanks_. On DTK/ROCm runtimes(8 x Hygon K100 AI DCU), updates to device mirrors on internal private streams are not immediately observable by the host without explicit stream synchronization, occasionally exposing stale membership data or all zeros in Python during bootstrapping/recovery. Querying mooncakePgCommGetActiveRanks directly inspects the C++ communicator's authoritative topology state.
  • Platform isolation: To prevent any behavioral discrepancy on non-Hygon platforms, we have now wrapped this authoritative snapshot logic strictly under #if defined(USE_HYGON), while keeping return activeRanks_; untouched for all non-Hygon platforms.

4. Regarding GPU vs CPU control plane in Hygon EP

The reasons for using the CPU (Gloo) control group for bootstrapping and the phase fence on Hygon are:

  1. Driver-level concurrency during IPC import: In earlier Hygon DTK/ROCm runtimes, concurrently executing GPU-based collective operations (such as RCCL) while ranks concurrently perform cross-device P2P IPC imports (hipIpcOpenMemHandle) could trigger driver-level lock contention or resource deadlocks. Using the lightweight host CPU control group ensures serialized, deterministic P2P handshake without driver conflicts.
  2. Phase fence visibility for split SEND/RECV: In the split SEND/RECV execution model, cross-device completion flags require reliable memory visibility across all ranks before the RECV phase launches. Aligning rank phases via the CPU control group guarantees global memory visibility across devices on DCU.

Note: Only the metadata handshake and phase fence use the CPU control group; all actual EP payload transfer remains 100% on the high-speed DCU P2P / DMA-BUF RDMA data path.

@UNIDY2002

Copy link
Copy Markdown
Collaborator

Thank you for your updates! Have you tried mooncake PG for the metadata handshake?

1 similar comment
@UNIDY2002

Copy link
Copy Markdown
Collaborator

Thank you for your updates! Have you tried mooncake PG for the metadata handshake?

@github-actions github-actions Bot added the size/L 1001+ changed lines (additions + deletions) label Oct 30, 2026
@LiChangXin-KylinSoft

Copy link
Copy Markdown
Contributor Author

Yes, i actually used Mooncake PG (backend="mooncake" via self.group) for the metadata handshake and bootstrap initially during my DCU bring-up!

However, i encountered several concrete synchronization and timing issues in our testing logs:

1. Device Memory Timing Leading to All-Zero GID in connect()

During connect(), metadata like subnet_prefixes, interface_ids, and local_qpns were transferred as CUDA device tensors via Mooncake PG. On Hygon DCU, due to stream synchronization and memory visibility timing during early multi-process bootstrapping, peer ranks occasionally read unpopulated device memory (all zeros).

This resulted in an all-zero remote DGID (0000:0000:...:0000), which the Mellanox Verbs kernel driver rejected with -EINVAL (22) during ibv_modify_qp (init2rtr):

# Excerpt from test log:
[mlx5gda fallback] ibv_modify_qp (init2rtr) failed: ret=22 errno=22 (Invalid argument) dest_qpn=0x907b mtu=3 active_mtu=3 is_global=1 dlid=0
[EP IBGDA] init2rtr failed for QP 64 (roce=1 gid_idx=3 remote_qpn=36987 udp_sport=0 hop_limit=255)
[EP] IBGDA connectPeers failed, falling back to P2P-only path

2. Early Bootstrap Timing and receive buffer is null

In fallback collective communication (_fallback_dispatch), when calling dist.all_gather_into_tensor(all_x, x_padded, group=self.group) with Mooncake PG:

# Excerpt from log.log:
  File ".../mooncake/mooncake_ep_buffer.py", line 888, in _fallback_dispatch
    dist.all_gather_into_tensor(all_x, x_padded, group=self.group)
  File ".../torch/distributed/distributed_c10d.py", line 3435, in all_gather_into_tensor
    work = group._allgather_base(output_tensor, input_tensor, opts)
RuntimeError: mooncakePgAllGather failed: invalid argument: receive buffer is null

This was triggered because during early bootstrapping, Transfer Engine RPC published its listening address before local transport installation fully finished, causing Local segment descriptor not found and leaving activeRanks unready (reporting 0), which collapsed the output tensor shape and caused a null buffer error.

3. Cross-Backend Deadlock with Phase Fence

For the split SEND/RECV execution model, cross-device completion requires a deterministic host-side phase fence. When mixing Mooncake PG's GPU task-polling barrier with CPU phase fences, i observed rank-inversion deadlocks where one rank proceeded past the Mooncake PG barrier while other ranks were still blocked inside Mooncake PG GPU worker loops.


Conclusion

To bypass all device-stream racing and driver concurrency issues on DCU, i introduced the dedicated host CPU control group (dist.new_group(backend="gloo")) strictly for the metadata handshake and phase fence.

@UNIDY2002

Copy link
Copy Markdown
Collaborator

Thanks for your response! I have a few follow-up questions:

  1. Based on your response, it seems that EP on Hygon does not actually depend on PG. If that's the case, I'd recommend splitting the PR into EP part and PG part to make review easier and cut down code conflict radium.
  2. Can Mooncake PG alone work on Hygon DCU?
  3. I didn't expect the _fallback_dispatch path to be actually used in production. Which path is your PR targeting in the EP module, P2P, IBGDA, or fallback path?

@LiChangXin-KylinSoft

Copy link
Copy Markdown
Contributor Author

Thanks for the suggestion!

I would like to clarify a few things:

To be completely upfront, I did not actually port or validate Mooncake PG for Hygon DCU. The only reason mooncake-pg was touched in this PR is that the root CMakeLists.txt unconditionally invokes add_subdirectory(mooncake-pg) when WITH_EP=ON, which previously threw a FATAL_ERROR under USE_HYGON. Those changes were merely minimal build stubs to allow mooncake-ep to compile without breaking the build.

Since EP on Hygon does not depend on PG at all, and I have not done proper functional validation for PG:

  1. I will not submit a separate PG PR for now.
  2. I prefer to completely drop/revert the mooncake-pg modifications from this PR (or bypass building mooncake-pg when building EP on Hygon), making this PR strictly focused on Mooncake EP.
  3. Target Path in EP & Background:
    • Coming from an OS vendor perspective, our core goal is broad hardware ecosystem enablement and compatibility.
    • For this target, this PR focuses on the P2P fast path (intra-node PCIe / P2P IPC), which we have implemented and verified.
    • Regarding IBGDA: I actually experimented extensively with Mellanox RoCE NICs on Hygon DCU, but repeatedly encountered driver-level memory registration (cudaHostRegister failed: invalid argument) and remote I/O constraints. Hence, IBGDA is stubbed out for now.
    • The _fallback_dispatch mentioned in the previous log was purely triggered by the CI fault-tolerance unit test (test_ep_fallback_no_p2p_nofail, which explicitly sets disable_p2p=True to verify degradation behavior).

Attached Test Log:
log_rdma_ep.log

@UNIDY2002 UNIDY2002 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Three high-priority review points below. The first is a platform-detection correctness issue; the second concerns the Hygon IBGDA-disabled build path; the third concerns process-group ownership in the Python Buffer layer.

Comment thread python/mooncake/mooncake_ep_buffer.py Outdated
def _detect_hygon() -> bool:
if _env_enabled("MOONCAKE_EP_USE_HYGON"):
return True
if bool(getattr(torch.version, "hip", None)):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

torch.version.hip is also populated for ordinary AMD ROCm environments, so this branch classifies every HIP runtime as Hygon and returns before the device-name check. That makes AMD processes enter the Hygon-specific Gloo control group, serialized IPC, split phase-fence, and CPU fallback paths.

if((USE_CUDA OR USE_MUSA OR USE_MACA) AND NOT USE_CXI)
list(APPEND DEVICE_TRANSPORT_SOURCES ibgda_device_transport.cpp mlx5gda.cpp)
elseif(USE_HYGON)
list(APPEND DEVICE_TRANSPORT_SOURCES ibgda_device_transport_maca_stub.cpp)

@UNIDY2002 UNIDY2002 Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ibgda_device_transport_maca_stub.cpp has been removed from main and is also absent from this PR head, so this source list makes USE_HYGON=ON fail at configure/build time. Please reconsider the Hygon IBGDA-disabled path instead of referencing the deleted MACA stub. As one possible direction, the standard IBGDA implementation could remain available for the factory symbols while Hygon skips IBGDA initialization in the native EP path and uses P2P-only.

Comment thread python/mooncake/mooncake_ep_buffer.py Outdated
# scoped to Hygon and use PyTorch's standard Gloo backend so EP does not
# require a process-group implementation-specific CPU backend.
# CUDA/MACA retain their original process-group behavior.
self._hygon_control_group: Optional[dist.ProcessGroup] = None

@UNIDY2002 UNIDY2002 Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please consider letting the caller choose the process group passed to Buffer. The intended shape is:

# At the call site:
buffer_group = (
    dist.new_group(ranks=ep_ranks, backend="gloo")
    if is_hygon
    else group
)
buf = Buffer(buffer_group, num_ep_buffer_bytes=...)

For Hygon, the caller supplies the Gloo group; other platforms keep passing their existing group. Buffer should then derive the metadata tensor device from the supplied group, for example:

backend = dist.get_backend(self.group)
metadata_device = torch.device("cpu" if backend == "gloo" else "cuda")

This lets Buffer use the caller-selected group for metadata exchange and phase fences without creating a hidden _hygon_control_group or duplicating group membership/lifecycle management internally.

@LiChangXin-KylinSoft LiChangXin-KylinSoft changed the title [Feature] Support Hygon DCU platform for EP, PG, and TransferEngine DMA-BUF RDMA [EP] Support Hygon DCU platform for Mooncake EP and TransferEngine Nov 10, 2026
@LiChangXin-KylinSoft

LiChangXin-KylinSoft commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@UNIDY2002 Thank you for the detailed feedback and suggestions!

We have synced with the latest upstream main and addressed all three review points in the latest push:

1. Platform Detection Guarding Generic AMD ROCm

  • Updated _detect_hygon() in python/mooncake/mooncake_ep_buffer.py to ensure torch.version.hip alone does not classify the environment as Hygon.
  • Now, Hygon is only detected if the device name explicitly contains "hygon", "dcu", "z100", or "k100", or if MOONCAKE_EP_USE_HYGON is explicitly enabled. Standard AMD ROCm environments (MI300, MI250, etc.) remain completely untouched.

2. Removal of Deleted MACA Stub & Clean P2P-Only Path

  • Cleanly removed the reference to the deleted ibgda_device_transport_maca_stub.cpp in mooncake-transfer-engine/src/transport/device/CMakeLists.txt.
  • Guarded TransferEngineImpl::getOrCreateRdmaTransport under #if defined(USE_HYGON) return nullptr; #else ... #endif, allowing TransferEngine to enforce intra-node P2P transport cleanly without requiring IBGDA factory symbols.

3. Process Group Ownership & Elimination of _hygon_control_group

  • Following your recommendation, we have completely removed the internal self._hygon_control_group from Buffer.
  • Ownership of process group creation is now fully returned to the caller:
    • On Hygon DCU, callers (such as in test_ep_grid.py) initialize / supply a standard PyTorch backend="gloo" process group.
    • On CUDA / other platforms, callers supply their existing process group.
  • Buffer now derives the metadata exchange device via _bootstrap_device(), returning torch.device("cpu") when backend == "gloo".
  • All metadata exchanges in connect(), phase fences in _maca_phase_fence(), serialized IPC barriers, and fallback collectives now uniformly operate on self.group and _bootstrap_device() without hidden state.

4. Mooncake PG Decoupled & Upstream Merge

  • In line with PR [EP] Decouple PG builds and add TCPStore bootstrap #5312 ([EP] Decouple PG builds and add TCPStore bootstrap), we have set WITH_PG=OFF by default when USE_HYGON=ON in CMakeLists.txt.
  • All modifications to mooncake-pg have been completely reverted and dropped from this PR. The PR diff now strictly and cleanly focuses on Mooncake EP and TransferEngine P2P support.
  • All merge conflicts with upstream main are resolved (mergeable: true).

@UNIDY2002

Copy link
Copy Markdown
Collaborator

Comment thread python/mooncake/mooncake_ep_buffer.py Outdated
group=self.group,
)
if work is not None:
work.wait()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we go without the work.wait pattern? As far as I understand, the stream is usually synchronized at the next synchronization point, and is naturally streamlined before that point.

Also, the code seems duplicated between the two arms. Is it possible to simplify the pattern?

@LiChangXin-KylinSoft

Copy link
Copy Markdown
Contributor Author

Thanks for the review and the heads-up on the CI!

I have addressed the review feedback and resolved all CI issues in the latest commit:

  1. Simplified Fallback Collectives:

    • Eliminated the work.wait() pattern in both _fallback_dispatch and _fallback_combine.
    • Unified the CPU and device collective branches using ctrl_dev = self._bootstrap_device(), removing duplicate code.
  2. Fixed CI & Build Issues:

    • CMake Syntax: Removed the extraneous endif() in root CMakeLists.txt that broke flow control on macOS and CTest.
    • Python Ruff Formatting: Fixed import sorting and line wrapping in mooncake_ep_buffer.py and test_ep_grid.py (verified clean with ruff check and scripts/ci/check_changed_python_format.py).
    • C++ Formatting (Clang-Format): Re-aligned all modified #if macros and expressions in mooncake-ep and mooncake-transfer-engine to Google 80-column style.
    • Hygon Build: Set USE_HYGON_DMABUF default to OFF in TransferEngine since Hygon EP focuses on the P2P transport. Verified full compilation (mooncake_ep_device, transfer_engine, and _ep) inside the official Hygon DTK 26.04 container.
    • DCO: Cleaned up commits and ensured valid Signed-off-by trailers.

Please take another look when you have a moment. Thanks!

@UNIDY2002 UNIDY2002 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do you think we should enable the EP module in the Hygon CI? I think it can help us do quick and continuous validations.

Comment thread python/mooncake/mooncake_ep_buffer.py Outdated
Comment on lines +967 to +977
res = get_active_ranks(self.backend).to(device=device, dtype=dtype)
if res.numel() == self.group_size:
# If all ranks report inactive (e.g. uninitialized Coordinator view),
# treat all ranks as active.
if (res != 0).sum().item() == 0:
return torch.ones((self.group_size,), dtype=dtype, device=device)
# Local rank must always be active if this process is executing.
if res[self.rank].item() == 0:
res = res.clone()
res[self.rank] = 1
return res

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we are using gloo for Hygon, I suppose we should not touch these lines of code.

@@ -7,6 +7,7 @@
set(DEVICE_TRANSPORT_SOURCES p2p_device_transport.cpp)
if((USE_CUDA OR USE_MUSA OR USE_MACA) AND NOT USE_CXI)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we include Hygon in this condition and reuse the standard IBGDA implementation? The default EP constructor still calls createIbgdaDeviceTransport() in mooncake_ep_buffer.cpp, so excluding its implementation leaves an unresolved symbol. Hygon can skip IBGDA initialization in the native EP constructor while retaining these sources to resolve the factory symbol. Please verify that these sources compile with DTK.

Comment thread CMakeLists.txt Outdated
endif()

if(WITH_EP AND USE_CUDA)
if(WITH_EP AND (USE_CUDA OR USE_HYGON))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The USE_HYGON case here is unreachable: Hygon EP takes the earlier if(WITH_EP AND (USE_XPU OR USE_HYGON)) branch, while this staging target is inside its mutually exclusive elseif(WITH_EP OR WITH_PG). As a result, libmooncake_ep_device.so is never copied to ep_pg_staging. The wheel script excludes this library from auditwheel and injects it afterward from that staging directory, so the Hygon wheel will miss the device library required by _ep. Could you move the EP device-library staging outside these mutually exclusive branches and verify that a freshly installed Hygon wheel can import the native EP module?

@LiChangXin-KylinSoft

Copy link
Copy Markdown
Contributor Author

We have updated the PR accordingly:

  1. Active ranks tensor (mooncake_ep_buffer.py): Reverted those lines back to the clean upstream version since Hygon uses Gloo and does not touch mooncake.pg.
  2. IBGDA transport sources (device/CMakeLists.txt & mooncake_ep_buffer.cpp): Added USE_HYGON to the IBGDA source compilation so that createIbgdaDeviceTransport symbol is properly exported, while skipping IBGDA initialization in the native EP constructor on Hygon.
  3. EP device library staging (CMakeLists.txt): Moved mooncake_ep_device_stage outside the mutually exclusive if/elseif construct so libmooncake_ep_device.so is always copied into ep_pg_staging and packaged into the wheel for Hygon.
  4. Hygon CI (ci_hygon.yml): Added -DWITH_EP=ON to the CMake build configuration in ci_hygon.yml.

@UNIDY2002 UNIDY2002 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The latest changes address my previous concerns about Hygon detection, caller-owned control groups, IBGDA initialization/linking, device-library staging, and the active-rank mask changes.

Could you also add EP coverage to the Hygon CI? The workflow currently builds the wheel and runs Transfer Engine and Store tests, but does not exercise EP. Please install the produced wheel in the test environment, verify that mooncake.ep imports successfully, and run a small multi-rank dispatch/combine correctness test using the Gloo control group. This would cover both the packaged native libraries and the Hygon EP runtime path.

Comment thread .github/workflows/ci_hygon.yml Outdated
mkdir -p build
cd build
cmake .. -DUSE_HTTP=ON -DCMAKE_BUILD_TYPE=Release
cmake .. -DUSE_HTTP=ON -DWITH_EP=ON -DCMAKE_BUILD_TYPE=Release

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please also pass -DUSE_HYGON=ON here. It defaults to OFF in common.cmake, and sourcing the DTK environment does not enable the CMake option. With only WITH_EP=ON, a clean configure defaults WITH_PG to ON and reaches the PG configuration error (Mooncake PG currently requires one of USE_CUDA, USE_MUSA, or USE_MACA), rather than exercising the Hygon EP build path.

@LiChangXin-KylinSoft

Copy link
Copy Markdown
Contributor Author

Thanks for the reminder and suggestions! i have updated the PR:

  1. CMake Options: Passed -DUSE_HYGON=ON along with -DWITH_EP=ON in ci_hygon.yml so that WITH_PG defaults to OFF cleanly.
  2. Hygon EP CI Coverage: Added a dedicated test-ep job in ci_hygon.yml and scripts/hygon/test_ep.sh. It installs the generated wheel, verifies import mooncake.ep, and runs the multi-rank dispatch/combine test using the Gloo control group (test_ep_grid.py).

lichangxin added 3 commits November 19, 2026 13:40
- Port and enable Mooncake EP on Hygon DCU platform using DTK toolkit.
- Implement device-side memory ordering primitives and warp operations in hygon_ops.cuh.
- Handle 64-lane hardware wavefront splitting into 32-lane logical warps for Hygon.
- Support intra-node P2P fast path for TransferEngine on Hygon.
- Support Gloo CPU collective bootstrapping and streamlined fallback collectives.
- Add Hygon platform detection and tests.

Signed-off-by: lichangxin <lichangxin@kylinos.cn>
- Move mooncake_ep_device_stage outside mutually exclusive branches in CMakeLists.txt
  so libmooncake_ep_device.so is properly staged and packaged into Hygon wheels.
- Include standard IBGDA device sources for Hygon to resolve createIbgdaDeviceTransport
  factory symbol while skipping runtime IBGDA init in native EP constructor.
- Add defensive fallback defines for DTK compatibility in cuda_alike.h.
- Revert untouched mooncake.pg active ranks fallback logic in mooncake_ep_buffer.py.
- Enable WITH_EP=ON in ci_hygon.yml for continuous EP validation.

Signed-off-by: lichangxin <lichangxin@kylinos.cn>
- Pass -DUSE_HYGON=ON alongside -DWITH_EP=ON in ci_hygon.yml to ensure
  clean CMake configuration without defaulting to Mooncake PG.
- Add test_ep.sh script to install the built wheel, verify mooncake.ep
  import, and run multi-rank dispatch/combine tests with Gloo backend.
- Add test-ep job and integrate EP test verification into hcu-pr-gate.
- Guard test_ep_grid.py against runners with fewer than 2 devices.

Signed-off-by: lichangxin <lichangxin@kylinos.cn>
@UNIDY2002

Copy link
Copy Markdown
Collaborator

@alogfans Please take a look when you have time, thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants