Skip to content

[PG][1/N] Initialize the new collective framework - #3484

Merged
alogfans merged 13 commits into
mainfrom
czh/pg-device-collectives-pr
Sep 30, 2026
Merged

alogfans merged 13 commits into
mainfrom
czh/pg-device-collectives-pr

Conversation

@caozhanhao

@caozhanhao caozhanhao commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Phase 1 of #3483.

This PR introduces an opt-in device collective framework for Mooncake PG and implements GPU Ring AllReduce on that framework.

The legacy GPU path couples collective algorithms to host workers, transfer submission, synchronization, and failure handling. The new framework gives algorithms a narrower contract: execute a rank-local plan through a device-facing transfer interface, while the Coordinator, runtime, and route providers handle group-wide decisions and shared execution rules. #3483 contains the broader design and rollout plan; this PR implements its first vertical slice.

User-visible behavior and backend selection

The new backend is opt-in. For the PyTorch backend, set the following consistently in every worker before creating the GPU communicator:

export MOONCAKE_PG_PREFERRED_GPU_COLLECTIVE_BACKEND=new

An unset value or legacy requests the legacy backend. Any other value is rejected as a configuration error. The C API exposes the same preference through mooncakePgCommConfig_t.preferredGpuCollectiveBackend.

The preference is local input to a group-wide decision, not permission for one rank to switch independently. The Coordinator selects the new backend only when all active ranks request it and advertise the required capability. Conflicting preferences or incomplete capabilities select the legacy backend for the entire group. The selected backend is published in GroupView during bootstrap and recomputed after membership transitions.

MooncakeCommunicator applies the selected backend before group-ready or rank-activation waiters are released. GPU AllReduce then dispatches to DeviceCollectiveRuntime; the existing worker path remains the fallback and continues to serve all other collective operations.

Architecture

flowchart LR
    Communicator -->|"default"| Legacy["Legacy backend"]
    Communicator -->|"opt-in GPU AllReduce"| Runtime["Device collective runtime"]
    Runtime --> Ring["Ring AllReduce"]
    Ring --> Transfer["Device transfer service"]
    Transfer -->|"direct"| P2P["CUDA P2P"]
    Transfer -->|"fallback"| Host["Host Proxy + Transfer Engine"]
Loading

Implementation details

Control plane and dispatch

Rank and communicator registration publish the transfer, workspace, view-epoch, and Ring endpoints required by the new backend. CentralizedCoordinatorStateMachine::resolveGpuCollectiveBackend validates group-wide preference and capability agreement and records one decision in the authoritative GroupView.

The control-plane now:

  1. The Agent installs peer endpoints before applying restored group state, and applies group state before notifying group-ready or rank-activation waiters.
  2. Full group updates and incremental rank-state updates use separate effects, so an unrelated rank-state notification cannot replay a stale GroupView over a newer device plan.
  3. Membership changes preserve endpoints for active members when automatic deactivation is disabled, and link reports are sized by the max world size rather kMaxNumRanks.

Device transfer service

DeviceTransferService gives device code one contract for payload transfer, notification, signal waiting, and completion. Algorithms address peers by GlobalRank and registered-region offset through DeviceTransferHandle, without depending on route-specific host objects.

Each RouteProvider resolves the same endpoint snapshot, and the service selects the first reachable route for each peer. CUDA P2P directly addresses an imported peer mapping; Host Proxy uses mapped command slots and HostTransferProxy to submit work through the Transfer Engine host API. Route selection is independent of backend and algorithm selection and is recomputed from endpoint updates; this PR does not switch routes after an in-flight failure.

Ring AllReduce

RingAllReduceProtocol derives one flat ring from the active members in the committed GroupView. The plan binds the rank's position, neighbors, peer offsets, transfer handle, and protocol state. The kernel keeps a fixed launch shape while selecting the active channel count and tile layout from the current plan and request, then runs a pipelined reduce-scatter followed by all-gather.

Before data movement starts, the startup leader publishes the invocation's view epoch to every required peer and waits for their epochs locally. Readiness and consumption sequences protect reused payload slots and are reset together with each plan update.

Stream ordering and CUDA Graphs

StrongStream gives device collective invocations one logical order while leaving each kernel on the caller's CUDA stream. Event handoffs preserve order across eager calls on different streams. During capture, graph-order streams establish dependencies within a graph, while external event nodes carry the latest collective tail between eager work and graph replays.

