Building from Source#
2026-08-31
15 min read
Advanced Micro Devices, Inc.
This page summarises the hip-python build system for users who want to
build the wheels (or just the docs) themselves. It is a brief tour;
the full design — including CMake helper APIs, the
generator-emitted CMake includes, sdist build mechanics, and the
Cython version requirement — lives in
share/design/BUILDING.md
in the source tree.
Components#
The build produces eight Python wheels, one per package directory
under packages/. The binding wheels contribute to the same two
PEP 420 implicit namespace packages at runtime — rocm.bindings.* and
cuda.bindings.* — so a downstream user installs only the wheels
they need.
Wheel |
Provides |
|---|---|
|
DLL loader, shared Cython types ( |
|
|
|
Math/FFT/random/sparse libraries: |
|
System-level libraries: |
|
LLVM-C bindings, AMD COMGR bindings (with the high-level
|
|
CUDA interop layer: |
|
Pure-Python alias package: |
|
The ROCm HIP backend for Numba ( |
The unified build orchestrator at packages/CMakeLists.txt builds
all eight via the all_wheels aggregate target. A development loop
can also build one package at a time (cd packages/<pkg> && python3
-m build --wheel --no-isolation) without touching the others.
Quick start#
Two minimal recipes — one for wheels, one for docs:
All wheels at once. From a checkout with ROCM_PATH pointing
at a ROCm installation (default /opt/rocm):
cd packages
cmake -B build
cmake --build build --target all_wheels -j$(nproc)
Wheels land in packages/build/dist/ (override with
-DHIP_PYTHON_WHEEL_OUTPUT_DIR=...).
Single package only — useful during development:
cd packages/rocm-bindings-core
python3 -m build --wheel --no-isolation
Frequently used build options#
Two options decide what all_wheels actually contains beyond the
binding wheels:
Option |
Default |
Effect |
|---|---|---|
|
|
Bundles a shared LLVM into the |
|
|
Builds the pure-Python |
For example, a Windows build that declines the bundled LLVM, and with it
numba.hip:
cd packages
cmake -B build -DHIP_PYTHON_BUNDLE_LIBLLVM=OFF -DHIP_PYTHON_BUILD_NUMBA_HIP=OFF
cmake --build build --target all_wheels
The full option list — build type, ROCm path, auditwheel repair,
configure-time codegen, stub generation — is in
share/design/BUILDING.md.
Documentation build#
Sphinx HTML docs are an independent CMake target — they do not
depend on all_wheels and can be built before, after, or in
parallel with the wheels. Sphinx parses .py / .pyi source
files directly via sphinx-autoapi, so no compiled extension
needs to be installed first.
The target is gated on HIP_PYTHON_BUILD_DOCS=ON:
cd packages
cmake -B build -DHIP_PYTHON_BUILD_DOCS=ON
cmake --build build --target docs
# open ../docs/index.html
Relevant CMake options:
Option |
Default |
Effect |
|---|---|---|
|
|
Gates target creation. Fails fast if |
|
|
Destination for the rendered HTML. Override for per-version
layouts ( |
|
|
Sphinx intermediate cache. |
Wheels and docs can build concurrently:
cmake --build build --target all_wheels docs -j$(nproc)
docs_src/sphinx/_toc.yml.in is itself generator output: the codegen
renders it from the handcoded _toc.yml.in.in template on every run,
substituting the discovered module list into one subtree per wheel. The
handwritten user-guide pages are listed inline in the template, so they
are the part to edit by hand; per-module API pages slot in without any
TOC edit.
Building on Windows#
Wheels are published for Windows alongside the Linux ones, so building from
source here is for development or for a configuration the published wheels do
not carry. ci\internal\build-wheels.ps1 is the PowerShell counterpart to the
Linux ci/internal/build-wheels.sh and drives the same all_wheels target:
. ci\internal\env-rocm.ps1 # sets ROCM_PATH and PATH
python -m pip install -r ci\internal\requirements-build.txt
ci\internal\build-wheels.ps1 # add -Light for core + hip + compiler
ci\internal\test.ps1 # examples, unit tests and numba-hip
The MSVC environment is imported automatically, so the script behaves the same from a plain PowerShell prompt, a CI runner, or a Developer shell.
test.ps1 takes ROCm from ROCM_PATH by default, which suits a system
install or an unpacked tarball. Pass -UseRocmSdkWheels to install ROCm into
the test venv from the rocm_sdk wheels instead, the way most users get it:
ci\internal\test.ps1 -UseRocmSdkWheels # target read from the GPU
ci\internal\test.ps1 -UseRocmSdkWheels -GfxArch gfx1100
The ROCm version defaults to the one the bindings were generated against, and
the rocm-sdk-device-* wheel to the target of the GPU in the machine. Those
wheels spread ROCm over several trees, so do not point ROCM_PATH at one of
them by hand: _rocm_sdk_devel in particular holds a second copy of
libhipblaslt.dll next to an incomplete set of Tensile kernels, and hipBLASLt
looks for kernels beside whichever copy it loaded, so that one crashes inside the
algorithm search. Let the bindings resolve libraries through
rocm_sdk.find_libraries, which knows which tree owns each library.
Where the Windows build differs from Linux:
Aspect |
Windows behaviour |
|---|---|
Host compiler |
MSVC ( |
Build type |
|
Generator |
Ninja. The Linux script forces |
|
Not used; it is a Linux ELF retagger. The wheels are emitted with a
native |
Module set |
Smaller. The components ROCm does not ship for Windows are detected and skipped at configure time; see the table in Installation. |
Library naming |
ROCm’s Windows DLLs are version-suffixed ( |
manylinux repair via auditwheel#
For distribution-friendly manylinux_* wheels, enable
HIP_PYTHON_AUDITWHEEL_REPAIR=ON. Each per-package wheel target
then runs auditwheel repair after the underlying python -m
build step:
cd packages
cmake -B build -DHIP_PYTHON_AUDITWHEEL_REPAIR=ON
cmake --build build --target all_wheels -j$(nproc)
What this does in practice:
Each freshly-built wheel is inspected for the externally-loaded shared libraries it depends on.
Libraries that match the
manylinuxallowlist (the C runtime and a small standard set) are left alone.Libraries outside the allowlist (the optional bundled ROCm math libraries when present, …) are explicitly excluded — hip-python
dlopen-resolves these at runtime via therocm.bindings.util.loadershim, so they MUST NOT be bundled into the wheel.The
manylinux_2_17_x86_64(or matching) tag is added to the wheel filename, making it pip-installable on systems older than the build host’s glibc.
The result is a wheel that runs on a wider range of distributions than the unrepaired one, while still loading the system’s actual ROCm libraries at import time.
See also#
share/design/BUILDING.mdin the source tree — full build-system design including CMake helper APIs (hip_python_initialize,hip_python_add_cython_module, …), the generator-emitted CMake include files, sdist build mechanics, and Cython version requirements.share/design/CODEGEN.md— how the generator-managed parts of the build (module lists, Cython sources, TOC entries) are produced.share/design/BINDINGS.md— the anatomy of the generated bindings (two-tier wrapper layout, GIL semantics, pointer-arg classification, handcoded helpers).