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
Build configuration:
Debug, Release, RelWithDebInfo, or MinSizeRelCustom build directory (default:
build/<platform>/<config>)Build Phases
Run CMake to generate/update makefiles
Build the project
Run tests after building
Clean build artifacts for the selected configuration
Package the build output
Hardware Acceleration
Enable CUDA support
Path to CUDA installation (default:
$CUDA_HOME or $CUDA_PATH)Enable ROCm support for AMD GPUs
Enable DirectML support (Windows only)
Enable TensorRT-RTX support
Language Bindings
Build C# API bindings
Build Java bindings
Skip building the Python wheel
Other Options
Enable parallel build
Skip running tests
Skip building examples
Enable guidance support for constrained decoding
CMake generator (default: “Visual Studio 17 2022” on Windows, “Unix Makefiles” elsewhere)
Extra CMake definitions (without -D prefix)
Advanced Build Scenarios
Cross-Compilation for Android
Android ABI:
armeabi-v7a, arm64-v8a, x86, or x86_64Android API Level (27 = Android 8.1)
Cross-Compilation for iOS
Build for iOS
macOS platform SDK location
Target architecture for iOS/macOS
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 to CUDA installation
Alternative path to CUDA (Windows)
Path to Android SDK
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