Skip to main content

Module cpu_fallback

Module cpu_fallback 

Source
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§

FallbackConfig
Configuration that controls when and how CPU fallback is activated.
FallbackContext
A GpuContext wrapper that carries a FallbackConfig and provides fallback-aware operation dispatch.
FallbackResult
The output of a fallback-aware operation, bundling the value with the execution path that produced it.

Enums§

ExecutionPath
Which execution path produced the result.

Functions§

execute_with_fallback
Execute gpu_op and, if it returns a fallback-triggering error, run cpu_op instead.
execute_with_fallback_timed
Like execute_with_fallback, but additionally checks whether the GPU op takes longer than config.timeout_ms milliseconds. If the timeout fires before the GPU closure returns, cpu_op is called and ExecutionPath::Cpu is reported.