pub enum ComputeBackend {
Serial,
CpuMulti,
Gpu,
}Expand description
Which execution backend a numerical kernel should use.
§Variants and what they cost
Serial— one thread, scalar. Always available. The deterministic trusted reference; bit-for-bit reproducible run to run.CpuMulti—rayonacross CPU cores. Requires theparallelfeature. Pays thread-pool overhead, so it loses on small problems; seeCPU_MULTI_MIN_WORK_ITEMS. Reduction order is not generally reproducible unless a kernel says otherwise.Gpu—wgpucompute. Requires thegpufeature, a non-Android target, and an actual adapter at run time. Pays a host-device transfer per dispatch, so it needs a much larger problem to win; seeGPU_MIN_WORK_ITEMS. WGSL has nof64, so a GPU kernel that computes inf32will NOT match the serialf64path to full precision — each kernel must document its own measured deviation.
§Choosing one
Prefer select_backend over hand-picking. If you do name a backend,
route it through resolve so an unavailable choice
degrades instead of failing.
§Units
Dimensionless — this is a mode selector, not a quantity.
Variants§
Serial
Single-threaded scalar execution — always present, always the oracle.
CpuMulti
Multi-threaded CPU execution via rayon (parallel feature).
Gpu
GPU compute via wgpu (gpu feature, non-Android, adapter present).
Implementations§
Source§impl ComputeBackend
impl ComputeBackend
Sourcepub fn is_available(self) -> bool
pub fn is_available(self) -> bool
Whether this backend can actually run in this build, on this target, right now.
Serial— alwaystrue.CpuMulti—truewhen theparallelfeature is on. Compile-time only; rayon needs no run-time probe.Gpu—trueonly when thegpufeature is on, the target is not Android, and a GPU adapter was found bygpu_adapter_present. This one genuinely queries the machine.
Sourcepub fn resolve(self) -> Self
pub fn resolve(self) -> Self
Degrade this backend to the best one that is actually available, without erroring.
The order is Gpu -> CpuMulti -> Serial: a requested GPU with no
adapter (or no gpu feature) tries multi-CPU, and failing that runs
serially. Serial is always reachable, so this never
fails and never panics.
This is the “graceful absence of a GPU” contract: a missing adapter is a normal outcome on a headless server, in CI, on Android, or on a laptop with no discrete GPU — not an error condition.