Captured kernels retain stable runtime and protocol state addresses, and a graph user object prevents their release while a live graph refers to them. Membership-dependent topology lives in the device plan, allowing a control update to change membership without changing captured kernel arguments or requiring recapture.

Host-to-device control update protocol

A plan cannot be replaced with an asynchronous copy while a previous invocation may still read it. Recovery adds another constraint: its final CTA can remain parked in the failed kernel, so waiting for a separate cudaMemcpyAsync before releasing that CTA may deadlock. ControlUpdate instead carries a complete, idempotent batch that device code applies at a protocol-defined safe point.

ControlUpdateBuilder orders state resets before the plan copy. Device execution fences each operation, so a Ready plan cannot become visible before the protocol state it depends on. The mapped ControlUpdateSlot follows the publication protocol defined by ControlUpdateState:

stateDiagram-v2
    [*] --> Idle
    Idle --> Writing: host begins publication
    Published --> Writing: host replaces an unclaimed update
    Writing --> Published: ordinary GroupView update
    Published --> Claimed: startup leader claims
    Writing --> Pinned: recovery update
    Pinned --> Claimed: parked last CTA claims
    Claimed --> Idle: ordered operations complete
Loading

A published but unclaimed ordinary update can be replaced by a newer complete image, coalescing intermediate GroupView changes. The first CTA that becomes resident is elected startup leader and claims the latest update before any CTA reads protocol state.

Other CTAs remain outside protocol state until startup completes, and StrongStream excludes a concurrent invocation. A recovery update becomes Pinned instead of Published, preventing replacement until the parked final CTA applies that exact update and leaves the failed kernel.

Failure recovery

Device code detects lack of progress through transfer and signal-wait timeouts but delegates membership reconciliation to the existing PG control plane:

  1. The first timeout latches the failed in-group rank. Every channel stops accessing the current plan and protocol buffers before reporting completion.
  2. The final channel CTA observes all channels quiescent, publishes the failure and a new failure_generation through ControlMailbox, and remains in the kernel.
  3. DeviceCollectiveRecoveryWorker drains route work, records the local failure hint, emits an epoch-qualified LinkEvent, and invokes syncAfterFailure when enabled.
  4. After the Agent applies the authoritative GroupView, the runtime publishes a Pinned update containing the protocol reset and replacement plan, then acknowledges the matching ready_generation.
  5. The parked CTA applies that update and exits. The next eager launch or graph replay starts from the replacement plan.

If reconciliation fails, the runtime invalidates the plan before publishing the pinned reset.

Resource ownership and operational impact

The main allocations are process-wide shared, and belong to MooncakePGContext, so creating another subgroup does not duplicate the payload workspace.

Backing allocation Owner and allocation point Default footprint and behavior
Peer-accessible region One per initialized CUDA PG context. It is allocated and registered during MooncakePGContext::initialize and released during context shutdown after all communicators are gone. 40 MiB total: a 32 MiB payload workspace plus an 8 MiB reserve for remotely addressable control and protocol slices.
Staging region One per CUDA PG context. It is allocated and locally registered the first time an active plan selects a route that requires staging (e.g. Host Proxy), then shared by later invocations and communicators. Peers never address or receive this region in endpoint metadata. An additional 32 MiB only when required. A context whose Ring routes only use direct CUDA P2P does not allocate it.

The 40 MiB peer-accessible backing region is sub-allocated as follows:

  • The first 32 MiB is the context-wide DeviceCollectiveWorkspace payload buffer shared by all communicators.
  • The remaining 8 MiB is a fixed reserve for control and protocol state. Each GPU communicator takes 8 * max_group_size bytes for view epochs and 32 * max_group_size * (1 + 2 * 2) * 8 bytes for Ring receive-ready, payload-ready, and payload-consumed signals, for a total of 1,288 * max_group_size bytes. At a capacity of 64, this is 80.5 KiB per communicator. These slices are returned when the communicator's device runtime is destroyed.

The steady bulk CUDA footprint introduced here is therefore 40 MiB per initialized context on direct P2P routes and 72 MiB after Host Proxy staging is needed, plus smaller metadata and control allocations. Context initialization also creates one Host Proxy worker, one recovery worker, the 32 mapped Host Proxy command slots, device route metadata proportional to max_world_size, and the StrongStream ordering stream and event. Each GPU communicator adds ordinary device invocation and Ring state, a mapped host control mailbox, and a CUDA handoff event; these allocations are not remotely registered and are small relative to the bulk regions above.

