Skip to main content

Module device

Module device 

Source
Expand description

Where a compiled expression runs.

Placement is deliberately not part of binding. A kernel bound to data is the same kernel wherever it executes; a Device says which processor executes it, and the CPU is one of the answers. Program::run_on takes the device explicitly, and everything a device cannot do falls back to the CPU path with a reason a caller can read.

What runs on a GPU this phase is the fused elementwise kernel and nothing else. crate::fuse already compiles a chain of scalar verbs into a postfix program over blocks, with an optional reduction folded in — that is a kernel description, and codegen turns it into WGSL at run time. Anything outside a fused node, and any fused node the generator declines, runs where it always ran.

§Precision

libjay computes floats in f64. WGSL can express f64, but almost no adapter implements it: Metal has no double at all, and on Vulkan it is a feature (SHADER_F64) that many drivers leave off. A device that cannot run f64 therefore declines by default rather than quietly computing in f32 — losing precision is not a performance decision libjay may take on the caller’s behalf. Precision::F32 is the caller saying, in so many words, that they want it.

§Residency

Device::upload returns an array that carries its own location: the buffer it hands back keeps the device allocation alive inside its owner handle, so passing it to a later run uploads nothing. The array is an ordinary Array otherwise, which is what lets a fallback to the CPU read it without asking anyone.

Structs§

Device
Where a program runs.
DeviceError
A device operation that could not be carried out. These are host-side failures — no adapter, an allocation refused, a shader the driver would not compile — not language errors, and they never reach a program’s diagnostics: the caller sees them from Device::upload, and a run turns them into a fallback to the CPU.
DeviceInfo
One adapter, as the machine reports it.

Enums§

Placement
Where a fused node’s arithmetic happened.
Precision
The type a device kernel computes in.
Refusal
Why a fused node ran on the CPU although a device was asked for.

Constants§

MIN_ELEMS
Least elements worth a dispatch.

Functions§

available
Every adapter this machine offers, in the order the backend ranks them. Empty on a machine with no GPU, which is not an error.