Skip to content

[EP] Enable MACA legacy EP with shared P2P and IBGDA device paths - #4091

Merged
stmatengss merged 38 commits into
mainfrom
feature/maca-ep-functional-clean
Oct 10, 2026
Merged

stmatengss merged 38 commits into
mainfrom
feature/maca-ep-functional-clean

Conversation

@UNIDY2002

@UNIDY2002 UNIDY2002 commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Enable Mooncake's legacy low-latency Expert Parallelism (EP) Buffer API on MetaX MACA devices by reusing the existing CUDA/MUSA EP and mlx5 IBGDA paths. The public legacy EP API remains unchanged: users construct Buffer, then call dispatch and combine with BF16 or FP8 payloads.

Motivation

MACA deployments need both intra-node P2P EP and GPU-initiated RDMA EP. The shared Mooncake transport already contains the required QP lifecycle, WQE, doorbell, signal, remote atomic, and CQ logic. This change supplies the MACA compiler/runtime integration and device-ordering adaptations needed on C500 hardware, without introducing a second EP implementation or an MXSHMEM-specific kernel.

Implementation

MACA build and runtime integration

  • Compile the legacy EP device kernel with the MACA SDK cu-bridge nvcc.
  • Link the EP extension and PG device worker against the MACA runtime.
  • Exclude the elastic EP kernel from the MACA target because it contains NVIDIA-specific PTX and is outside the legacy Buffer API.
  • Add the CUDA-runtime compatibility aliases required by the shared host code.

Shared IBGDA path

  • Reuse the common mlx5 QP/WQE/doorbell/CQ implementation used by CUDA and MUSA.
  • Use MACA system-scope fences and atomics for release publication and QP mutex ownership.
  • Publish GPU-produced payload data before posting the corresponding IBGDA WQE, which is required for NIC visibility of MACA fine-grained memory.
  • Serialize the two MACA sub-warp leaders that can contend for one QP channel during legacy combine posting.
  • Keep the shared QP table at 256 entries and derive all-to-all metadata shape from the runtime local-QP vector.

Legacy EP protocol

  • Remove the native phase-ACK kernels and API. The Python phase fence remains the synchronization boundary for MACA split SEND/RECV launches.
  • Preserve MACA split SEND/RECV behavior and avoid passing the unsupported native async_finish && return_recv_hook combination.
  • Zero-initialize packed receive counters before dispatch.
  • Enable MACA FP8 conversion through the SDK's __maca_fp8_e4m3 type.
  • Remove zero-copy arms from the correctness matrix because zero-copy is not a supported path for this feature.

Scope

This PR targets the legacy EP Buffer API. The newer elastic kernel is not compiled for MACA in this change. Performance tuning beyond the validated functional path, including QP sharding and active-QP auto-tuning, remains a follow-up.

Module

  • Mooncake EP (mooncake-ep)
  • Mooncake PG (mooncake-pg)
  • Transfer Engine (mooncake-transfer-engine)
  • Python Wheel (mooncake-wheel)

Type of Change

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

How Has This Been Tested?

Validation focused on MACA C500 devices and the actual legacy EP communication paths. The tests use the standard workload shape where noted (tokens=128, hidden=7168, experts=288, top-k=8) and exclude zero-copy.

Test commands:

# Official legacy EP correctness test, P2P path
PYTHONPATH=$ROOT/python python3 -u python/tests/ep/test_mooncake_ep.py

# Official legacy EP correctness test, pure IBGDA path
# The test harness passes disable_p2p=True and selects the allocated HCAs.
PYTHONPATH=$ROOT/python python3 -u python/tests/ep/test_mooncake_ep.py

# Native eight-rank MACA EP correctness/performance workload
PYTHONPATH=$ROOT/python python3 -u mooncake-ep/benchmarks/legacy_buffer_perf.py

Test results:

  • Manual testing done: two-rank MACA P2P correctness passes for BF16 and FP8 dispatch/combine, including hook and non-hook paths.
  • Manual testing done: two-rank pure-IBGDA correctness passes for BF16 and FP8 with fine-grained payload allocation, explicit HCA selection, split SEND/RECV, and the Python phase fence. Native phase ACK is disabled.
  • Manual testing done: eight-rank fixed-routing MACA correctness passes on the reduced formal smoke workload (tokens=8, hidden=7168, experts=8, top-k=1) with zero maximum error. A matched native run reports approximately 667--760 us dispatch+combine latency.
  • Manual testing done: the formal eight-rank pure-IBGDA workload (tokens=128, hidden=7168, experts=288, top-k=8, P2P disabled) passes dispatch and combine correctness on all ranks with max_abs_error=0. The native loop reports approximately 2.09--2.11 GB/s dispatch+combine effective bandwidth and 13.9--14.0 ms average latency. NCCL/MCCL is used for device metadata and a separate Gloo control group supplies the MACA phase fence.
  • Manual testing done: the formal two-rank workload also completes pure IBGDA dispatch/combine correctness for BF16 and FP8. This is a functional bootstrap check; the performance data below is from the eight-rank workload.
  • Manual testing done: the MACA allocator requirement and HCA selection were validated independently. Fine-grained payload memory is required for GPU-produced IBGDA data; invalid HCA selection fails at IBGDA initialization rather than silently falling back to P2P.

