Trait OracleContext
pub trait OracleContext {
// Required methods
fn allocate_and_write(
&mut self,
data: &[u8],
binding: u32,
group: u32,
usage: BindingUsage,
) -> Result<BufferView, ForgeError>;
fn allocate_transient(
&mut self,
size_bytes: usize,
binding: u32,
group: u32,
usage: BindingUsage,
) -> Result<BufferView, ForgeError>;
fn read_buffer_f32(&self, view: &BufferView) -> Result<Vec<f32>, ForgeError>;
fn clear_transient_allocations(&mut self);
fn adapter(&self) -> &AdapterIdentity;
fn constraints(&self) -> &AdapterConstraints;
fn timestamp_supported(&self) -> bool;
fn run_kernel(
&mut self,
kernel: &KernelSpec,
schedule: &Schedule,
buffers: &[BufferView],
element_count: usize,
warmups: usize,
samples: usize,
) -> Result<Vec<u64>, ForgeError>;
}Expand description
The hardware surface the differential oracle drives. Implemented by both the
wgpu (super::WgpuComputeContext) and the CUDA ([super::CudaComputeContext])
backends so each cross-backend kernel evaluator is written once, generically.
The allocator/read methods mirror the inherent methods both contexts already
have; Self::run_kernel is the one method that abstracts the backend-specific
kernel compile + warmup/sample dispatch loop, returning the per-sample timing
(nanoseconds).
Required Methods§
fn allocate_and_write(
&mut self,
data: &[u8],
binding: u32,
group: u32,
usage: BindingUsage,
) -> Result<BufferView, ForgeError>
fn allocate_and_write( &mut self, data: &[u8], binding: u32, group: u32, usage: BindingUsage, ) -> Result<BufferView, ForgeError>
Allocate a transient slab sub-range and upload data into it. usage
selects the backing slab on wgpu (read-only/uniform vs read-write); the
CUDA backend addresses one slab and ignores it.
fn allocate_transient(
&mut self,
size_bytes: usize,
binding: u32,
group: u32,
usage: BindingUsage,
) -> Result<BufferView, ForgeError>
fn allocate_transient( &mut self, size_bytes: usize, binding: u32, group: u32, usage: BindingUsage, ) -> Result<BufferView, ForgeError>
Allocate a transient (uninitialised) slab sub-range. usage is honoured by
the wgpu backend and ignored by CUDA, as for Self::allocate_and_write.
fn read_buffer_f32(&self, view: &BufferView) -> Result<Vec<f32>, ForgeError>
fn read_buffer_f32(&self, view: &BufferView) -> Result<Vec<f32>, ForgeError>
Read a device buffer back as f32s.
fn clear_transient_allocations(&mut self)
fn clear_transient_allocations(&mut self)
Release every transient allocation (resets the ring’s read head to the write head). Only valid once all device work on those ranges has completed.
fn adapter(&self) -> &AdapterIdentity
fn adapter(&self) -> &AdapterIdentity
The adapter identity (vendor/device/driver) backing this context.
fn constraints(&self) -> &AdapterConstraints
fn constraints(&self) -> &AdapterConstraints
The adapter’s intrinsic capability/limit constraints.
fn timestamp_supported(&self) -> bool
fn timestamp_supported(&self) -> bool
Whether GPU-timestamp timing is available (wgpu only; CUDA times on the
host wall clock, so this is always false there).
fn run_kernel(
&mut self,
kernel: &KernelSpec,
schedule: &Schedule,
buffers: &[BufferView],
element_count: usize,
warmups: usize,
samples: usize,
) -> Result<Vec<u64>, ForgeError>
fn run_kernel( &mut self, kernel: &KernelSpec, schedule: &Schedule, buffers: &[BufferView], element_count: usize, warmups: usize, samples: usize, ) -> Result<Vec<u64>, ForgeError>
Compile kernel for this backend (WGSL → super::WgpuPipeline for wgpu;
CUDA-C → [super::CudaPipeline] for cudarc), then dispatch it warmups times
(untimed) followed by samples timed dispatches over element_count
elements, returning the per-sample timing in nanoseconds.
This is the single method that hides the backend-specific compile + dispatch: the buffers (and their bindings/usages) are provided by the caller, identical across backends, so only the pipeline construction and the timing source differ.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".