Environment:Ggml org Llama cpp Metal GPU Environment
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, GPU_Acceleration |
| Last Updated | 2026-02-14 22:00 GMT |
Overview
Apple Metal GPU acceleration environment for macOS, iOS, tvOS, and visionOS requiring the Metal framework and Apple Silicon or discrete AMD GPU.
Description
This environment enables GPU-accelerated inference on Apple platforms using the Metal compute shading API. Metal is the default and recommended backend for macOS builds. It automatically leverages the unified memory architecture of Apple Silicon chips (M1/M2/M3/M4), allowing models to use both CPU and GPU memory seamlessly. Metal shaders are embedded in the library at build time by default.
Usage
Use this environment for GPU-accelerated inference on Apple hardware. Metal is enabled by default when building on macOS (GGML_METAL=ON). No additional flags are needed for standard builds. Required for all inference workflows when running on Apple Silicon.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | macOS, iOS, tvOS, visionOS | Metal API required |
| Hardware | Apple Silicon (M1+) or AMD GPU | Apple Silicon uses unified memory |
| Frameworks | Foundation, Metal, MetalKit | Auto-linked by CMake |
| Disk | ~200 MB | For compiled Metal shaders and binaries |
Dependencies
System Packages
- Xcode Command Line Tools (provides Metal compiler)
cmake>= 3.14- macOS SDK with Metal framework support
Credentials
No credentials are required.
Quick Install
# Metal is auto-enabled on macOS; standard build is sufficient
cmake -B build
cmake --build build --config Release -j $(sysctl -n hw.logicalcpu)
# Explicit Metal flags (for custom configurations)
cmake -B build -DGGML_METAL=ON -DGGML_METAL_EMBED_LIBRARY=ON
cmake --build build --config Release -j $(sysctl -n hw.logicalcpu)
Code Evidence
Metal auto-detection from ggml/CMakeLists.txt:
if (APPLE)
option(GGML_METAL "ggml: use Metal" ON)
else()
option(GGML_METAL "ggml: use Metal" OFF)
endif()
Framework linking from ggml/src/ggml-metal/CMakeLists.txt:
find_library(FOUNDATION_LIBRARY Foundation REQUIRED)
find_library(METAL_LIBRARY Metal REQUIRED)
find_library(METALKIT_LIBRARY MetalKit REQUIRED)
target_link_libraries(ggml-metal PRIVATE
${FOUNDATION_LIBRARY} ${METAL_LIBRARY} ${METALKIT_LIBRARY})
Metal build options from ggml/src/ggml-metal/CMakeLists.txt:
option(GGML_METAL_NDEBUG "ggml: disable Metal debugging" OFF)
option(GGML_METAL_SHADER_DEBUG "ggml: compile with -fno-fast-math" OFF)
option(GGML_METAL_EMBED_LIBRARY "ggml: embed Metal library in binary" ${GGML_METAL})
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
Could NOT find Metal |
Not building on macOS or Xcode tools missing | Install Xcode Command Line Tools: xcode-select --install
|
Metal library not found |
Embedded Metal library build failed | Rebuild with -DGGML_METAL_EMBED_LIBRARY=ON
|
Unsupported OS for Metal |
Trying to enable Metal on Linux/Windows | Metal is Apple-only; use CUDA or Vulkan on other platforms |
Compatibility Notes
- Apple Silicon (M1/M2/M3/M4): Unified memory allows models to exceed GPU VRAM since CPU and GPU share the same memory pool.
- Accelerate Framework: Automatically linked on macOS for BLAS operations (
GGML_ACCELERATE=ONby default). - Shader Debugging: Enable
GGML_METAL_SHADER_DEBUGto compile Metal shaders with-fno-fast-mathfor debugging numerical issues. - iOS/tvOS/visionOS: Supported via XCFramework builds. Use
build-xcframework.shscript.