pub struct FallbackContext { /* private fields */ }Expand description
A GpuContext wrapper that carries a FallbackConfig and provides
fallback-aware operation dispatch.
Before invoking the GPU closure, FallbackContext checks the device-lost
flag. If the device is already known to be lost, it routes directly to the
CPU closure without attempting any GPU work.
§Example
use oxigdal_gpu::{GpuContext, GpuError};
use oxigdal_gpu::cpu_fallback::{FallbackConfig, FallbackContext, ExecutionPath};
let gpu = GpuContext::new().await?;
let fb = FallbackContext::with_default_config(gpu);
let result = fb.execute(
|| Ok::<u32, GpuError>(1_u32),
|| 2_u32,
)?;
assert_eq!(result.path, ExecutionPath::Gpu);Implementations§
Source§impl FallbackContext
impl FallbackContext
Sourcepub fn new(ctx: GpuContext, config: FallbackConfig) -> Self
pub fn new(ctx: GpuContext, config: FallbackConfig) -> Self
Create a new FallbackContext with the supplied configuration.
Sourcepub fn with_default_config(ctx: GpuContext) -> Self
pub fn with_default_config(ctx: GpuContext) -> Self
Create a FallbackContext with the default FallbackConfig.
Sourcepub fn gpu_context(&self) -> &GpuContext
pub fn gpu_context(&self) -> &GpuContext
Return a reference to the underlying GpuContext.
Sourcepub fn fallback_config(&self) -> &FallbackConfig
pub fn fallback_config(&self) -> &FallbackConfig
Return a reference to the active FallbackConfig.
Sourcepub fn is_device_lost(&self) -> bool
pub fn is_device_lost(&self) -> bool
Return true if the GPU device has been lost.
Sourcepub fn execute<T, GpuFn, CpuFn>(
&self,
gpu_op: GpuFn,
cpu_op: CpuFn,
) -> GpuResult<FallbackResult<T>>
pub fn execute<T, GpuFn, CpuFn>( &self, gpu_op: GpuFn, cpu_op: CpuFn, ) -> GpuResult<FallbackResult<T>>
Execute gpu_op with automatic CPU fallback per the configured policy.
If the device-lost flag is already set, the GPU closure is skipped
entirely and cpu_op is called directly (provided fallback is enabled).
Otherwise the behaviour mirrors execute_with_fallback.