Supported scope and limitations

Area This PR's behavior
Rollout The legacy backend remains the default. The new backend requires a consistent group-wide opt-in and falls back to legacy when preferences or capabilities do not agree.
Build support Collective v2 is currently compiled only for CUDA. MUSA and MACA builds continue to use the legacy collective runtime.
Operations Only GPU AllReduce uses the new runtime. Other GPU collectives and all CPU collectives remain on their existing paths.
Algorithm One flat Ring AllReduce implementation. Group-wide algorithm selection and size/topology-based policy are follow-up work.
Routes Direct CUDA P2P and Host Proxy through the Transfer Engine. There is no IBGDA or NCCL GIN route and no dynamic route failover in this PR.
CUDA Graphs Eager execution, capture, replay, and reuse after membership updates are supported. Runtime state cannot be destroyed while retained by a live graph.
C API compatibility mooncakePgCommConfig_t appends preferredGpuCollectiveBackend.

See #3483 for the follow-up rollout.

Review guide

The suggested review order follows the control decision into the data path and then into recovery:

Order Area Entry points and review focus
1 Backend decision and dispatch resolveGpuCollectiveBackend, AgentStateMachine::applyGroupView, and MooncakeCommunicator::allReduceGpu: consensus, update ordering, and fallback.
2 Device transfer DeviceTransferService, RouteProvider, and TransferLane: route resolution and the common device contract.
3 Collective protocol DeviceCollectiveRuntime and RingAllReduceProtocol: plan materialization, launch policy, and Ring sequencing.
4 Ordering and recovery StrongStream, ControlUpdateState, prepareCollectiveInvocation, and completeChannel: graph order, update publication, safe points, and recovery handshake.
5 Integration and test behavior C/PyTorch configuration, Transfer Engine device primitives, and test_pg_elastic.py.

Module

  • Transfer Engine (mooncake-transfer-engine)
  • Mooncake Store (mooncake-store)
  • 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?

For both legacy and new implementations:

  • All tests under mooncake-pg/tests passed.
  • E2E tests of scale-up and recovery are also passed.

Benchmark

The existing benchmark exercises Mooncake PG through the PyTorch integration layer. Its measurements therefore include Python/PyTorch dispatch overhead, which can dominate small-message latency and does not accurately isolate collective performance. For a more direct comparison, I used a minimal nccl-tests shim for Mooncake PG that forwards the required NCCL AllReduce API to the Mooncake PG C API. This allows NCCL, the legacy Mooncake PG backend, and the new backend to run under the same nccl-tests harness and configuration.

The sweep compares four execution modes on a single node of 8 x H20:

  • NCCL default: NCCL selects its algorithm, protocol, topology, and channel configuration automatically.
  • NCCL Ring + Simple: NCCL is forced to use the Ring algorithm and Simple protocol through NCCL_ALGO=Ring and NCCL_PROTO=Simple. This provides a closer algorithmic baseline, although NCCL still chooses its own topology and channel configuration.
  • Mooncake PG legacy: the shim forwards AllReduce to the existing host-worker-based GPU collective implementation.
  • Mooncake PG new: the shim forwards AllReduce to the device collective runtime and the GPU Ring AllReduce implementation introduced by this PR.

All four modes use the same nccl-tests message-size sweep, datatype, reduction operation, warmup count, and measured iteration count.

