metalworking
GitHub (opens in a new tab)
/glossary/metal/mps

MPS: Metal Performance Shaders

MPS is Apple's library of pre-built GPU kernels (matmul, convolution, image ops): the closest thing Metal has to cuBLAS/cuDNN, and the baseline your custom kernel has to beat.

CUDA equivalent: cuBLAS/cuDNN in role, not in stature. On NVIDIA, beating cuBLAS at dense GEMM is a research result; the library embodies decades of tuning plus hardware co-design. MPS is good, but the ML ecosystem on Apple Silicon has repeatedly matched or beaten it with open kernels:

Why beatable: classic MPS kernels are general and opaque. Each call opens, fills and ends its own compute encoder (so you must end yours before calling it and start a new one after, and an MPS call between two custom kernels always costs an encoder boundary), with no function-constant specialization for your shapes and no fusion with your surrounding ops. Quantized paths do exist: since macOS 15, MPSNDArrayQuantizedMatrixMultiplication and MPSGraph's dequantize cover int4, int8 and lookup-table weights, and macOS 27 adds MX and fp4 formats. MPSGraph, the graph layer above MPS, compiles a whole graph into an MPSGraphExecutable, fuses inside it, targets the Neural Engine as well as the GPU, and has a scaledDotProductAttention op (macOS 15; causal masks and attention sinks in macOS 27) plus a TF32 switch (allowConvertingOperandsFromFP32ToFP19, macOS 26). Even so, none of these use the LLM engines' own packed layouts, and a custom kernel still owns its tiling and epilogue. The places frameworks still lean on MPS are where its coverage is genuinely hard to replicate (convolution variants, some reductions, small-matrix cases where AMX-backed CPU paths and MPS-tuned dispatch beat naive GPU kernels).

For the kernel reader, MPS's main role is the benchmark floor: MPSMatrixMultiplication takes three kinds of object (an MPSMatrixDescriptor per operand, an MPSMatrix wrapping each operand's buffer, row-major, and the kernel itself, computing C = alpha op(A) op(B) + beta C) and gives honest GPU-time numbers via command-buffer timestamps; the m5-gemm harness (opens in a new tab) is a compact PyObjC example. If your custom kernel doesn't beat MPS at your shapes, ship MPS. That's the three questions working as intended.