docs / GPU Programming / Scalar Widths & f16

Scalar widths & f16

Kernels support i32, u32, f32, and f16 natively on every adapter. Half precision works end-to-end on the device:

gpu let a = Array<f16, 4>()
gpu var dst = Array<f16, 4>()
forall i in 0..4
    dst[i] = a[i] * 2.0        // float literals narrow to f16 automatically

64-bit scalars (int/i64, u64, f64) are gated on device features: an adapter that supports them runs them natively. One that doesn't refuses the kernel before dispatch with a clear message — never a silent truncation. Two guardrails back this up at compile time: an i64 value that provably exceeds the 32-bit range cannot be uploaded into a narrow buffer, and float→int casts saturate identically on host and device.

system.math works inside kernels: abs, min, max, pow, sqrt, floor, ceil, round, sin, cos, tan, tanh, atan2, log, exp, step, clamp, mix. Casts (x as f32, f as int) convert between widths explicitly, and math-intrinsic results keep the width of their f32 arguments — no accidental promotion to f64 inside a kernel.