inplace_busbw
Raw Results
===== NCCL default =====
# nccl-tests version 2.19.7 nccl-headers=23004 nccl-library=23004
# Collective test starting: all_reduce_perf
# nThread 1 nGpus 1 minBytes 64 maxBytes 1073741824 step: 2(factor) warmup iters: 10 iters: 100 agg iters: 1 validation: 1 graph: 0 unalign: 0
#
# Using devices
#  Rank  0 Group  0 Pid 671707 on     qjh001 device  0 [0000:65:02] NVIDIA H20
#  Rank  1 Group  0 Pid 671708 on     qjh001 device  1 [0000:65:03] NVIDIA H20
#  Rank  2 Group  0 Pid 671709 on     qjh001 device  2 [0000:67:02] NVIDIA H20
#  Rank  3 Group  0 Pid 671710 on     qjh001 device  3 [0000:67:03] NVIDIA H20
#  Rank  4 Group  0 Pid 671713 on     qjh001 device  4 [0000:69:02] NVIDIA H20
#  Rank  5 Group  0 Pid 671715 on     qjh001 device  5 [0000:69:03] NVIDIA H20
#  Rank  6 Group  0 Pid 671718 on     qjh001 device  6 [0000:6b:02] NVIDIA H20
#  Rank  7 Group  0 Pid 671721 on     qjh001 device  7 [0000:6b:03] NVIDIA H20
#
#                                                              out-of-place                       in-place          
#       size         count      type   redop    root     time   algbw   busbw  #wrong     time   algbw   busbw  #wrong 
#        (B)    (elements)                               (us)  (GB/s)  (GB/s)             (us)  (GB/s)  (GB/s)         
          64            16     float     sum      -1    14.53    0.00    0.01       0    14.45    0.00    0.01       0
         128            32     float     sum      -1    15.15    0.01    0.01       0    14.96    0.01    0.01       0
         256            64     float     sum      -1    15.44    0.02    0.03       0    15.38    0.02    0.03       0
         512           128     float     sum      -1    15.98    0.03    0.06       0    15.25    0.03    0.06       0
        1024           256     float     sum      -1    16.13    0.06    0.11       0    15.38    0.07    0.12       0
        2048           512     float     sum      -1    16.28    0.13    0.22       0    15.58    0.13    0.23       0
        4096          1024     float     sum      -1    16.44    0.25    0.44       0    15.75    0.26    0.46       0
        8192          2048     float     sum      -1    16.61    0.49    0.86       0    15.95    0.51    0.90       0
       16384          4096     float     sum      -1    18.04    0.91    1.59       0    16.57    0.99    1.73       0
       32768          8192     float     sum      -1    18.66    1.76    3.07       0    17.95    1.83    3.20       0
       65536         16384     float     sum      -1    18.95    3.46    6.05       0    18.25    3.59    6.28       0
      131072         32768     float     sum      -1    19.25    6.81   11.91       0    18.43    7.11   12.44       0
      262144         65536     float     sum      -1    19.54   13.42   23.48       0    19.27   13.61   23.81       0
      524288        131072     float     sum      -1    20.39   25.71   45.00       0    20.48   25.61   44.81       0
     1048576        262144     float     sum      -1    27.76   37.78   66.11       0    27.49   38.15   66.76       0
     2097152        524288     float     sum      -1    40.66   51.58   90.27       0    40.36   51.97   90.94       0
     4194304       1048576     float     sum      -1    53.24   78.78  137.87       0    52.85   79.36  138.88       0
     8388608       2097152     float     sum      -1    81.16  103.36  180.88       0    80.46  104.26  182.45       0
    16777216       4194304     float     sum      -1   121.33  138.28  242.00       0   120.47  139.26  243.71       0
    33554432       8388608     float     sum      -1   195.40  171.72  300.51       0   195.40  171.73  300.52       0
    67108864      16777216     float     sum      -1   315.64  212.61  372.07       0   316.86  211.79  370.64       0
   134217728      33554432     float     sum      -1   562.84  238.47  417.32       0   563.34  238.26  416.95       0
   268435456      67108864     float     sum      -1  1066.50  251.70  440.47       0  1066.70  251.65  440.39       0
   536870912     134217728     float     sum      -1  2081.77  257.89  451.31       0  2084.10  257.60  450.81       0
  1073741824     268435456     float     sum      -1  4009.38  267.81  468.66       0  4009.59  267.79  468.64       0
# Out of bounds values : 0 OK
# Avg bus bandwidth    : 130.501 
#
# Collective test concluded: all_reduce_perf
#


