/glossary
The glossary
64 entries in six sections. Every entry stands alone: it opens with a definition, gives the CUDA equivalent where one exists, and links to what it assumes. Read it like a reference, or read the book for the same material as a track.
The Machine
- NVIDIA to MetalEvery NVIDIA and CUDA term next to its Apple counterpart, on one page: the chip, the kernel code, the toolchain, and the libraries.
- GPU Core SMThe GPU core is the M-series GPU's unit of compute: it owns a register file, threadgroup memory, and ALU pipes, and schedules simdgroups onto them.
- Simdgroup warpA simdgroup is 32 threads executing in lockstep on one GPU core: Metal's unit of SIMD execution and the level at which shuffles, reductions, and matrix operations happen.
- RegistersThe register file, ~208 KB per GPU core, is the largest programmable memory on the core and the real budget every fast Metal kernel is written against.
- Threadgroup Memory smemThreadgroup memory is the on-core scratch space shared by one threadgroup , capped at 32 KB per threadgroup.
- Unified MemoryApple Silicon has one physical memory pool shared by CPU and GPU.
- OccupancyOccupancy is how many simdgroups are resident on a core at once: the pool of independent work the scheduler hides latency with.
- F16 fp16On Apple GPUs, 16-bit floats are faster than 32-bit for reasons that have little to do with peak throughput: shorter stalls and half the register pressure.
- Special PathsTwo hardware asymmetries that reshape kernels on this platform: a fast `exp2` path, and float atomics that exist in the language but are slow.
- AMXAMX is Apple's undocumented CPU matrix coprocessor.
- Neural Accelerators Tensor CoreThe M5 generation adds a dedicated matrix unit to every GPU core: the neural accelerators , reached through Metal 4 tensor ops rather than `simdgroup_matrix`.
Metal, the Stack
- Metal, the API CUDAMetal is Apple's single graphics-and-compute API: the layer that owns devices, queues, memory, and kernel execution.
- MSL CUDA C++MSL is the C++ dialect Metal kernels are written in: C++17 from Metal 4 on with GPU address spaces, kernel attributes, and a SIMD standard library, compiled through AIR to GPU binary.
- Dispatch Geometry gridA Metal dispatch launches a grid of threadgroups of threads: CUDA's grid/block/thread hierarchy under different names, with two API-level traps for the CUDA-trained.
- Compilation Pipeline PTXMSL source compiles to AIR , AIR ships in a metallib, and the GPU binary is, by default, generated when you build a pipeline state on the user's machine.
- Function ConstantsFunction constants are values bound when you ask a library for a specialized function, which the final compile at pipeline creation treats as literals: Metal's mechanism for specializing one shipped kernel into many optimized variants.
- Command Buffers streamGPU work in Metal is encoded into command buffers: batches of dispatches built CPU-side, committed to a queue, and executed asynchronously.
- SynchronizationInside a kernel, Metal has the same two sync levels as CUDA and one inverted cost that changes how you design: barriers are nearly free.
- simdgroup_matrix wmma`simdgroup_matrix
` is Metal's matrix-multiply primitive: an 8×8 matrix held collectively in one simdgroup's registers, with a single-call multiply-accumulate. - simdgroup_async_copy cp.async`simdgroup_async_copy` was Apple's undocumented DMA intrinsic for asynchronous tile copies from device to threadgroup memory, and it no longer compiles.
- MTLTensor and MPP TMAMetal 4 adds tensors as a first-class type plus Metal Performance Primitives , a shader-side library of matrix operations.
- MPS cuBLASMPS is Apple's library of pre-built GPU kernels : the closest thing Metal has to cuBLAS/cuDNN, and the baseline your custom kernel has to beat.
- Profiling NsightThe honest page: Metal has no Nsight Compute, and the gap shapes how performance work is done on this platform.
- Disassembly SASSWhen arithmetic says a kernel's performance is impossible, the last resort is reading what the compiler actually emitted.
MLX
- MLX, an OverviewMLX is Apple's open-source array framework for Apple Silicon: a NumPy-shaped API with autograd, built natively on unified memory, whose GPU backend is the steel kernel library this glossary reads.
- Lazy EvaluationMLX operations don't compute; they record.
- How an Op Becomes a KernelBetween `mx.matmul` and a `simdgroup_matrix` instruction sits one C++ hop: the primitive's `eval_gpu`, which picks a kernel variant, picks tile sizes, binds function constants, and encodes the dispatch.
- Steel CUTLASSSteel is MLX's kernel library, the CUTLASS of Apple Silicon: GEMM and attention decomposed into composable C++ templates that one wiring kernel assembles per shape.
- mx.fast`mx.fast` is MLX's drawer of fused operations plus the escape hatch for writing your own: `mx.fast.metal_kernel`.
- QuantizationMLX's workhorse quantization is group-wise affine , and a dedicated kernel family multiplies against them without ever materializing the dequantized matrix.
- mx.compile`mx.compile` traces a function's lazy graph once, fuses runs of elementwise operations into generated Metal kernels, and replays the optimized graph on subsequent calls.
- Distributed NCCL`mx.distributed` runs one model across several Macs.
Techniques
- Arithmetic IntensityArithmetic intensity, FLOPs per byte of memory traffic, is the number that decides whether a kernel is limited by the ALUs or by memory bandwidth.
- RooflineA roofline is the two-ceiling model that turns a kernel's measured time into a verdict: how far from the physical limit, and which limit.
- TilingTiling is the reuse pyramid: copy a block of the problem one level closer to the ALUs, do all the math it can support, then let it go.
- Cooperative LoadA cooperative load is the whole threadgroup jointly copying a tile from device memory to threadgroup memory.
- Register BlockingRegister blocking keeps each simdgroup's patch of the output resident in registers for the kernel's entire lifetime: accumulate across every K step, write to memory exactly once.
- Double BufferingDouble buffering allocates two staging buffers so the K-loop can load tile `l+1` while computing on tile `l`: buying overlap with threadgroup memory, and on this platform, buying it through ILP rather than DMA.
- Fusion and EpiloguesFusion means computing a chain of operations in one kernel so intermediates never touch memory.
- Online SoftmaxOnline softmax computes a numerically-safe softmax in one streaming pass, maintaining a running max, running sum, and running output that are corrected as new tiles arrive.
- Flash AttentionFlash attention computes `softmax·V` without ever materializing the L×L score matrix: streaming K and V in tiles, holding each tile's scores in registers, folding contributions into a running output via online softmax.
- The KV CacheThe KV cache stores every past token's key and value vectors so attention never recomputes them.
- Decode vs PrefillLLM inference is two different workloads wearing one API: prefill processes the prompt as big matmuls , decode generates one token at a time as dot products against the whole KV cache .
Kernels
- The Tiled GEMM`sync_copy.metal` from yaroslavvb/m5-gemm : ~140 lines of MSL that beat MPS at fp32 matmul, 13.5 vs 11.7 TFLOPS at 4096² on an M5 Max.
- The Double-Buffered GEMM`sync_copy_db.metal` is the tiled GEMM with double buffering added, and the cleanest measured demonstration in this glossary that there is no single fastest kernel.
- The Async-Copy Ghost`async_copy.metal` from 0xekez/metal-matmul is the original of the GEMM lineage, built on `simdgroup_async_copy`, kept in the glossary as the worked example of what DMA-staged tiling looked like and why it died.
- Steel's BlockLoader`BlockLoader` is the cooperative load grown up: the hand-derived constants of the m5-gemm loader recomputed at compile time from template parameters, for every shape MLX serves.
- Steel's BlockMMA`BlockMMA` is register blocking as a reusable component: each simdgroup's grid of 8×8 fragments, the K-march that feeds them, and the epilogue hook. Everything between "tiles are staged" and "results are stored.".
- The Fused GEMM Kernel`steel_gemm_fused.h` is what remains of a GEMM once BlockLoader, BlockMMA, and epilogues are factored out: ~350 lines of wiring, most of which is function-constant dispatch.
- Steel Attention`steel_attention.h` is the complete flash attention forward built from the steel vocabulary: the most readable production FA on the platform, and the payoff for knowing online softmax before you arrive.
- metal-flash-attentionphilipturner/metal-flash-attention : 83% ALU utilization on M1 Max, and a structural bet visible in one fact. There are no `.metal` files in the repo.
- llama.cpp AttentionOne 11,603-line shader, `ggml-metal.metal`, serves every model architecture and quantization format llama.cpp runs on Apple hardware.
- The NAX GEMMThe fourth kernel school: GEMM through Metal 4 tensor ops on the M5 neural accelerators.
War Stories
- The Three QuestionsBefore writing any custom kernel on this platform, ask three questions in order.
- Sparse-V+22.8% decode at 32K context , perplexity unchanged, from three lines, after fourteen dequant-level optimizations had topped out at +38%.
- The FailuresThe most instructive documents on the platform are the published negative results.
- Cheap TricksThree measured, zero-code or near-zero-code wins that belong in every Apple Silicon practitioner's kit, plus the reminder that they carry the platform's signature risk.
Engines and Servers
- oMLX vLLMoMLX is an open-source LLM inference server for Apple Silicon built on MLX 0.32.3 and mlx-lm. It is the largest public body of Metal optimization work aimed at one platform: about 30,000 lines of runtime patches, 35,000 lines of native kernel code, and a scheduler that gets most of its speed without new kernels at all.
- exo NCCL clusterexo joins several Macs into one inference cluster and places a model across them .
- vllm-mlx vLLMvllm-mlx is an OpenAI- and Anthropic-compatible inference server for Apple Silicon written entirely in Python on mlx-lm, mlx-vlm and mlx-audio .
- vllm-metal vLLM pluginvllm-metal is the community hardware plugin that runs vLLM, the standard datacenter inference server, on Apple Silicon . vLLM supplies the API server, scheduler and paged block manager; mlx-lm supplies the token-wise model layers; vllm-metal owns "the request-aware attention path" : a 2,820-line nanobind extension and 14 Metal files, 5,715 lines, that read vLLM's paged KV pool directly.
- Magnitude autotunerMagnitude is an open-source inference engine for coding agents that compiles and tunes its kernels on the user's machine before a model runs .
- Cider INT8 GEMMCider is a small MLX add-on that does two things: online activation quantization, W8A8 and W4A8, running on the M5 INT8 tensor-op datapath as custom MLX primitives, and a decode-only replacement for `mx.fast.scaled_dot_product_attention`.
- Rapid-MLX spec decodeRapid-MLX is an OpenAI- and Anthropic-compatible inference server for Apple Silicon aimed at coding agents , written in Python on stock MLX and mlx-lm, about 371,600 lines, with one `.metal` file and about twenty modules of inline `mx.fast.metal_kernel` source.