Skip to main content
The CUDA backend offloads tensor operations to NVIDIA GPUs using CUDA kernels and cuBLAS. It also supports AMD GPUs via ROCm (HIP) and Moore Threads GPUs via MUSA, using the same API.

Requirements

  • NVIDIA GPU with CUDA Compute Capability 5.0 or later
  • CUDA Toolkit (nvcc, runtime libraries)
  • CMake 3.17+
When built with ROCm support (GGML_HIP=ON), the backend name becomes "ROCm" and cuBLAS is replaced by hipBLAS. The C API is identical.

Build

Useful CMake options:

Initialization

To select a device, you can enumerate available devices first:

Buffer types

The CUDA backend provides three buffer types:
Use the pinned host buffer type for tensors on the CPU side of a CPU/GPU pipeline. Pinned (page-locked) memory transfers to and from the GPU significantly faster than pageable memory.

Multi-GPU setup

To use more than one GPU, create a separate backend per device and pass them all to the scheduler:
For weight tensors spread across GPUs, allocate them into a split buffer:

Pinned host memory

For faster host-side memory, register existing host buffers with the CUDA driver:

API summary

GGML_CUDA_MAX_DEVICES is 16. You cannot create backends for more than 16 CUDA devices in a single process.