===== NCCL Ring + Simple =====
# nccl-tests version 2.19.7 nccl-headers=23004 nccl-library=23004
# Collective test starting: all_reduce_perf
# nThread 1 nGpus 1 minBytes 64 maxBytes 1073741824 step: 2(factor) warmup iters: 10 iters: 100 agg iters: 1 validation: 1 graph: 0 unalign: 0
#
# Using devices
#  Rank  0 Group  0 Pid 672289 on     qjh001 device  0 [0000:65:02] NVIDIA H20
#  Rank  1 Group  0 Pid 672290 on     qjh001 device  1 [0000:65:03] NVIDIA H20
#  Rank  2 Group  0 Pid 672291 on     qjh001 device  2 [0000:67:02] NVIDIA H20
#  Rank  3 Group  0 Pid 672292 on     qjh001 device  3 [0000:67:03] NVIDIA H20
#  Rank  4 Group  0 Pid 672294 on     qjh001 device  4 [0000:69:02] NVIDIA H20
#  Rank  5 Group  0 Pid 672296 on     qjh001 device  5 [0000:69:03] NVIDIA H20
#  Rank  6 Group  0 Pid 672298 on     qjh001 device  6 [0000:6b:02] NVIDIA H20
#  Rank  7 Group  0 Pid 672302 on     qjh001 device  7 [0000:6b:03] NVIDIA H20
#
#                                                              out-of-place                       in-place          
#       size         count      type   redop    root     time   algbw   busbw  #wrong     time   algbw   busbw  #wrong 
#        (B)    (elements)                               (us)  (GB/s)  (GB/s)             (us)  (GB/s)  (GB/s)         
          64            16     float     sum      -1    47.19    0.00    0.00       0    46.53    0.00    0.00       0
         128            32     float     sum      -1    49.22    0.00    0.00       0    48.98    0.00    0.00       0
         256            64     float     sum      -1    49.65    0.01    0.01       0    48.96    0.01    0.01       0
         512           128     float     sum      -1    49.82    0.01    0.02       0    49.09    0.01    0.02       0
        1024           256     float     sum      -1    50.00    0.02    0.04       0    49.31    0.02    0.04       0
        2048           512     float     sum      -1    50.05    0.04    0.07       0    49.36    0.04    0.07       0
        4096          1024     float     sum      -1    50.29    0.08    0.14       0    49.57    0.08    0.14       0
        8192          2048     float     sum      -1    50.84    0.16    0.28       0    49.87    0.16    0.29       0
       16384          4096     float     sum      -1    52.73    0.31    0.54       0    51.61    0.32    0.56       0
       32768          8192     float     sum      -1    58.93    0.56    0.97       0    57.83    0.57    0.99       0
       65536         16384     float     sum      -1    61.96    1.06    1.85       0    60.94    1.08    1.88       0
      131072         32768     float     sum      -1    64.19    2.04    3.57       0    62.91    2.08    3.65       0
      262144         65536     float     sum      -1    65.19    4.02    7.04       0    65.33    4.01    7.02       0
      524288        131072     float     sum      -1    67.59    7.76   13.57       0    67.54    7.76   13.59       0
     1048576        262144     float     sum      -1    71.34   14.70   25.72       0    70.81   14.81   25.91       0
     2097152        524288     float     sum      -1    71.00   29.54   51.69       0    70.74   29.65   51.88       0
     4194304       1048576     float     sum      -1    82.25   50.99   89.24       0    82.09   51.09   89.42       0
     8388608       2097152     float     sum      -1   106.28   78.93  138.13       0   105.77   79.31  138.79       0
    16777216       4194304     float     sum      -1   132.17  126.94  222.14       0   130.12  128.93  225.63       0
    33554432       8388608     float     sum      -1   196.41  170.84  298.97       0   195.42  171.70  300.48       0
    67108864      16777216     float     sum      -1   362.06  185.36  324.37       0   361.69  185.54  324.70       0
   134217728      33554432     float     sum      -1   700.25  191.67  335.43       0   701.01  191.46  335.06       0
   268435456      67108864     float     sum      -1  1366.17  196.49  343.85       0  1367.43  196.31  343.54       0
   536870912     134217728     float     sum      -1  2671.60  200.96  351.67       0  2670.98  201.00  351.75       0
  1073741824     268435456     float     sum      -1  5252.64  204.42  357.73       0  5234.83  205.12  358.95       0
# Out of bounds values : 0 OK
# Avg bus bandwidth    : 102.829 
#
# Collective test concluded: all_reduce_perf
#


