Prerequisites
Common Requirements
CMake
Version 3.26 or higher (3.28+ for macOS xcframework support)
Python
Python 3.8 or higher
Git
For cloning the repository
C++ Compiler
GCC 11+, Clang, or MSVC
Platform-Specific Requirements
- Linux
- Windows
- macOS
Optional: Hardware Acceleration
CUDA Support
CUDA Support
For NVIDIA GPU acceleration:
- CUDA Toolkit 11.8 or higher
- cuDNN compatible with your CUDA version
- Set
CUDA_HOMEorCUDA_PATHenvironment variable
ROCm Support
ROCm Support
For AMD GPU acceleration:
- ROCm 5.0 or higher
- Compatible AMD GPU
DirectML Support (Windows)
DirectML Support (Windows)
For Windows DirectML acceleration:
- Windows 10/11
- DirectX 12 capable GPU
- No additional installation required
Clone the Repository
Build Phases
The build system supports three phases:- Update (
--update): Run CMake to generate makefiles - Build (
--build): Build all projects - Test (
--test): Run all unit tests
Default behavior:
- Native builds:
--update --build --test - Cross-compiled builds:
--update --build(tests skipped)
Basic Build
CPU-Only Build
- Generate build files in
build/<platform>/Release - Build the C++ library
- Build the Python wheel
- Run tests (unless
--skip_testsis specified)
Build with CUDA
If
CUDA_HOME or CUDA_PATH environment variable is set, you can omit --cuda_home.Build with DirectML (Windows)
Build with ROCm
Build Options
Configuration
string
default:"RelWithDebInfo"
Build configuration:
Debug, Release, RelWithDebInfo, or MinSizeRelpath
Custom build directory (default:
build/<platform>/<config>)Build Phases
flag
Run CMake to generate/update makefiles
flag
Build the project
flag
Run tests after building
flag
Clean build artifacts for the selected configuration
flag
Package the build output
Hardware Acceleration
flag
Enable CUDA support
path
Path to CUDA installation (default:
$CUDA_HOME or $CUDA_PATH)flag
Enable ROCm support for AMD GPUs
flag
Enable DirectML support (Windows only)
flag
Enable TensorRT-RTX support
Language Bindings
flag
Build C# API bindings
flag
Build Java bindings
flag
Skip building the Python wheel
Other Options
flag
Enable parallel build
flag
Skip running tests
flag
Skip building examples
flag
Enable guidance support for constrained decoding
string
CMake generator (default: “Visual Studio 17 2022” on Windows, “Unix Makefiles” elsewhere)
list
Extra CMake definitions (without -D prefix)
Advanced Build Scenarios
Cross-Compilation for Android
string
default:"arm64-v8a"
Android ABI:
armeabi-v7a, arm64-v8a, x86, or x86_64integer
default:"27"
Android API Level (27 = Android 8.1)
Cross-Compilation for iOS
flag
Build for iOS
string
macOS platform SDK location
string
Target architecture for iOS/macOS
string
Minimum target platform version
Build Apple Framework
Windows ARM64
Custom ONNX Runtime
Use a custom ONNX Runtime build:Build Examples
Development Build with Tests
Production Build with CUDA
Build Only (Skip Update and Test)
Clean and Rebuild
Build with Constrained Decoding Support
Installing the Python Package
After building, install the Python wheel:Troubleshooting
CMake Generation Fails
CMake Generation Fails
- Ensure CMake version is 3.26 or higher (3.28+ for macOS)
- Check that all dependencies are installed
- Delete
CMakeCache.txtand the build directory, then retry - Verify compiler version (GCC 11+ required)
CUDA Not Found
CUDA Not Found
- Set
CUDA_HOMEorCUDA_PATHenvironment variable - Ensure
nvccis in your PATH - Verify CUDA Toolkit version is 11.8 or higher
Build Errors on Windows
Build Errors on Windows
- Ensure Visual Studio 2022 is installed
- Run build from “Developer Command Prompt for VS 2022”
- Check that Windows SDK is installed
- Try specifying generator explicitly:
--cmake_generator "Visual Studio 17 2022"
Out of Memory During Build
Out of Memory During Build
- Reduce parallel builds: Remove
--parallelflag - Use
ReleaseorMinSizeRelconfiguration instead ofDebug - Close other applications
- Increase system swap/page file
Test Failures
Test Failures
- Ensure model files are accessible
- Check hardware acceleration is properly configured
- Try running tests individually to isolate issues
- Use
--skip_teststo skip testing during build
Build System Details
Build Directory Structure
CMake Variables
You can pass custom CMake variables:Environment Variables
path
Path to CUDA installation
path
Alternative path to CUDA (Windows)
path
Path to Android SDK
path
Path to Android NDK
Next Steps
Quickstart
Run your first inference with the built package
Model Builder
Build optimized ONNX models
Contributing
Contribute to ONNX Runtime GenAI
Examples
Explore code examples