metalworking
GitHub (opens in a new tab)
/glossary/machine/f16

F16

On 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.

CUDA equivalent: none that matches cleanly. On NVIDIA you reach for fp16/bf16 to unlock tensor-core throughput, a peak-FLOPs argument. Here the argument is about latency and residency:

  • Dependent-instruction stalls are shorter in 16-bit. A back-to-back dependent multiply pays ~1.84 cycles with F32 registers vs ~1.56 with F16; at low occupancy the dependent-FMA gap blows out to ~11.3 vs ~3.9 cycles. Measured, not spec'd; source: metal-benchmarks, ALU Bottlenecks (opens in a new tab).
  • Half the register footprint, which on this machine means more resident simdgroups, better latency hiding, and more headroom before the spilling cliff.
  • Half the memory traffic, which on a bandwidth-bound machine is often the whole ballgame.

So "use F16 everywhere you can tolerate it" is the local wisdom even where the ALU throughput tables show F16 and F32 tied. The standard numerics discipline still applies, and every serious kernel in the case studies follows it: storage and traffic in 16-bit, accumulation in fp32. MLX's steel templates default AccumType = float regardless of data type.

Related precision facts:

  • bf16 is supported (Metal 3.1 and later) and behaves like F16 for storage, traffic and register pressure, with two language limits: the SIMD-group shuffle and reduction functions do not accept bfloat, so reductions convert to float first, and bfloat and half do not mix in one expression without an explicit cast.
  • fp8 was not real on M4-class hardware: reverse-engineering of Metal 4.1's tensor API (Rigel (opens in a new tab), tested on an M4 Max) found fp8 software-emulated at ~0.94× fp16 throughput, so it halved the bytes without any speedup. macOS 27's Metal (MSL 4.1) adds fp8, fp4 and 2-bit integer operands to matmul2d, with E8M0 block scales (WWDC26 330 (opens in a new tab)); Apple says TensorOps will use whatever hardware acceleration exists but has published no fp8 throughput for M5, so whether the neural accelerators run it natively is still to be measured.
  • Denormals and infinities are not guaranteed. The specification lets any float, half or bfloat operation flush denormals to zero, and under fast math, Metal's default, the handling of INF and NaN is undefined, so masking with -INFINITY or relying on tiny half values needs -fmetal-math-mode=relaxed (which honors INF and NaN) or explicit finite sentinels.
  • I16/U16 get the same stall advantage over 32-bit integers; index arithmetic in ushort is a standing micro-optimization in production kernels (you'll see ushort loop counters throughout the GEMM case studies).