Skip to content

Add symmetric-memory and NCCL-RMA P2P comm kernels - #712

Merged
AkshitaB merged 8 commits into
akshitab/moe-v2-corefrom
akshitab/moe-symm-mem
Jun 9, 2026
Merged

AkshitaB merged 8 commits into
akshitab/moe-v2-corefrom
akshitab/moe-symm-mem

Conversation

@AkshitaB

@AkshitaB AkshitaB commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

What this adds

Symmetric-memory and NCCL-RMA point-to-point communication kernels used for expert-parallel all-to-all and RMA-based transport:

  • kernels/symm_mem_vdev2d.py + kernels/cuda/symm_mem_vdev2d{.cpp,_kernel.cu} — a 2D virtual-device symmetric-memory kernel, built ahead-of-time via CMake against NVSHMEM (build_symm_mem_vdev2d_ext.py + kernels/cuda/CMakeLists.txt), loaded lazily.
  • kernels/olmo_symm_mem.py — symmetric-memory helpers built through the JIT extension loader.
  • kernels/nccl_rma_p2p.py + kernels/cuda/nccl_rma_p2p.cpp — NCCL RMA put/signal/wait primitives, built through the JIT extension loader.

All Python wrappers are CPU-import-safe; the CUDA/NVSHMEM extensions build lazily on first use. nvtx is used only for optional profiler annotations, behind the no-op fallback.

Testing

  • src/test/kernels/nccl_rma_p2p_test.py — a 2-GPU test (@requires_multi_gpu) that allocates an RMA window, does a bidirectional put_signal / wait_signal exchange between two ranks, and checks the received payloads. Skips cleanly when fewer than 2 GPUs are present.

The symmetric-memory (symm_mem_vdev2d) path additionally requires a multi-GPU NVSHMEM build and is exercised by hardware tests.

make checks passes; the test skips cleanly without multiple GPUs.

@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from b2f0b31 to e0b1de3 Compare June 6, 2026 01:06
@AkshitaB
AkshitaB force-pushed the akshitab/moe-permute-reorder branch from 590b903 to 6149204 Compare June 9, 2026 01:05
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from e0b1de3 to e80566a Compare June 9, 2026 01:05
@AkshitaB
AkshitaB force-pushed the akshitab/moe-permute-reorder branch from 6149204 to 23fa8cc Compare June 9, 2026 05:16
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from e80566a to ac7aeee Compare June 9, 2026 05:16
@AkshitaB
AkshitaB force-pushed the akshitab/moe-permute-reorder branch from 23fa8cc to ee8ffee Compare June 9, 2026 05:25
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from ac7aeee to ec04a9c Compare June 9, 2026 05:25
@AkshitaB
AkshitaB force-pushed the akshitab/moe-permute-reorder branch from ee8ffee to e76dd17 Compare June 9, 2026 05:29
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from ec04a9c to dc52b2a Compare June 9, 2026 05:29
@AkshitaB
AkshitaB force-pushed the akshitab/moe-permute-reorder branch from e76dd17 to 52b51f8 Compare June 9, 2026 05:45
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from dc52b2a to 743a5e9 Compare June 9, 2026 05:45
@AkshitaB
AkshitaB force-pushed the akshitab/moe-permute-reorder branch from 52b51f8 to f8a2371 Compare June 9, 2026 06:25
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from 743a5e9 to 49bf190 Compare June 9, 2026 06:25
@AkshitaB
AkshitaB force-pushed the akshitab/moe-permute-reorder branch from f8a2371 to eb25f6a Compare June 9, 2026 06:38
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch 3 times, most recently from 962e277 to 089dd4e Compare June 9, 2026 07:14
Base automatically changed from akshitab/moe-permute-reorder to akshitab/moe-v2-core June 9, 2026 07:47
TianhuaTao and others added 2 commits June 9, 2026 00:49
Three low-level comm-primitive wrappers used by the all-to-all / dispatch path:

  * symm_mem_vdev2d - 2D virtual-device symmetric-memory primitives, backed by a
    CMake-built NVSHMEM extension (kernels/cuda/CMakeLists.txt). The Python wrapper
    loads the prebuilt _symm_mem_vdev2d_ext_gpu module lazily; the companion
    build_symm_mem_vdev2d_ext.py is a CLI to build the extension AOT against a
    local NVSHMEM install.
  * olmo_symm_mem    - thin helpers layered on symm_mem_vdev2d for setup and
    group handling.
  * nccl_rma_p2p     - NCCL RMA-based point-to-point send/recv extension
    (JIT-built via load_cuda_extension).

nvtx is guarded in symm_mem_vdev2d.py; all wrappers are import-safe on CPU.

Co-Authored-By: Akshita Bhagia <[email protected]>
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@AkshitaB
AkshitaB force-pushed the akshitab/moe-symm-mem branch from 089dd4e to d191769 Compare June 9, 2026 07:49
AkshitaB and others added 6 commits June 9, 2026 01:04
- Extend LazyCudaExtension with with_cuda and a dynamic_build_kwargs hook
  (load-time-computed build args), and convert nccl_rma_p2p's bespoke loader
  to it -- the NCCL include/lib paths are discovered in the hook so the module
  stays import-safe without NCCL. (symm_mem_vdev2d keeps its CMake/importlib
  loader; olmo_symm_mem reuses it.)
- Add docstrings + __all__ to the public symm-mem/RMA entry points
  (nccl_rma_p2p, olmo_symm_mem, symm_mem_vdev2d). The build CLI script gets
  docstrings but no __all__.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
run_distributed_test defaults the gloo backend to "fork", but the test
initializes CUDA in the child processes, which fails ("Cannot re-initialize
CUDA in forked subprocess"). Force start_method="spawn"; gloo stays as the
coordination PG while the RMA path uses its own NCCL communicator.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The first nccl_rma_p2p call JIT-compiles the extension. Previously only rank 0
hit that (via get_unique_id) while rank 1 waited inside broadcast_object_list,
so rank 0's slow compile stalled the collective and rank 1's gloo connection
dropped ("connection closed by peer"). Trigger the build on every rank up front
with a barrier, so the compile happens outside the collective and a genuine
build failure surfaces symmetrically with its real error.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The nccl_rma_p2p extension uses NCCL's one-sided RMA "window" API
(ncclPutSignal/ncclWaitSignal/ncclWaitSignalDesc_t), present only in recent
NCCL (~2.28+). The NCCL bundled with the current torch build is older, so the
extension fails to compile. Skip the test with a clear reason and a note to
re-enable once the kernels CI image ships a new enough NCCL.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Covers the cuda-extension loader, grouped_mm/scaled_grouped_mm, FP8 weight
store, permute/reorder kernels, and the symm-mem/NCCL-RMA comm kernels.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The extension uses NCCL's one-sided RMA window API (ncclPutSignal /
ncclWaitSignal), present only in recent NCCL (~2.28+). Before compiling,
inspect the resolved nccl.h for those symbols and raise a clear RuntimeError
(naming the found NCCL version and how to point at a newer one) instead of
letting it fail deep in nvcc with "'ncclPutSignal' was not declared". The
check runs at load time, so the module stays import-safe.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@AkshitaB
AkshitaB marked this pull request as ready for review June 9, 2026 08:51
@AkshitaB
AkshitaB merged commit 01d615d into akshitab/moe-v2-core Jun 9, 2026
24 checks passed
@AkshitaB
AkshitaB deleted the akshitab/moe-symm-mem branch June 9, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants