docs / GPU Programming / API Reference

API reference

Accelerable

The capability trait that gates device residency. The compiler dispatches on the trait, never on a type name, so adding a new GPU-eligible container is an .mi edit, not a compiler change. User structs opt in with struct Point implements Accelerable.

public trait Accelerable
    fn byte_size() int
    fn binding_kind() AcceleratorBindingKind   // Storage | Uniform | PushConstant

gpu let / gpu var

Declare a device-resident binding. gpu let is immutable, gpu var is mutable. The initializer is an array literal, a sized constructor (Array<f32, N>()), or another gpu-resident binding (a move — the device handle transfers). Upload is deferred to the first kernel that captures the binding. The buffer persists across launches and is freed when the binding leaves scope.

forall / gpu forall

Launch a kernel over an index range (1D, 2D, or 3D). Bare forall routes by captured residency. gpu forall forces the device. Bounds may be literals, consts, or runtime values, including a runtime start. The body may capture device buffers and host scalars, index buffers, call scalar functions, and use arithmetic, if, and while.

gpu fn + .launch(grid, block)

A named kernel with explicit dispatch. Parameters are device buffers (gpu-resident at the launch site. out = writable) and scalars. shared arrays declare workgroup memory. Launch with kernel_name(args).launch(Dim3(gx, gy, gz), Dim3(bx, by, bz)). The block shape must be a compile-time literal and consistent across all launches of the same kernel.

kernel context

thread_idx, block_idx, block_dim, grid_dim, global_idx (each .x/.y/.z), barrier(), and warp.size / warp.lane_id / warp.shuffle_down(v, n). All available today. See The kernel Context.

Atomics — system.gpu.atomic

Atomic<i32> / Atomic<u32> buffer elements with atomic_add / sub / max / min / and / or / xor / exchange / compare_exchange(buf, index, …). Kernel-only. Plain-buffer or host-context use is rejected.

Vectors — system.gpu.vector

Vec2<T> / Vec3<T> / Vec4<T> with component fields and the builtins dot, length, normalize, cross (Vec3-only), reflect, mix, plus scalar broadcast. Inline std430 storage in arrays.

system.math on the device

abs, min, max, pow, sqrt, floor, ceil, round, sin, cos, tan, tanh, atan2, log, exp, step, clamp, mix — all usable inside kernels, width-preserving on f32.

Telemetry

gpu_reset_telemetry(), then gpu_uploads() / gpu_launches() / gpu_readbacks() / gpu_fences() return cumulative counts — the executable form of the cost model.