Skip to main content
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.

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.
Useful CMake options:

Initialization

Alternatively, use the generic backend selector:

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:
Refer to Apple’s Metal Feature Set Tables for the capabilities of each family.

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:
GPU captures require running the process from Xcode or with Metal capture enabled in the scheme. Use this during development to profile shader performance.

Using Metal with the scheduler

Metal works with ggml_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