For context, the prebuilt MXDeepEP low-latency benchmark on the same MACA family reports approximately 12.3 GB/s per-rank effective dispatch+combine bandwidth for the formal eight-rank workload. From the human author's perspective (@UNIDY2002), Mooncake's 2 GB/s per-rank result is already close to saturating the two 100-Gbps data-plane ports: 2 GB/s * 8 ranks = 16 GB/s, versus 2 * 100 Gbps / 8 = 25 GB/s of raw link bandwidth. The same calculation applied to the MXDeepEP number gives 12.3 GB/s * 8 ranks = 98.4 GB/s, which appears to exceed that RDMA limit.

Codex's interpretation is that this comparison is too high because the printed figures are per-rank effective all-to-all rates and can count overlapping or duplicated traffic; they are not aggregate wire-rate measurements. The MXDeepEP result is therefore retained as a useful baseline, while the apparent 98.4-GB/s aggregate should not be read as physical link utilization. Mooncake's current native MACA result is a functional baseline; QP/CQ scheduling and communication overlap are follow-up performance targets.

Compatibility and Operational Notes

  • MACA IBGDA payloads must use fine-grained allocation. Set MOONCAKE_EP_MACA_ALLOC=fine for the pure-IBGDA route; the default allocator remains unchanged for ordinary P2P users.
  • Set MOONCAKE_EP_DEVICE_FILTER to the actual InfiniBand device names for the allocated node (for example, mlx5_10,mlx5_11). Do not use a network bond name or the plural MOONCAKE_EP_DEVICE_FILTERS; verify the selected HCA in the [EP IBGDA] Initialized on ... log before interpreting results.

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

The task-local validation harness, temporary recovery-test bypass, and raw hardware logs are maintained outside the upstream source tree.

AI Assistance Disclosure

  • No AI tools were used
  • AI tools were used (Codex assisted with source analysis, implementation, hardware validation, and PR preparation.)

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.

🟡 Changes recommended

Unresolved critical MACA ordering and async-completion issues, along with moderate build and runtime concerns, block approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds MACA/C500 support for the legacy Mooncake EP Buffer API using shared P2P and IBGDA transport paths.

Changes:

  • Adds MACA build/runtime, allocation, synchronization, and FP8 support.
  • Adapts legacy split SEND/RECV and IBGDA QP handling.
  • Removes native phase ACK and unsupported zero-copy paths.
File summaries
File Reviewed changes and final comments
python/tests/ep/test_mooncake_ep.py Updates legacy EP tests and removes unsupported zero-copy cases.
python/tests/ep/test_ep_grid.py Updates the EP test grid and removes zero-copy cases.
python/mooncake/mooncake_ep_buffer.py Adds MACA dispatch/combine handling. critical (1 vote): async completion may signal before the internally triggered RECV finishes. moderate (1 vote): the phase fence can hang on inactive peers. nit (1 vote): MACA FP8 remains untested by the matrices.
mooncake-transfer-engine/src/transport/device/p2p_device_transport.cpp Documents MACA fine-grained allocation requirements.
mooncake-transfer-engine/include/transport/device/maca/maca_ops.cuh Adds MACA memory-ordering helpers.
mooncake-transfer-engine/include/transport/device/ibgda_device.cuh Adds MACA QP locking behavior.
mooncake-transfer-engine/include/gpu_vendor/maca.h Adds CUDA-runtime compatibility aliases.
mooncake-pg/src/CMakeLists.txt Integrates MACA PG device compilation.
mooncake-ep/src/mooncake_ep_kernel.cu Adds MACA IBGDA synchronization and serialization. critical (2 votes): add a system-scope fence before posting combine WQEs. critical (2 votes): guard the added fence from CUDA/MUSA hot paths.
mooncake-ep/src/mooncake_ep_buffer.cpp Removes native phase-ACK orchestration.
mooncake-ep/src/ep_py.cpp Excludes Elastic EP bindings on MACA. moderate (1 vote): make the unavailable Python ElasticBuffer API fail explicitly.
mooncake-ep/src/CMakeLists.txt Builds and links the MACA legacy kernel. moderate (1 vote): add header dependencies or a depfile to prevent stale incremental MACA kernels.
mooncake-ep/include/mooncake_ep_device.h Adds MACA FP8 storage and conversion. nit (2 votes): add automated MACA FP8 coverage.
mooncake-ep/include/mooncake_ep_configs.cuh Removes MACA phase-ACK configuration.
mooncake-ep/include/mooncake_ep_buffer.h Removes phase epoch state.
mooncake-ep/include/mooncake_ep_api.cuh Removes phase-ACK declarations.
Review details

