The Metal backend runs tensor operations on Apple GPUs using Metal compute shaders. It is the recommended backend for macOS and provides the best performance on Apple Silicon (M-series) chips as well as AMD GPUs on Intel Macs.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ggml-org/ggml/llms.txt
Use this file to discover all available pages before exploring further.
Requirements
- macOS 13.0 (Ventura) or later
- Apple Silicon (M1/M2/M3/M4) or AMD GPU on an Intel Mac
- Xcode Command Line Tools
Build
On macOS, Metal is detected automatically and
DGGML_METAL=ON may already be the default in upstream build configurations. Check your CMakeCache.txt to confirm.| Option | Default | Description |
|---|---|---|
GGML_METAL=ON | OFF (non-Apple) | Enable the Metal backend |
GGML_METAL_EMBED_LIBRARY=ON | OFF | Embed the Metal shader library into the binary |
GGML_METAL_SHADER_DEBUG=ON | OFF | Compile shaders with debug info |
Initialization
Checking GPU family support
Metal devices are organised into feature families. You can query whether the device supports a specific family before using features that depend on it:Abort callback
Register a callback to cancel a Metal compute pass early:GPU capture
To capture a Metal compute pass with Xcode Instruments, call this before executing the graph you want to capture:Using Metal with the scheduler
Metal works withggml_backend_sched_t the same way any other backend does. Add a CPU backend as a fallback for operations not yet implemented in Metal:
API summary
| Function | Description |
|---|---|
ggml_backend_metal_init() | Create a Metal backend instance |
ggml_backend_is_metal(backend) | Check whether a backend is the Metal backend |
ggml_backend_metal_supports_family(backend, family) | Query GPU feature family support |
ggml_backend_metal_set_abort_callback(backend, cb, data) | Register an abort callback |
ggml_backend_metal_capture_next_compute(backend) | Capture the next compute pass for Xcode profiling |
ggml_backend_metal_reg() | Return the Metal backend registry entry |
