docs / GPU Programming / The Residency Surface

The residency surface

A small set of forms covers the whole surface:

FormMeaningCost
gpu let g = …Immutable device bufferUpload (deferred to first capture)
gpu var g = …Mutable device bufferUpload (deferred to first capture)
forall i in 0..nLaunch a kernel over indices 0..nKernel launch (or a CPU loop — see below)
let h = gCopy a device buffer back to the hostFence + readback
gpu let b = gMove a device buffer to a new bindingFree — the device handle transfers, no copy
g.slice(a..b)Partial readback of [a, b)Fence + readback
g.reduce(init, op)On-device tree reduction to a scalarKernel launch

What may be device-resident

A type can be bound with gpu only if it implements the Accelerable capability trait. The standard library ships impls for Array<T, N> and List<T> over the accelerable scalars — int, i32, i64, u32, u64, f16, f32, f64, bool — plus the vector types, Tensor, and user structs declared implements Accelerable. String, Map, Set, and function values are not accelerable. Binding one with gpu is a compile error that names the missing trait.

No silent promotion. A host Array never becomes device-resident because a kernel wants it. You write gpu let at the binding, and the upload is visible at that line.