Loading page

Verify your Apple silicon environment

Before compiling llama.cpp, confirm your macOS version, CPU architecture, performance-core count, and unified memory capacity.

Check the architecture, macOS release, chip model, core topology, and memory size:

    

        
        
uname -m
sw_vers
sysctl -n machdep.cpu.brand_string
sysctl hw.perflevel0.physicalcpu hw.perflevel1.physicalcpu hw.physicalcpu hw.memsize

    

Confirm that uname -m prints arm64. Note the value of hw.perflevel0.physicalcpu, which gives your performance-core count (for example, 8 on an Apple M4 Pro). Check that hw.memsize is at least 16 GB (17179869184 bytes or higher).

You can also check whether your Mac exposes Arm Scalable Matrix Extension (SME) and SME2 features:

    

        
        
sysctl -a 2>/dev/null | grep -E "hw.optional.arm.FEAT_SME|hw.optional.arm.FEAT_I8MM|hw.optional.arm.FEAT_DotProd"

    

The output is similar to:

    

        
        hw.optional.arm.FEAT_DotProd: 1
hw.optional.arm.FEAT_I8MM: 1
hw.optional.arm.FEAT_SME: 1
hw.optional.arm.FEAT_SME2: 1

        
    

Install build prerequisites

Confirm that Xcode Command Line Tools, CMake, and Git are installed:

    

        
        
xcode-select -p
clang --version
cmake --version
git --version

    

If any tool is missing, install Xcode Command Line Tools with xcode-select --install. Install CMake and Git with Homebrew using brew install cmake git. You can also download CMake from the CMake download page .

Note

You can install a prebuilt package with brew install llama.cpp, which includes Metal support. Building from source lets you enable Arm KleidiAI (-DGGML_CPU_KLEIDIAI=ON) for CPU-side prefill with SME on M4 and M5 Macs.

Clone and build llama.cpp

Create a dedicated project directory and clone the official llama.cpp repository:

    

        
        
mkdir -p ~/hermes-gemma4 && cd ~/hermes-gemma4
git clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp

    

Configure CMake to build the Metal GPU backend and an optimized Arm KleidiAI CPU backend in one binary set:

    

        
        
cmake -B build \
  -DCMAKE_BUILD_TYPE=Release \
  -DGGML_METAL=ON \
  -DGGML_METAL_EMBED_LIBRARY=ON \
  -DGGML_ACCELERATE=ON \
  -DGGML_CPU_KLEIDIAI=ON

    

Inspect the CMake configuration output to confirm that HAVE_SME - Success and Using KleidiAI optimized kernels if applicable appear. Check for Accelerate framework found and Metal framework found as well. On macOS arm64, CMake detects supported Arm extensions, including dot-product, i8mm, and SME when available.

The key CMake options control the following features on Apple silicon:

FlagPurpose
-DGGML_METAL=ONEnables the Metal backend for GPU offloading.
-DGGML_METAL_EMBED_LIBRARY=ONEmbeds the compiled Metal shaders in the binaries.
-DGGML_ACCELERATE=ONLinks the Apple Accelerate framework for CPU operations.
-DGGML_CPU_KLEIDIAI=ONEnables Arm KleidiAI microkernels for CPU inference.

Compile llama.cpp across all available cores:

    

        
        
cmake --build build --config Release -j $(sysctl -n hw.ncpu)

    

Validate the compiled binaries

Verify that llama-server and llama-bench built cleanly and detect your Metal GPU:

    

        
        
./build/bin/llama-server --version
./build/bin/llama-bench --list-devices

    

The output is similar to:

    

        
        version: 1.0.0-dev (build 1, commit 33aeb17)
built with AppleClang 21.0.0.21000401 for Darwin arm64
...
ggml_metal_device_init: GPU name:   MTL0 (Apple M4 Pro)
ggml_metal_device_init: GPU family: MTLGPUFamilyApple9  (1009)
ggml_metal_device_init: GPU family: MTLGPUFamilyMetal4  (5002)
ggml_metal_device_init: simdgroup reduction   = true
ggml_metal_device_init: simdgroup matrix mul. = true
ggml_metal_device_init: has unified memory    = true
...
Available devices:
  MTL0: Apple M4 Pro (18186 MiB, 18185 MiB free)
  BLAS: Accelerate (0 MiB, 0 MiB free)

        
    

Confirm that MTL0 lists your Apple silicon GPU and BLAS: Accelerate appears under Available devices:.

What you’ve accomplished and what’s next

You’ve verified your Apple silicon macOS environment, enabled Metal and Arm KleidiAI in CMake, and compiled llama.cpp from source.

Next, you’ll download Gemma 4 E4B from Hugging Face. You’ll benchmark Metal GPU versus CPU performance.