Suppressed comments (7)

mooncake-ep/src/CMakeLists.txt:131

  • This custom command depends only on the .cu source, so CMake will not rebuild _maca.o when an included EP/transport header changes (for example mooncake_ep_device.h or maca_ops.cuh). Incremental builds can therefore silently keep a stale MACA kernel; generate and attach a compiler depfile (as the MUSA path does) or list the transitive headers.
      DEPENDS "${_ep_device_source}"

mooncake-ep/src/ep_py.cpp:61

  • Excluding the native class here leaves the high-level mooncake.mooncake_elastic_buffer.ElasticBuffer constructible, but its constructor still unconditionally calls ep.ElasticBuffer (python/mooncake/mooncake_elastic_buffer.py:418-453). On a MACA wheel this now fails with an attribute error rather than an explicit unsupported-feature error. Add a MACA capability check/clear exception in the Python wrapper or otherwise make this API's unavailability explicit.
#if !defined(MOONCAKE_EP_USE_MACA)
    py::class_<MooncakeElasticBuffer>(m, "ElasticBuffer")

mooncake-ep/src/mooncake_ep_kernel.cu:200

  • This does not actually serialize the MACA pseudo-warps: kNumWarpsPerGroup is 4, so sub-warps 0 and 2 both satisfy (sub_warp_id & 1) == 0 and can enter mc_rdma_put concurrently on the same QP channel. That defeats the ordering this MACA workaround is intended to provide; iterate over each sub_warp_id (or otherwise admit one leader at a time) instead of grouping by parity.
                    for (int half = 0; half < 2; ++half) {
                        if ((sub_warp_id & 1) == half) {

mooncake-ep/src/mooncake_ep_kernel.cu:577

  • The same parity condition leaves two of the four combine pseudo-warps able to post to the same QP at once: sub-warps 0 and 2 run together in the first iteration, and 1 and 3 in the second. The comment says these leaders are being serialized, so this should admit one sub_warp_id per iteration (or use another mechanism that guarantees one WQE/doorbell update at a time).
                for (int half = 0; half < 2; ++half) {
                    if ((sub_warp_id & 1) == half) {

python/mooncake/mooncake_ep_buffer.py:653

  • The same event-ordering issue applies to combine: MACA forces runtime_return_recv_hook, so the native event is recorded before the wrapper's phase-fence/RECV hook runs. A caller using async_finish=True and waiting only on the returned event can observe combined_x before the combine receive/reduction has completed. Return an event recorded after the internally-triggered receive phase, or otherwise tie the event to that phase.
            native_async_finish = async_finish and not (
                _USE_SPLIT_SEND_RECV and runtime_return_recv_hook
            )

python/mooncake/mooncake_ep_buffer.py:499

  • This internally-forced receive hook always wraps the MACA phase fence, but the fence has no active_ranks membership and sends/receives with every peer. The legacy EP tests still exercise failed-rank cases; if a peer has exited or is inactive, dispatch waits on that peer before the receive kernel can run, so timeout/fault-tolerant execution can hang. Thread the active-rank mask through the hook/fence and skip inactive peers, or use a failure-aware control-plane fence.
            # The MACA split path requests the native receive hook even when
            # the caller did not.  Native EP forbids async+hook together;
            # the wrapper owns completion through the phase-fence hook.
            native_async_finish = async_finish and not (
                _USE_SPLIT_SEND_RECV and runtime_return_recv_hook
            )

python/mooncake/mooncake_ep_buffer.py:410

  • Removing the MACA FP8 rejection exposes a new supported path, but the official correctness matrices still force MACA to BF16-only (dispatch_use_fp8/fp8_options remain [False]). The new __maca_fp8_e4m3 conversion is therefore not exercised by the automated EP tests; enable MACA FP8 in the matrices or add a MACA-specific FP8 case before treating this support as covered.

        if use_fp8 is None:
            use_fp8 = not _USE_MACA

        # MUSA and MACA use split SEND/RECV launches because they do not expose
        # CUDA cooperative-grid synchronization. Only MACA adds a phase fence.
  • Files reviewed: 16/16 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Resolved
Comment thread mooncake-ep/src/mooncake_ep_kernel.cu Resolved
Comment thread python/mooncake/mooncake_ep_buffer.py Resolved
@UNIDY2002
UNIDY2002 force-pushed the feature/maca-ep-functional-clean branch from 47b4e13 to d7cdeb4 Compare September 14, 2026 12:18
@UNIDY2002
UNIDY2002 added this pull request to stack #4126 September 15, 2026 03:11
@UNIDY2002
UNIDY2002 force-pushed the feature/maca-ep-functional-clean branch from bd983aa to 1a20e01 Compare September 15, 2026 04:22

@yuechen-sys yuechen-sys left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@stmatengss
stmatengss merged commit 8e231d5 into main Oct 10, 2026
28 checks passed
@UNIDY2002
UNIDY2002 deleted the feature/maca-ep-functional-clean branch October 10, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants