Skip to content

Build from source

This page gives the CMake commands for a host-only build and a CUDA build, the CUDA architectures a build targets, and the tests. Check the requirements on installation.md first.

Host-only build (no GPU, no CUDA)

A host-only build holds the C++ scheduler, block manager and batch assembler, the qix-serve launcher, the node router and the unit tests. It cannot serve a model.

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DTND_BUILD_TESTS=ON -DTND_DISABLE_CUDA=ON
cmake --build build -j"$(nproc)"

TND_DISABLE_CUDA=ON (CMakeLists.txt:22) skips CUDA detection even on a machine that has a toolkit. Without it, a machine with no CUDA compiler builds host-only anyway (CMakeLists.txt:115-120).

CUDA build

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DTND_BUILD_TESTS=ON
cmake --build build -j"$(nproc)"

CMake enables CUDA when it finds a CUDA compiler (CMakeLists.txt:81-85) and the driver library libcuda.so.1 (CMakeLists.txt:97-103). The search also looks in the toolkit's lib64/stubs (CMakeLists.txt:98-102), so a build machine with no driver still builds CUDA when the toolkit ships the stub libcuda. A toolkit with neither the driver nor the stub builds host-only and prints a warning; -DTND_FORCE_CUDA=ON (CMakeLists.txt:15) builds the CUDA parts anyway (CMakeLists.txt:108-110).

Run CMake with the Python interpreter whose torch you will serve with, for example -DPython_EXECUTABLE=$(which python3). CMake reads torch's C++ ABI from that interpreter, and an explicit Python_EXECUTABLE wins over the first python3 on PATH (cmake/TndPackagingContracts.cmake, tnd_select_abi_python).

The CUDA build compiles many kernel files. On a small machine, lower the job count (cmake --build build -j2) to stay within memory.

CUDA architectures

When you do not pass -DCMAKE_CUDA_ARCHITECTURES (or set the CUDAARCHS environment variable), tnd_resolve_cuda_architectures in cmake/TndPackagingContracts.cmake:21-46 picks the list from the toolkit version:

CUDA toolkit Architectures built
below 12.8 70;75;80;86;89;90
12.8 70;75;80;86;89;90;100
12.9 up to 13.0 70;75;80;86;89;90;100;103
13.0 or newer 75;80;86;89;90;100;103 (CUDA 13 dropped sm_70)
  • 90 is Hopper (H100, H200).
  • 100 is B200 and GB200.
  • 103 is B300 and GB300. It is a separate target from 100.

An explicit list is used as given. It may carry an a or f suffix (90a, 100f) for architecture-specific instructions; CMake meta-values such as native or all are refused (cmake/TndPackagingContracts.cmake, tnd_cuda_architectures_to_torch).

The configure log prints the list it chose: Resolved CUDA architectures: ... (CMakeLists.txt:96).

Build options

The options that change what is built are declared with option(...) in CMakeLists.txt. The ones a user is most likely to touch:

Option Default What it does
TND_BUILD_TESTS ON Builds the GoogleTest binaries (CMakeLists.txt:1836)
TND_DISABLE_CUDA OFF Host-only build even when a toolkit is present
TND_FORCE_CUDA OFF CUDA build without libcuda.so.1 on the build machine
TND_REQUIRE_TORCH ON Fail the configure when CUDA is on and torch is missing
TND_ENABLE_FP8 ON FP8 KV-cache kernels (needs CUDA 11.8 or newer)
TND_ENABLE_EP ON The expert-parallel all-to-all (needs CUDA, torch and NCCL)
TND_ENABLE_TP OFF The tensor-parallel group (needs CUDA, torch and NCCL)

Each option's help string in CMakeLists.txt says what it needs. None of them is a tuning knob: the engine picks its run-time settings itself (see configuration.md).

Run from the build tree

The build copies the tnd Python package and its compiled modules into build/tnd/, so you can run without installing:

export PYTHONPATH="$PWD/build"
./build/tnd-serve --model Qwen/Qwen2.5-7B-Instruct

From the build tree, qix-serve:

  • finds the serving profiles in csrc/serve_auto/profiles/ (the last place it looks, csrc/serve_auto/tnd_serve_main.cpp:98-111);
  • finds tnd-node-router through TND_NODE_ROUTER, else on PATH, else next to itself (csrc/serve_auto/tnd_serve_main.cpp:130-135);
  • starts each rank as python3 -m tnd.serve and prints a WARN line, because the rank wrapper tnd-serve-launch is not on PATH (csrc/serve_auto/tnd_serve_main.cpp:121-128). That wrapper ships with the .deb package only, so a build from source always takes this path. Pass --rank-python <path> to name the interpreter.

Tests

C++ unit tests

ctest --test-dir build --output-on-failure

The test binaries are registered with gtest_discover_tests: tnd_paged_core_tests, tnd_serve_auto_tests, tnd_convoy_tests and tnd_tp_channel_tests on every build (CMakeLists.txt:1914-2051), and tnd_kernel_tests on a CUDA build (CMakeLists.txt:2073). The kernel tests need a GPU.

The core set

tests/CORE_SET.json names about two tests for each engine component. scripts/core_set.py builds what those tests need into build-core/ and runs them:

python3 scripts/core_set.py local             # the whole core set
python3 scripts/core_set.py local --changed   # only the components that own a file you changed
python3 scripts/core_set.py owners csrc/serve_auto/serving_profile.cpp

It runs on a CPU-only machine. The Python tests need torch, pytest, pytest-timeout and numpy; a CPU build of torch is enough. Exit code 0 means every test passed, 1 means a test failed, 2 means the set could not run. A Python test that skips counts as a failure.

Clean up

A CUDA build directory takes several GB. Delete it when you are done: rm -rf build build-core.