===== Mooncake PG legacy =====
# nccl-tests version 2.19.7 nccl-headers=23004 nccl-library=23004
# Collective test starting: all_reduce_perf
# nThread 1 nGpus 1 minBytes 64 maxBytes 1073741824 step: 2(factor) warmup iters: 10 iters: 100 agg iters: 1 validation: 1 graph: 0 unalign: 0
#
# Using devices
#  Rank  0 Group  0 Pid 672730 on     qjh001 device  0 [0000:65:02] NVIDIA H20
#  Rank  1 Group  0 Pid 672731 on     qjh001 device  1 [0000:65:03] NVIDIA H20
#  Rank  2 Group  0 Pid 672732 on     qjh001 device  2 [0000:67:02] NVIDIA H20
#  Rank  3 Group  0 Pid 672737 on     qjh001 device  3 [0000:67:03] NVIDIA H20
#  Rank  4 Group  0 Pid 672738 on     qjh001 device  4 [0000:69:02] NVIDIA H20
#  Rank  5 Group  0 Pid 672739 on     qjh001 device  5 [0000:69:03] NVIDIA H20
#  Rank  6 Group  0 Pid 672740 on     qjh001 device  6 [0000:6b:02] NVIDIA H20
#  Rank  7 Group  0 Pid 672741 on     qjh001 device  7 [0000:6b:03] NVIDIA H20
#
#                                                              out-of-place                       in-place          
#       size         count      type   redop    root     time   algbw   busbw  #wrong     time   algbw   busbw  #wrong 
#        (B)    (elements)                               (us)  (GB/s)  (GB/s)             (us)  (GB/s)  (GB/s)         
          64            16     float     sum      -1    82.17    0.00    0.00       0    87.47    0.00    0.00       0
         128            32     float     sum      -1    86.88    0.00    0.00       0    81.24    0.00    0.00       0
         256            64     float     sum      -1    81.55    0.00    0.01       0    91.93    0.00    0.00       0
         512           128     float     sum      -1    91.43    0.01    0.01       0    87.57    0.01    0.01       0
        1024           256     float     sum      -1    84.51    0.01    0.02       0    84.76    0.01    0.02       0
        2048           512     float     sum      -1    84.59    0.02    0.04       0    84.81    0.02    0.04       0
        4096          1024     float     sum      -1    84.84    0.05    0.08       0    84.74    0.05    0.08       0
        8192          2048     float     sum      -1    86.05    0.10    0.17       0    85.92    0.10    0.17       0
       16384          4096     float     sum      -1    86.99    0.19    0.33       0    85.81    0.19    0.33       0
       32768          8192     float     sum      -1    86.74    0.38    0.66       0    86.13    0.38    0.67       0
       65536         16384     float     sum      -1    92.48    0.71    1.24       0    91.91    0.71    1.25       0
      131072         32768     float     sum      -1   117.87    1.11    1.95       0   117.55    1.11    1.95       0
      262144         65536     float     sum      -1   177.32    1.48    2.59       0   178.53    1.47    2.57       0
      524288        131072     float     sum      -1   292.22    1.79    3.14       0   291.54    1.80    3.15       0
     1048576        262144     float     sum      -1   537.58    1.95    3.41       0   537.77    1.95    3.41       0
     2097152        524288     float     sum      -1  1162.22    1.80    3.16       0  1160.61    1.81    3.16       0
     4194304       1048576     float     sum      -1  2251.22    1.86    3.26       0  2252.91    1.86    3.26       0
     8388608       2097152     float     sum      -1  4468.90    1.88    3.28       0  4414.78    1.90    3.33       0
    16777216       4194304     float     sum      -1  8810.88    1.90    3.33       0  8795.63    1.91    3.34       0
    33554432       8388608     float     sum      -1  17551.1    1.91    3.35       0  17537.4    1.91    3.35       0
    67108864      16777216     float     sum      -1  35143.9    1.91    3.34       0  34948.6    1.92    3.36       0
   134217728      33554432     float     sum      -1  70131.7    1.91    3.35       0  69830.4    1.92    3.36       0
   268435456      67108864     float     sum      -1   140126    1.92    3.35       0   140054    1.92    3.35       0
   536870912     134217728     float     sum      -1   280687    1.91    3.35       0   277690    1.93    3.38       0
  1073741824     268435456     float     sum      -1   558365    1.92    3.37       0   556389    1.93    3.38       0
# Out of bounds values : 0 OK
# Avg bus bandwidth    : 1.87441 
#
# Collective test concluded: all_reduce_perf
#


