Core types
ggml_backend_t
ggml_backend_t is an opaque handle to an initialized backend instance. It holds an execution stream and is the primary object you pass to graph compute calls.
ggml_backend_buffer_t and ggml_backend_buffer_type_t
Buffers hold the raw memory for tensors. A buffer type (ggml_backend_buffer_type_t) is a descriptor that tells ggml where and how to allocate memory. You get one from a backend and use it to allocate buffers:
ggml_backend_dev_t and device discovery
Every registered backend exposes one or moreggml_backend_dev_t objects. You can enumerate all available devices at runtime:
ggml_backend_dev_type:
Convenience initializers select a backend without enumerating devices manually:
The backend scheduler
ggml_backend_sched_t lets you run a single computation graph across multiple backends simultaneously. The scheduler:
- Assigns each graph node to the backend that best supports the operation
- Copies tensors between backends automatically when needed
- Allocates compute buffers on each backend
- Prioritises backends with a lower index in the array you supply
GGML_BACKEND_BUFFER_USAGE_WEIGHTS are preferentially assigned to whichever backend owns those weights.
1
Reserve (optional)
Pass a representative max-size graph to pre-allocate buffers. This avoids allocation at compute time.
2
Reset
Clear allocations from the previous graph before computing a new one.
3
Allocate
Explicitly allocate the graph (skipped automatically on first compute).
4
Set inputs
Copy data into the allocated input tensors.
5
Compute
Execute the graph. Returns a
ggml_status value.6
Read outputs
Copy results back to host memory.
Complete example
The following is drawn directly fromexamples/simple/simple-backend.cpp and shows the full lifecycle — backend selection, graph construction, scheduling, and result retrieval.
Available backends
CPU backend
SIMD-optimised execution on x86 and ARM with configurable thread pools.
CUDA backend
NVIDIA GPU acceleration with multi-GPU and split-tensor support.
Metal backend
Native Apple GPU compute for macOS and Apple Silicon.
Vulkan backend
Cross-vendor GPU support for Linux, Windows, and Android.
RPC backend
Distribute computation to remote machines over the network.
