Getting the Code
Clone the repository from GitHub:CPU Build
1
Configure the build
Use CMake to configure the build directory:
2
Build the project
Compile with CMake:
For faster compilation, add
-j to run multiple jobs in parallel:3
Run the binary
After building, binaries are located in
build/bin/:Debug Builds
For debug builds, the process differs based on your generator:Static Builds
To build static libraries instead of shared:Performance Tips
- ccache: Install ccache for faster repeated compilation
- Parallel builds: Use
-jflag with the number of CPU cores - Generators: Use Ninja generator for automatic parallelization:
cmake -B build -G Ninja
Metal Build (macOS)
On macOS, Metal is enabled by default for GPU acceleration.Metal makes computations run on the GPU. To disable Metal at compile time:
CUDA Build (NVIDIA GPU)
For NVIDIA GPU acceleration, ensure you have the CUDA toolkit installed.1
Install CUDA toolkit
Download from the NVIDIA developer site and follow installation instructions for your platform.
2
Build with CUDA support
3
Verify CUDA is working
Run with GPU layers:
Non-Native CUDA Builds
By default, llama.cpp builds for GPUs connected to your system. For a build covering all CUDA GPUs:Override Compute Capability
Ifnvcc cannot detect your GPU, explicitly specify architectures:
1
Find your GPU's compute capability
Check NVIDIA’s CUDA GPUs page for your GPU’s compute capability.Examples:
- GeForce RTX 4090: 8.9
- GeForce RTX 3080 Ti: 8.6
- GeForce RTX 3070: 8.6
2
Build with specific architectures
CUDA Runtime Variables
Control CUDA behavior with environment variables:HIP Build (AMD GPU)
For AMD GPU acceleration using ROCm/HIP:1
Install ROCm
Install ROCm from your Linux distro’s package manager or from the ROCm Quick Start guide.
2
Build with HIP support
For a gfx1030-compatible AMD GPU:
GPU_TARGETS is optional. Omitting it will build for all GPUs in the current system.3
Find your GPU architecture
Windows HIP Build
Using x64 Native Tools Command Prompt for VS:Vulkan Build
Vulkan provides cross-platform GPU acceleration.Windows
- w64devkit
- Git Bash MINGW64
- MSYS2
1
Install dependencies
- Download and extract w64devkit
- Install the Vulkan SDK
2
Copy Vulkan dependencies
Launch
w64devkit.exe and run:3
Build
Linux
- System packages
- LunarG SDK
Install required dependencies:Then build:
Debian/Ubuntu
macOS
1
Install Vulkan SDK
Follow the Getting Started with the MacOS Vulkan SDK guide.
Check the “KosmicKrisp” box during installation for better performance.
2
Set environment variables
3
Build
BLAS Build
BLAS support can improve prompt processing performance for batch sizes > 32.Accelerate Framework (macOS)
Enabled by default on macOS. Just build normally:OpenBLAS (Linux)
Install OpenBLAS and build:Intel oneMKL
SYCL Build (Intel GPU)
For Intel GPU support (Data Center Max, Flex, Arc series):Platform-Specific Builds
Windows
1
Install Visual Studio 2022
Install Visual Studio 2022 Community Edition.Select these components:
- Workload: Desktop development with C++
- Components:
- C++ CMake Tools for Windows
- Git for Windows
- C++ Clang Compiler for Windows
- MS-Build Support for LLVM-Toolset (clang)
2
Use Developer Command Prompt
Always use a Developer Command Prompt or PowerShell for VS2022.
3
Build
For Windows on ARM (WoA):For x64 with Ninja and clang:
Android
See the Android build documentation for detailed instructions.Additional Backends
CANN (Ascend NPU)
ZenDNN (AMD EPYC CPUs)
Arm KleidiAI
Optimized kernels for Arm CPUs:For SME support, set
GGML_KLEIDIAI_SME=1 at runtime.OpenCL (Adreno GPU)
See the OpenCL backend documentation for Android and Windows ARM64 build instructions.Multi-Backend Builds
You can build with multiple backends simultaneously:Dynamic Backend Loading
Build backends as dynamic libraries for portability:HTTPS/TLS Support
For HTTPS features, install OpenSSL development libraries:If not installed, llama.cpp will build and run without SSL support.

