Build Guide#
This document describes how to build Mooncake.
Build From Source#
Recommended Version#
OS: Ubuntu 22.04 LTS+
cmake: 3.20.x
gcc: 9.4+
Default Build#
Install common build dependencies first. A stable Internet connection is required because the script installs system packages, initializes submodules, and installs Go.
sudo bash dependencies.sh
Then build and install Mooncake:
mkdir build
cd build
cmake ..
make -j
sudo make install
Build with VRAM Segment#
To enable VRAM Segment, install CUDA toolkit and build Mooncake with
USE_VRAM_SEGMENT enabled:
sudo bash dependencies.sh
mkdir build
cd build
cmake .. -DUSE_VRAM_SEGMENT=ON
make -j
sudo make install
If NVLink is available in your environment, you can also enable it
with -DUSE_INTRA_NVLINK=ON:
sudo bash dependencies.sh
mkdir build
cd build
cmake .. -DUSE_VRAM_SEGMENT=ON -DUSE_INTRA_NVLINK=ON
make -j
sudo make install
Build with MLU Store Support#
Install the Cambricon Neuware SDK. If it is installed outside
/usr/local/neuware, set NEUWARE_HOME to its root directory.
Follow the Default Build steps above, adding
-DWITH_STORE=ON -DUSE_MLU=ON -DUSE_CUDA=OFF to the cmake .. command.
For the Python Tensor API, install torch_mlu along with the torch and
Neuware SDK versions supported by that release.
Both Classic TE and TENT can use this Store backend. To use TENT, also add
-DUSE_TENT=ON when building and set MC_USE_TENT=1 before starting the client.
MLU Tensor Offload and Reload#
Store uses CNRT for MLU pointer detection, device selection, synchronous copies, and pinned host buffers.
Start mooncake_master and create a store client as shown in
Start a Store Client. The following example
offloads a Tensor to Store and reloads it into a new MLU allocation:
from uuid import uuid4
import torch
import torch_mlu
key = f"mlu-example-{uuid4().hex}"
source = torch.arange(4096, dtype=torch.float32).to("mlu")
torch.mlu.synchronize() # Finish the producer before Store reads the pointer.
result = store.put_tensor(key, source)
if result != 0:
raise RuntimeError(f"put_tensor failed: {result}")
try:
del source
destination = torch.empty(4096, dtype=torch.float32, device="mlu")
size = destination.numel() * destination.element_size()
result = store.register_buffer(destination.data_ptr(), size)
if result != 0:
raise RuntimeError(f"register_buffer failed: {result}")
try:
# This API also accepts contiguous MLU tensors.
result = store.get_tensor_into_cuda(key, destination)
if result != size:
raise RuntimeError(f"get_tensor_into_cuda returned {result}, expected {size}")
if not torch.equal(destination.cpu(), torch.arange(4096, dtype=torch.float32)):
raise RuntimeError("Reloaded Tensor does not match the original data")
finally:
result = store.unregister_buffer(destination.data_ptr())
if result != 0:
raise RuntimeError(f"unregister_buffer failed: {result}")
finally:
result = store.remove(key, force=True)
if result != 0:
raise RuntimeError(f"remove failed: {result}")
Keep registered Tensor owners alive until transfers finish and buffers are unregistered. For a producer on a nondefault stream, synchronize its event or stream before calling Store. Tensor writes currently gather metadata and payload into host staging; registered-pointer writes use the Transfer Engine path.
With mooncake_master running, run the real-device regression suite from the
repository root:
MC_STORE_TEST_REQUIRE_MLU=1 MASTER_SERVER=127.0.0.1:50051 \
PROTOCOL=tcp python3 -m unittest discover -s mooncake-wheel/tests \
-p test_mlu_tensor.py
Build with Intel XPU#
Intel XPU support requires TENT and a native oneAPI SYCL build with the Intel
DPC++ compiler (icpx), not GCC. A Mooncake EP-only build on XPU
(-DWITH_EP=ON -DWITH_STORE=OFF) does not need TENT; see the EP build notes in
Mooncake EP & Mooncake PG. Install the
common dependencies above and the Intel GPU driver, Level Zero runtime, and
oneAPI compiler separately.
From the repository root, use a fresh build directory:
source /opt/intel/oneapi/setvars.sh
cmake -S . -B build-xpu \
-DCMAKE_C_COMPILER=icx \
-DCMAKE_CXX_COMPILER=icpx \
-DUSE_TENT=ON \
-DUSE_XPU=ON \
-DUSE_CUDA=OFF \
-DWITH_STORE_RUST=OFF
cmake --build build-xpu --parallel "$(nproc)"
For Python bindings, install from the repository root with the same compiler and backend settings. This performs a separate native build:
python -m pip install . \
-Ccmake.define.CMAKE_C_COMPILER=icx \
-Ccmake.define.CMAKE_CXX_COMPILER=icpx \
-Ccmake.define.USE_TENT=ON \
-Ccmake.define.USE_XPU=ON \
-Ccmake.define.USE_CUDA=OFF
Keep the matching SYCL/Level Zero runtime available when running Mooncake,
and use XPU-enabled PyTorch for tensor APIs. The prebuilt wheels do not include
XPU support. Select TENT at runtime with MC_USE_TENT=1. For direct dma-buf
RDMA requirements, the host-staging fallback, and same-node IPC permissions,
see the Intel XPU part of the GPU-Direct RDMA note under Hardware Backend Setup
below;
see Intel XPU Transport for runtime settings and
current limitations.
Build with NVMe-oF SSD Pool#
To enable the NVMe-oF SSD pool, install the SPDK dependencies and build
Mooncake with USE_NOF enabled:
sudo bash dependencies.sh --with-spdk
mkdir build
cd build
cmake .. -DUSE_NOF=ON
make -j
sudo make install
-DUSE_NOF=ON builds the NoF registration APIs and deployment tools. Use
-DUSE_NOF=OFF or omit the option when the NVMe-oF SSD pool is not needed.
Registering client buffers for NoF over RDMA requires SPDK 22.05 or newer
(spdk_mem_register). The build probes for it automatically and continues
with older SPDK versions, but then logs a CMake warning, and pure-NoF writes
over RDMA from unregistered user buffers fail at runtime with
“No translation” errors.
Build with Store-RS#
Store-RS is an optional Rust-native Mooncake Store. The default CMake build leaves it disabled, and the Python Store facade uses the C++ backend. Enable it when building a root wheel that should include the Rust backend and its standalone commands.
The build needs a root checkout with submodules, CMake, a C++ toolchain, Rust
(cargo on PATH), and Python 3.10 or newer. A multi-client runtime also
needs Redis or etcd.
export MOONCAKE_ROOT_DIR="$PWD"
export MOONCAKE_STORE_RS_DIR="$MOONCAKE_ROOT_DIR/mooncake-store-rs"
export MOONCAKE_BUILD_DIR="$MOONCAKE_ROOT_DIR/build/store-rs"
export MOONCAKE_PYTHON_BIN="$(command -v python3)"
cmake -S "$MOONCAKE_ROOT_DIR" -B "$MOONCAKE_BUILD_DIR" \
-DPython3_EXECUTABLE="$MOONCAKE_PYTHON_BIN" \
-DWITH_STORE=ON \
-DWITH_STORE_RUST=OFF \
-DWITH_STORE_RS=ON \
-DWITH_TE=ON \
-DUSE_TENT=ON \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_BUILD_TYPE=Release
cmake --build "$MOONCAKE_BUILD_DIR" --target build_store_rs --parallel
This out-of-tree build provides the native artifacts and standalone binaries. For a Python wheel only, skip the separate CMake build command; the wheel builder configures and builds its own CMake tree.
The root wheel owns the mooncake Python package. Build and install one wheel, then select its Store backend before importing mooncake.store:
Setting |
Backend |
|---|---|
Unset or cpp |
C++ Store |
rs |
Store-RS, included by WITH_STORE_RS=ON |
The facade reads MOONCAKE_STORE_BACKEND when mooncake.store is first imported. Use exactly cpp or rs. The setting does not change the standalone command names.
MOONCAKE_STORE_BACKEND=rs .venv-store-rs/bin/python -c \
"from mooncake.store import MooncakeDistributedStore; print(MooncakeDistributedStore)"
.venv-store-rs/bin/mooncake-store-rs-client --help
.venv-store-rs/bin/mooncake-store-rs-admin --help
.venv-store-rs/bin/mooncake-store-rs-bench --help
For workspace unit tests and installed-package smoke coverage, run
scripts/ci/run_store_rs_smoke.sh after installing the CMake python
component. The Store-RS validation guide
lists the required CMake paths and the direct commands for heavier scenarios.
Configuration, validation, and API details are in the Store-RS deployment guides, the Rust API, the Python API, and the Admin HTTP API.
RISC-V Build#
Mooncake supports native 64-bit RISC-V Linux builds with USE_RISCV enabled.
The option keeps regular Release optimizations but disables interprocedural
optimization for the Python extensions, avoiding the excessive memory use of
full GNU LTO on RISC-V build hosts. The build also detects whether 16-byte
atomic operations require libatomic and links it automatically.
The following configuration builds the C++, Python, and Rust components while disabling every component that requires Go:
mkdir build-riscv
cd build-riscv
cmake -G Ninja .. \
-DCMAKE_BUILD_TYPE=Release \
-DUSE_RISCV=ON \
-DWITH_STORE_GO=OFF \
-DWITH_P2P_STORE=OFF \
-DUSE_ETCD=OFF \
-DSTORE_USE_ETCD=OFF \
-DSTORE_USE_K8S_LEASE=OFF \
-DBUILD_UNIT_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
-DBUILD_BENCHMARK=OFF
cmake --build . --parallel 4
Adjust the parallel job count for the available memory. The example uses four jobs because optimized C++ and Python binding translation units can each need several gigabytes of memory on RISC-V.
Hardware Backend Setup#
Run sudo bash dependencies.sh before using any of these backend-specific build
options. The script handles common dependencies; vendor SDKs and runtime
environment setup must be prepared separately.
Hardware / backend |
Build option |
External SDK / setup |
Environment and notes |
|---|---|---|---|
NVIDIA CUDA / GPUDirect |
|
Install CUDA 12.1+ and enable |
Add CUDA libraries to |
NVIDIA NCCL DeviceTransport |
|
Install NCCL 2.30.4+ with |
Disabled by default. Enabling it directly links NCCL into the EP extensions, so importing |
NVIDIA NCCL host RMA (WRITE only) |
|
Install NCCL 2.30.4+. Requires CUDA. |
Set |
NVIDIA Multi-Node NVLink |
|
Requires CUDA. |
Also set |
Moore Threads MUSA |
|
Install MUSA SDK and |
Add |
Cambricon MLU |
|
Install Cambricon Neuware SDK. |
Set |
MetaX MACA |
|
Install MACA SDK. |
Set |
Intel XPU (Arc / Data Center GPU) |
|
Install the oneAPI DPC++ compiler and Level Zero runtime ( |
Source |
Huawei Ascend Direct |
|
Install Ascend CANN Toolkit and ADXL dependencies. |
Source |
Huawei Ascend UBSHMEM |
|
Install Ascend CANN Toolkit. Requires CANN >= 9.0.0, driver >= 26.0.0, Lingqu >= 1.5. |
Source the CANN |
AMD HIP / ROCm |
|
Install ROCm/HIP SDK. |
Ensure HIP compiler, headers, and runtime libraries are visible to CMake. |
Hygon DCU |
|
Install DTK SDK. |
Set |
ScaleFabric SHCA |
|
Install |
Supports Transfer Engine/TENT RDMA paths only; Mooncake-EP IBGDA is not supported. |
Iluvatar CoreX |
|
Install CoreX SDK. |
Set |
Biren GPU |
|
Install Biren SUPA SDK. |
Set |
NCCL host RMA constraints
The first valid NCCL host WRITE freezes the ordered CUDA-buffer catalog before
bootstrap. Registration and unregistration are not allowed afterward, even if
bootstrap fails. Session initialization is attempted once for each
endpoint/device pair. If the session reaches a terminal failure, it retains the
error and subsequent transfers fail without retrying bootstrap. Recovery
requires destroying and recreating the NCCL-only TransferEngine on both
peers, then registering the buffers again. A one-sided restart is unsupported.
Same-engine targets remain unsupported and should use
the intra-node NVLink/P2P transport.
NCCL DeviceTransport version contract
Mooncake currently requires NCCL Device API device code, whether AOT-compiled
or JIT-compiled, to use NCCL headers that exactly match the loaded runtime
libnccl.so. NcclTransport::initialize() rejects a mismatch. After upgrading
NCCL, rebuild Mooncake and every AOT CUDA kernel that includes
transport/device/nccl_device.cuh. Invalidate and regenerate any cached NCCL
Device API JIT kernels before running. This is required for the current GIN
device-code model, which is not cross-version compatible.
GPU-Direct RDMA
Mooncake can use the DMA-BUF path for GPU-Direct RDMA, which does not
require the nvidia-peermem kernel module. When WITH_NVIDIA_PEERMEM is
unset, Mooncake uses the legacy ibv_reg_mr path if a peer-memory module
(nvidia-peermem, or nv_peer_mem from MLNX_OFED) is loaded and DMA-BUF
otherwise (for example the NVIDIA open kernel modules with the inbox RDMA stack
and no MLNX_OFED, where ibv_reg_mr on GPU memory would fail with
Failed to register memory 0x...: Bad address [14]). Set
WITH_NVIDIA_PEERMEM=0 to force DMA-BUF, or WITH_NVIDIA_PEERMEM=1 to force
ibv_reg_mr. DMA-BUF needs the NVIDIA open kernel modules and Linux 5.12 or
later; see Section 3.7 of https://docs.nvidia.com/cuda/gpudirect-rdma/ for
nvidia-peermem installation instructions.
Intel XPU builds (-DUSE_XPU=ON) use DMA-BUF for direct RDMA: when a USM
device allocation is registered, TENT asks the Level Zero runtime to export it
as a dma-buf and registers that with ibv_reg_dmabuf_mr, so the NIC reads and
writes VRAM directly with no host copy. This needs rdma-core 34+ and a NIC
driver with dma-buf support (for example mlx5). The direct path is attempted
per buffer and is not guaranteed: when the verb or driver support is missing,
when the export fails for a given allocation (see the pooling caveat below), or
when transports/rdma/disable_gpu_direct_rdma is set to true in the TENT
configuration, transfers touching that buffer fall back to staging through
pinned host memory.
Both direct RDMA and host-staged transfers involving XPU memory currently
require an XPU-platform initiator, even when its local buffer is DRAM and
only the remote buffer is XPU memory. Staging also requires the initiator’s
XpuTransport to be enabled; without it, XPU memory is not staged and is
routed only over a transport that copies device memory itself, such as TCP.
A CPU-platform initiator cannot currently route
these requests; it does not transparently fall back to staging. A cpu:0
buffer inside an XPU-platform process is not a CPU-platform peer.
The Transfer Engine requests dedicated exportable Level Zero allocations;
runtime allocation/export failures can still require staging. For device
memory allocated elsewhere (for example PyTorch XPU tensors), the Intel
compute runtime can pool small USM allocations into shared buffers whose
dma-buf cannot be registered per allocation. Foreign or fallback USM is
eligible for export only when the allocation and dma-buf sizes match exactly.
Extra backing bytes cannot safely be distinguished from a shared pool, even
when they match a rounded page size, so padded foreign allocations also stage.
NEOReadDebugKeys=1 EnableDeviceUsmAllocationPool=0 disables pooling, but does
not bypass this conservative size check.
On the same node, registered XPU memory is also shared between processes with
Level Zero IPC handles, so VRAM-to-VRAM transfers between two local engines
(for example prefill and decode workers) are local XPU copies rather than
network transfers. Importing a handle uses pidfd_getfd(2) on the exporting
process and therefore needs ptrace permission over it. The Level Zero runtime
marks every process that opens a device with PR_SET_PTRACER_ANY, so the same
user in the same pid namespace with Yama ptrace_scope 0 or 1 (the default on
most distributions) is enough; ptrace_scope 2 needs CAP_SYS_PTRACE (in
Kubernetes, securityContext.capabilities.add: [SYS_PTRACE]) and 3 forbids it.
Without that permission, or with transports/xpu/disable_ipc: true in the
TENT configuration, those transfers use the RDMA or TCP transport instead.
Use Mooncake in Docker Containers#
Mooncake supports Docker-based deployment. You can either build the image from
this repository with docker/mooncake.Dockerfile or substitute a published
tag that matches the release you want to run.
For the container to use the host’s network resources, you need to add the --device option when starting the container. The following is an example.
# In host
sudo docker build -f docker/mooncake.Dockerfile -t mooncake:from-source .
sudo docker run --net=host --device=/dev/infiniband/uverbs0 --device=/dev/infiniband/rdma_cm --ulimit memlock=-1 -t -i mooncake:from-source /bin/bash
# Run transfer engine in container
cd /Mooncake-main/build/mooncake-transfer-engine/example
./transfer_engine_bench --device_name=ibp6s0 --metadata_server=10.1.101.3:2379 --mode=target --local_server_name=10.1.100.3
For SGLang HiCache deployments inside Docker, reserve HugeTLB pages on the host before starting the container and pass the allocator settings through the container environment:
python3 scripts/check_hicache_hugepage_requirements.py \
--tp-size 4 \
--hicache-size 64gb \
--global-segment-size 8gb \
--arena-pool-size 56gb \
--available-hugetlb 512gb
sudo sysctl -w vm.nr_hugepages=262144
grep -E 'HugePages_Total|HugePages_Free|Hugepagesize' /proc/meminfo
sudo docker run --gpus all \
--net=host \
--ipc=host \
--ulimit memlock=-1 \
--shm-size=128g \
--device=/dev/infiniband/uverbs0 \
--device=/dev/infiniband/rdma_cm \
-e MC_STORE_USE_HUGEPAGE=1 \
-e MC_STORE_HUGEPAGE_SIZE=2MB \
-e MOONCAKE_GLOBAL_SEGMENT_SIZE=8gb \
-e MC_MMAP_ARENA_POOL_SIZE=56gb \
-t -i mooncake:from-source /bin/bash
The 64gb / 56gb values above are tuned examples for large HiCache deployments, not defaults. The arena remains disabled unless you explicitly enable it, and if you enable it via gflag without an env override the default pool size is 8gb. On smaller hosts, start with 8gb or 16gb and size upward with the helper. When you want the baseline direct-mmap() path instead of the arena, set MC_DISABLE_MMAP_ARENA=1 (also accepts true, yes, or on) and omit MC_MMAP_ARENA_POOL_SIZE. Set it before the first Mooncake mmap-buffer allocation in the process. If you build the image from source with docker/mooncake.Dockerfile, that source-built image also installs the helper as mooncake-hicache-sizing.
Without MC_STORE_USE_HUGEPAGE=1, the arena may opportunistically try hugepages and then retry on regular pages if HugeTLB is unavailable. When MC_STORE_USE_HUGEPAGE=1 is set, both the arena path and the direct-mmap() fallback path require HugeTLB pages. Mooncake will not silently degrade that explicit hugepage request to regular pages.
For RDMA Store segments backed by HugeTLB, page population is automatically deferred until immediately before transfer-engine registration and parallelized across CPU threads:
export MC_STORE_USE_HUGEPAGE=1
export MC_STORE_HUGEPAGE_SIZE=2MB
Direct mappings use a generic worker pool. NUMA-segmented mappings bind each
worker to the node associated with its memory region. The mmap arena keeps its
eager population behavior; set MC_DISABLE_MMAP_ARENA=1 if an arena was
otherwise enabled and deferred direct-mmap population is desired.
Advanced Compile Options#
The following options can be passed to cmake ...
Accelerator and Hardware Options#
Option |
Default |
Description |
|---|---|---|
|
|
Enable GPU memory support, including GPUDirect RDMA, NVMe-oF, and GPU-aware TCP transport. Required when transferring GPU memory, even when using TCP. |
|
|
Enable the NCCL DeviceTransport backend. Requires CUDA and NCCL 2.30.4+ with |
|
|
Enable the experimental, WRITE-only NCCL host RMA transport. Requires CUDA and NCCL 2.30.4+, must be installed before its buffers are registered, and must be the engine’s only installed transport. |
|
|
Enable Multi-Node NVLink transport. Requires |
|
|
Enable Moore Threads GPU support via MUSA. |
|
|
Enable MetaX (Muxi) GPU support via MACA. |
|
|
Enable AMD GPU support via HIP/ROCm. |
|
|
Enable Hygon DCU support via DTK SDK. Uses a CUDA-compatible runtime. |
|
|
Enable Iluvatar CoreX GPU support. Uses a CUDA-compatible runtime. |
|
|
Enable Biren GPU support via the SUPA SDK. Uses a CUDA-compatible runtime. Set |
|
|
Enable Cambricon MLU memory support via Neuware, including memory detection, topology discovery, and RDMA registration. |
|
|
Enable Intel XPU memory support in TENT via SYCL/Level Zero: memory detection, host staging, intra-node PCIe P2P copies between XPUs, and dma-buf GPUDirect RDMA registration. Requires |
|
|
Enable the TENT GDS transport for Intel XPU memory through a cuFile-compatible library (for example Intel xFile) that provides |
|
|
Enable RISC-V build compatibility settings, including disabling full IPO/LTO for Python extensions. |
|
|
Enable ScaleFabric SHCA InfiniBand support for Transfer Engine/TENT RDMA paths only. Mooncake-EP IBGDA is not supported. |
|
|
Enable Ascend Direct transport and HCCS support via the ADXL engine. Recommended for Ascend builds. |
|
|
Enable Huawei Ascend NPU shared memory transport via CANN VMM APIs. |
|
|
Enable intranode NVLink transport. |
|
|
Enable create VRAM Segment instead of (default) DRAM Segment. |
|
|
Enable CXL support. |
|
|
Enable the MPComm transport in TENT (multi-NIC memory pooling over RDMA). Requires |
Vendor SDK Path Overrides#
Option |
Applies when |
Description |
|---|---|---|
|
|
Override the MACA SDK root. |
|
|
Override the MACA include directory. |
|
|
Override the MACA library directory. |
|
|
Override MACA runtime libraries linked by |
|
|
Override the DTK SDK root. |
|
|
Override the DTK include directory. |
|
|
Override the DTK library directory. |
|
|
Override the CoreX SDK root. |
|
|
Override the CoreX include directory. |
|
|
Override the CoreX library directory. |
|
|
Override the Biren SUPA SDK root. |
|
|
Override the Neuware SDK root. |
|
|
Override the Neuware include directory. |
|
|
Override the Neuware library directory. |
|
|
Required. MPComm install prefix; must contain |
Transport and Metadata Options#
Option |
Default |
Description |
|---|---|---|
|
|
Enable AWS Elastic Fabric Adapter transport via libfabric. See EFA Transport. |
|
|
Build Mooncake Store with NVMe-oF SSD pool support. Use |
|
|
Enable Redis-based metadata service for Transfer Engine. Requires hiredis. |
|
|
Enable HTTP-based metadata service. |
|
|
Enable etcd-based metadata service. Requires Go 1.23+. |
|
|
Enable etcd-based failover for Mooncake Store. Independent from |
|
|
Enable Redis-based failover for Mooncake Store. Independent from |
|
|
Enable Kubernetes Lease-based failover for Mooncake Store. Cannot be enabled with |
Component Options#
Option |
Default |
Description |
|---|---|---|
|
|
Build the Mooncake Transfer Engine component and sample code. |
|
|
Build the Mooncake Store component. |
|
|
Build Go bindings for Mooncake Store when |
|
|
Build the Mooncake Conductor service. |
|
|
Enable Golang support and build the P2P Store component. Requires Go 1.23+. |
|
|
Build the Transfer Engine Rust library ( |
|
|
Build Mooncake Store Rust bindings and CMake Rust targets. |
|
|
Build the Rust-native Mooncake Store (Store-RS), its Python extension, and the standalone commands. Requires |
|
|
Build Mooncake EP and the native Mooncake PG core/device libraries. The Torch-facing PG adapter is compiled by the installed package at first |
Build Behavior Options#
Option |
Default |
Description |
|---|---|---|
|
|
Build Transfer Engine as a shared library. |
|
|
Build unit tests. |
|
|
Build examples. |
|
|
Use jemalloc in the Mooncake Store master. |