===== Mooncake PG new =====
# nccl-tests version 2.19.7 nccl-headers=23004 nccl-library=23004
# Collective test starting: all_reduce_perf
# nThread 1 nGpus 1 minBytes 64 maxBytes 1073741824 step: 2(factor) warmup iters: 10 iters: 100 agg iters: 1 validation: 1 graph: 0 unalign: 0
#
# Using devices
#  Rank  0 Group  0 Pid 684914 on     qjh001 device  0 [0000:65:02] NVIDIA H20
#  Rank  1 Group  0 Pid 684915 on     qjh001 device  1 [0000:65:03] NVIDIA H20
#  Rank  2 Group  0 Pid 684916 on     qjh001 device  2 [0000:67:02] NVIDIA H20
#  Rank  3 Group  0 Pid 684917 on     qjh001 device  3 [0000:67:03] NVIDIA H20
#  Rank  4 Group  0 Pid 684918 on     qjh001 device  4 [0000:69:02] NVIDIA H20
#  Rank  5 Group  0 Pid 684919 on     qjh001 device  5 [0000:69:03] NVIDIA H20
#  Rank  6 Group  0 Pid 684920 on     qjh001 device  6 [0000:6b:02] NVIDIA H20
#  Rank  7 Group  0 Pid 684922 on     qjh001 device  7 [0000:6b:03] NVIDIA H20
#
#                                                              out-of-place                       in-place          
#       size         count      type   redop    root     time   algbw   busbw  #wrong     time   algbw   busbw  #wrong 
#        (B)    (elements)                               (us)  (GB/s)  (GB/s)             (us)  (GB/s)  (GB/s)         
          64            16     float     sum      -1    98.42    0.00    0.00       0    98.35    0.00    0.00       0
         128            32     float     sum      -1    98.54    0.00    0.00       0    98.47    0.00    0.00       0
         256            64     float     sum      -1    98.70    0.00    0.00       0    98.53    0.00    0.00       0
         512           128     float     sum      -1    98.98    0.01    0.01       0    98.45    0.01    0.01       0
        1024           256     float     sum      -1    98.90    0.01    0.02       0    98.49    0.01    0.02       0
        2048           512     float     sum      -1    99.00    0.02    0.04       0    98.63    0.02    0.04       0
        4096          1024     float     sum      -1    99.14    0.04    0.07       0    98.72    0.04    0.07       0
        8192          2048     float     sum      -1    99.09    0.08    0.14       0    98.70    0.08    0.15       0
       16384          4096     float     sum      -1    99.26    0.17    0.29       0    98.85    0.17    0.29       0
       32768          8192     float     sum      -1    99.56    0.33    0.58       0    99.20    0.33    0.58       0
       65536         16384     float     sum      -1   102.90    0.64    1.11       0   102.45    0.64    1.12       0
      131072         32768     float     sum      -1   110.89    1.18    2.07       0   109.63    1.20    2.09       0
      262144         65536     float     sum      -1   117.92    2.22    3.89       0   117.58    2.23    3.90       0
      524288        131072     float     sum      -1   122.99    4.26    7.46       0   123.06    4.26    7.46       0
     1048576        262144     float     sum      -1   126.45    8.29   14.51       0   126.17    8.31   14.54       0
     2097152        524288     float     sum      -1   129.90   16.14   28.25       0   129.80   16.16   28.28       0
     4194304       1048576     float     sum      -1   135.38   30.98   54.22       0   135.81   30.88   54.04       0
     8388608       2097152     float     sum      -1   149.42   56.14   98.24       0   149.23   56.21   98.37       0
    16777216       4194304     float     sum      -1   192.15   87.31  152.80       0   191.50   87.61  153.32       0
    33554432       8388608     float     sum      -1   271.80  123.45  216.04       0   271.73  123.48  216.10       0
    67108864      16777216     float     sum      -1   417.06  160.91  281.59       0   419.44  160.00  279.99       0
   134217728      33554432     float     sum      -1   748.95  179.21  313.61       0   753.67  178.08  311.65       0
   268435456      67108864     float     sum      -1  1438.68  186.58  326.52       0  1444.13  185.88  325.29       0
   536870912     134217728     float     sum      -1  2804.46  191.43  335.01       0  2802.25  191.59  335.27       0
  1073741824     268435456     float     sum      -1  5529.33  194.19  339.83       0  5523.07  194.41  340.22       0
# Out of bounds values : 0 OK
# Avg bus bandwidth    : 86.9825 
#
# Collective test concluded: all_reduce_perf
#

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)

Codex was used to assist in designing and implementing this PR. All code and architectural changes have been thoroughly reviewed and verified by me in person.

@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.

This is a wonderful start as the new collective framework! Thanks for your contribution.

I have several questions and concerns. You can resolve them in the future.

