Apple MPS Backend ("mps")
macOS Apple Silicon GPU backend built on Apple's system Metal Performance Shaders Graph (MPSGraph) framework.
Importing
- Included by default in
backends/default? Yes — automatically included on macOS (darwin, with CGo enabled) when importing_ "github.com/gomlx/gomlx/backends/default"(exclude at build time with--tags=nomps). - Standalone blank import (links only the Apple MPS backend):
import _ "github.com/gomlx/go-darwinml/compute/mps"
Overview
The "mps" backend (github.com/gomlx/go-darwinml/compute/mps), part of the github.com/gomlx/go-darwinml repository alongside the "mlx" backend, executes GoMLX computation graphs on Apple Silicon GPUs using macOS’s built-in Metal and Metal Performance Shaders Graph (MPSGraph) frameworks—requiring no external third-party libraries.
- Selection & Configuration Options: Set
GOMLX_BACKEND=mpsor callcompute.NewWithConfig("mps")(no additional configuration options). - Environment Variables: None specific to
"mps"(note: when benchmarking against the"go"backend on Apple M4/M5/M6, AppleSMEin the"go"backend is controlled byGOMLX_GO_SIMD_SME=0).
Architecture & Features
- Zero-Copy Unified Memory Shared Buffers: Allocates tensors directly as Metal
MTLBuffers (MTLResourceStorageModeShared), allowing CPU and GPU to read and write the same physical memory pages without staging copies, with automatic resource cleanup via Go’sruntime.AddCleanup. - Ping-Pong Buffer Pooling: Works around
MPSGraph’s lack of in-place input/output buffer aliasing by pooling donated inputMTLBuffers across consecutive executions (with cross-executable stealing to avoid memory duplication on multi-task or multi-shape models). - Fused Operations: Native support for
FusedSoftmax,FusedGelu,FusedLayerNorm,FusedDense,FusedScaledDotProductAttention(SDPA),FusedAttentionQKVProjection, andFusedActivation.
Limitations
- Requires macOS (
darwin) with CGo enabled and an Apple Silicon GPU. - Unsupported DTypes: Does not support
Float64,Complex64,Complex128, or sub-byte integer types (a hardware/Metal limitation on Apple GPUs). - Unsupported Operations: Complex & FFT operations (
Complex,Real,Imag,Conj,FFT), bit-level/bitwise-reduction operations (Bitcast,BitCount,Clz,ReduceBitwiseAnd/Or/Xor,ReduceLogicalXor),SelectAndScatterSum/Min, dynamic-shape operations, multi-device collective operations,OptimizationBarrier/SchedulingBarrier, and quantized fused ops (FusedQuantizedDense,QuantizedEmbeddingLookup). Operations with GoMLX decompositions (likeCumSumandCumMax) fall back automatically.
Apple Silicon Performance Note
"go" vs "mps" / "mlx" on Apple Silicon: With the addition of ARM64 NEON and Apple SME (FEAT_SME) SIMD assembly microkernels and the 3-level parallel scheduler in the "go" backend, the "go" backend is often faster than "mps" and "mlx" on Apple Silicon Macs—particularly on small-to-medium models or workloads where Metal command-buffer dispatch and graph compilation overhead dominate (you can test "go" with or without SME via GOMLX_GO_SIMD_SME=0). We recommend benchmarking GOMLX_BACKEND=go (with GOEXPERIMENT=simd), GOMLX_BACKEND=mlx, and GOMLX_BACKEND=mps for your specific model.Last updated December 1, 2026