Expand description
Automatic CPU fallback for GPU operations.
This module provides a generic fallback system that transparently routes GPU operations to CPU implementations when GPU errors such as device loss or backend unavailability are encountered.
§Design
The core abstraction is execute_with_fallback, a free function that
accepts a GPU closure and a CPU closure. When the GPU closure returns an
error whose kind matches the active FallbackConfig, the CPU closure is
invoked instead and its result is returned as if it had come from the GPU.
FallbackContext wraps a GpuContext together with a FallbackConfig
and additionally checks the device-lost flag before even attempting the
GPU closure, avoiding redundant error generation on a known-dead device.
§CPU primitive operations
The cpu sub-module contains pure-Rust implementations of common raster
element-wise operations used as CPU fallback kernels.
Modules§
- cpu
- Pure-Rust CPU implementations of common raster element-wise operations.
Structs§
- Fallback
Config - Configuration that controls when and how CPU fallback is activated.
- Fallback
Context - A
GpuContextwrapper that carries aFallbackConfigand provides fallback-aware operation dispatch. - Fallback
Result - The output of a fallback-aware operation, bundling the value with the execution path that produced it.
Enums§
- Execution
Path - Which execution path produced the result.
Functions§
- execute_
with_ fallback - Execute
gpu_opand, if it returns a fallback-triggering error, runcpu_opinstead. - execute_
with_ fallback_ timed - Like
execute_with_fallback, but additionally checks whether the GPU op takes longer thanconfig.timeout_msmilliseconds. If the timeout fires before the GPU closure returns,cpu_opis called andExecutionPath::Cpuis reported.