Comment on lines +252 to 263
// Apply an authoritative group view together with the current rank-state
// snapshot as one communicator update.
void applyGroupState(const GroupView& view,
const std::vector<RankState>& rank_states,
const std::vector<uint64_t>& rank_epochs,
const std::vector<bool>& activatable);
// Apply one rank-state change without reapplying the GroupView or
// propagating to the selected collective backend.
void applyRankStateUpdate(GlobalRank rank, InGroupRank in_group_rank,
RankState state, uint64_t rank_epoch,
bool activatable);
// Called by AgentHost when a TE link to a peer comes back up.

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.

What's the purpose of GroupView and RankState? I am quite confused with the relationship between them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A global rank can belong to multiple groups at the same time. RankState represents state shared by those groups, such as the rank's health. The coordinator maintains this state per global rank so that groups share a common health assessment and do not make independent, potentially conflicting decisions about the same process's health.

GroupView describes how a group is composed from global ranks. It provides a group-specific view of those ranks: whether each member is active, its in-group rank number, and the buffer addresses/offsets used for communication. The same global rank can be active in one group and inactive in another, with different in-group rank numbers and communication resources.

The two functions here synchronize communicator state with the Agent. applyGroupState() performs a full communicator update, applying the GroupView together with the Agent's current rank-state snapshot and rebuilding the collective plan as needed. applyRankStateUpdate() propagates incremental rank-state changes without modifying the group configuration or collective plan.

Comment on lines +18 to +23
enum class DeviceRouteKind : uint32_t {
Unreachable = 0,
P2p = 1,
HostProxy = 2,
};

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.

Consider renaming it to DeviceRouteType. Type is more common in technical taxonomies than Kind

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done.

// Owns the host-side decisions specific to Ring AllReduce. The common runtime
// supplies view-epoch signal storage, ordering, and recovery lifecycle; the
// Ring Plan supplies the exact peers that preparation must check.
class RingAllReduceProtocol {

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.

Name a collective algorithm with XXXProtocol is confusing. We may use Simple/LL128 protocol in the future. Consider naming it with XXXAlgorithm or others.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for catching this. I've renamed it to RingAllReduceAlgorithm and moved the implementation from protocols/ring to algorithms/ring. I'll address the decoupling between the algorithm and protocol in follow-up PRs.

Comment on lines +17 to +20
__device__ __forceinline__ bool transferTimedOut(uint64_t start,
uint64_t timeout_ticks) {
return timeout_ticks != 0 && clock64() - start >= timeout_ticks;
}

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.

transferTimedOut (transfer_lane.cuh:17) and hostProxyTimedOut (host_proxy_route.cuh:64) have identical bodies. Could you resolve this duplicate?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. Extracted the common logic into deviceTimedOut().

Comment on lines +26 to +48
// One mapped SPSC command slot belongs to each device lane:
//
// GPU producer Host proxy consumer
// ------------ -------------------
// acquire completed_sequence == N - 1
// write command
// system fence
// release submitted_sequence = N --> acquire submitted_sequence == N
// snapshot command
// execute payload, then signal action
// write result
// acquire completed_sequence = N <-- release completed_sequence = N
// read result
//
// The service contract permits only one producer per lane at a time.
struct HostProxyCommandSlot {
uint64_t submitted_sequence = 0;
uint64_t completed_sequence = 0;

HostProxyCommandResult result = HostProxyCommandResult::Succeeded;

HostProxyCommand command;
};

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.

HostProxyCommandSlot implements an SPSC serving as communication buffer for Host and Device. But ControlMailbox serves as the same role and implementation is quite abundant. could you propose an abstraction for them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. Added D2HRequestSlot<Request, Reply> for both host-proxy commands and the failure-recovery requests in ControlMailbox.

@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. Thanks for your principle contribution!

@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.

@alogfans Please take a look

@caozhanhao
caozhanhao force-pushed the czh/pg-device-collectives-pr branch from d4a5ea4 to ff87188 Compare September 28, 2026 15:26
@caozhanhao

caozhanhao commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hi, I've rebased this PR onto the latest main (no functional changes). It looks like GitHub's stacked PR requires a linear history before a PR be merged (GitHub docs).

@alogfans alogfans 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.

LGTM

@alogfans
alogfans merged commit ef2b8eb into main Sep 30, 2026
30 checks passed
@zhyncs
zhyncs deleted the czh/pg-device-collectives-pr branch October 6, 2026 19:00
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.

[RFC]: A Device-API-based collective framework for Mooncake PG

4 participants