Repository navigation
[EP] Support Hygon DCU platform for Mooncake EP and TransferEngine - #4810
LiChangXin-KylinSoft wants to merge 3 commits into
Conversation
UNIDY2002
left a comment
There was a problem hiding this comment.
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.
| @@ -1,3 +1,4 @@ | |||
| // Mooncake EP dispatch & combine kernels (Hygon Stage 19: glc slc L2 bypass) | |||
There was a problem hiding this comment.
| // Mooncake EP dispatch & combine kernels (Hygon Stage 19: glc slc L2 bypass) |
| 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 |
There was a problem hiding this comment.
| // Communication context �?platform dispatch is inside comm_device.cuh | |
| // Communication context — platform dispatch is inside comm_device.cuh |
| 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 |
There was a problem hiding this comment.
| // Local or P2P path �?warp-cooperative copy | |
| // Local or P2P path — warp-cooperative copy |
| #endif | ||
| } else { | ||
| // IBGDA path — send directly from source buffer | ||
| // IBGDA path �?send directly from source buffer |
There was a problem hiding this comment.
| // IBGDA path �?send directly from source buffer | |
| // IBGDA path — send directly from source buffer |
| 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 |
There was a problem hiding this comment.
| // Communication context �?platform dispatch is inside comm_device.cuh | |
| // Communication context — platform dispatch is inside comm_device.cuh |
| 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 |
There was a problem hiding this comment.
| // Local or P2P path �?warp-cooperative copy | |
| // Local or P2P path — warp-cooperative copy |
| #endif | ||
| } else { | ||
| // IBGDA path — stage to send buffer then RDMA write | ||
| // IBGDA path �?stage to send buffer then RDMA write |
There was a problem hiding this comment.
| // 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 | |||
There was a problem hiding this comment.
| # 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() { |
There was a problem hiding this comment.
Please explain in detail why we have to change the impl of getActiveRanksTensor().
|
@UNIDY2002 Thank you very much for the thorough review and valuable suggestions! I have pushed commit 1. Comment formatting & Suggested changes
2. Platform-specific mode in
|
|
Thank you for your updates! Have you tried mooncake PG for the metadata handshake? |
1 similar comment
|
Thank you for your updates! Have you tried mooncake PG for the metadata handshake? |
|
Yes, i actually used Mooncake PG ( However, i encountered several concrete synchronization and timing issues in our testing logs: 1. Device Memory Timing Leading to All-Zero GID in
|
|
Thanks for your response! I have a few follow-up questions:
|
|
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 Since EP on Hygon does not depend on PG at all, and I have not done proper functional validation for PG:
Attached Test Log: |
UNIDY2002
left a comment
There was a problem hiding this comment.
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.
| def _detect_hygon() -> bool: | ||
| if _env_enabled("MOONCAKE_EP_USE_HYGON"): | ||
| return True | ||
| if bool(getattr(torch.version, "hip", None)): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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.
|
@UNIDY2002 Thank you for the detailed feedback and suggestions! We have synced with the latest upstream 1. Platform Detection Guarding Generic AMD ROCm
2. Removal of Deleted MACA Stub & Clean P2P-Only Path
3. Process Group Ownership & Elimination of
|
| group=self.group, | ||
| ) | ||
| if work is not None: | ||
| work.wait() |
There was a problem hiding this comment.
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?
9210035 to
0c0ea84
Compare
|
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:
Please take another look when you have a moment. Thanks! |
UNIDY2002
left a comment
There was a problem hiding this comment.
Do you think we should enable the EP module in the Hygon CI? I think it can help us do quick and continuous validations.
| 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 |
There was a problem hiding this comment.
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) | |||
There was a problem hiding this comment.
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.
| endif() | ||
|
|
||
| if(WITH_EP AND USE_CUDA) | ||
| if(WITH_EP AND (USE_CUDA OR USE_HYGON)) |
There was a problem hiding this comment.
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?
|
We have updated the PR accordingly:
|
UNIDY2002
left a comment
There was a problem hiding this comment.
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.
| mkdir -p build | ||
| cd build | ||
| cmake .. -DUSE_HTTP=ON -DCMAKE_BUILD_TYPE=Release | ||
| cmake .. -DUSE_HTTP=ON -DWITH_EP=ON -DCMAKE_BUILD_TYPE=Release |
There was a problem hiding this comment.
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.
|
Thanks for the reminder and suggestions! i have updated the PR:
|
- 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>
074df81 to
0a20844
Compare
|
@alogfans Please take a look when you have time, thanks! |
Description
This PR introduces end-to-end support for the Hygon DCU (DTK/HIP) accelerator platform across Mooncake EP and TransferEngine:
vcc/hipcc wrapper), and DTK version in common.cmake.
Suggested Merge Priority
Module
Type of Change
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:
Checklist
AI Assistance Disclosure
The implementation and adaptation in this PR were generated using Google Antigravity (Advanced Agentic Coding Assistant).