pub struct CudaComputeContext {
pub ctx: Arc<CudaContext>,
pub stream: Arc<CudaStream>,
pub prefetch_stream: Option<Arc<CudaStream>>,
pub module_cache: Mutex<HashMap<u64, (CudaFunction, Arc<CudaModule>, Arc<KernelSpec>)>>,
pub adapter: AdapterIdentity,
pub constraints: AdapterConstraints,
pub allocator: QualiaSlabAllocator,
pub slab: CudaSlice<u8>,
}Fields§
§ctx: Arc<CudaContext>§stream: Arc<CudaStream>§prefetch_stream: Option<Arc<CudaStream>>Secondary stream for overlapping H2D parameter writes with compute.
Lazily created on first write_view_prefetch call to avoid overhead
when double-buffering is not used.
module_cache: Mutex<HashMap<u64, (CudaFunction, Arc<CudaModule>, Arc<KernelSpec>)>>Cache of loaded CUDA functions keyed by (source_hash, entry_point).
Avoids redundant load_module JIT on every compile_pipe! call —
the PTX text is already cached in NVRTC_PTX_CACHE, but the driver
module load is a separate JIT step that was repeated per token.
adapter: AdapterIdentity§constraints: AdapterConstraints§allocator: QualiaSlabAllocator§slab: CudaSlice<u8>Implementations§
Source§impl CudaComputeContext
impl CudaComputeContext
pub fn new(capacity_bytes: usize) -> Result<Self, ForgeError>
Sourcepub fn begin_graph_capture(&self) -> Result<(), ForgeError>
pub fn begin_graph_capture(&self) -> Result<(), ForgeError>
Begin thread-local capture on the prepared compute stream.
Sourcepub fn end_graph_capture(&self) -> Result<CapturedCudaGraph, ForgeError>
pub fn end_graph_capture(&self) -> Result<CapturedCudaGraph, ForgeError>
Finish, instantiate and upload the current compute-stream capture.
Sourcepub fn launch_graph(&self, graph: &CapturedCudaGraph) -> Result<(), ForgeError>
pub fn launch_graph(&self, graph: &CapturedCudaGraph) -> Result<(), ForgeError>
Enqueue one replay on the graph’s retained compute stream.
pub fn allocate_and_write( &mut self, data: &[u8], binding: u32, group: u32, ) -> Result<BufferView, ForgeError>
Sourcepub fn write_view_prefetch(
&mut self,
view: &BufferView,
data: &[u8],
) -> Result<(), ForgeError>
pub fn write_view_prefetch( &mut self, view: &BufferView, data: &[u8], ) -> Result<(), ForgeError>
Overwrite a device view with host bytes on the prefetch stream,
overlapping with compute on the primary stream. Caller must invoke
[join_prefetch] before launching a kernel that reads this data.
Sourcepub fn join_prefetch(&self) -> Result<(), ForgeError>
pub fn join_prefetch(&self) -> Result<(), ForgeError>
Make the compute stream wait for all outstanding prefetch-stream work. Call this before launching a kernel that depends on prefetched data.
Sourcepub fn write_view(
&mut self,
view: &BufferView,
data: &[u8],
) -> Result<(), ForgeError>
pub fn write_view( &mut self, view: &BufferView, data: &[u8], ) -> Result<(), ForgeError>
Overwrite an existing device view with host bytes (no new allocation).
data.len() must be ≤ view.length_bytes.
pub fn allocate_transient( &mut self, size_bytes: usize, binding: u32, group: u32, ) -> Result<BufferView, ForgeError>
pub fn advance_read_head(&mut self, offset: usize)
pub fn clear_transient_allocations(&mut self)
Sourcepub fn write_checkpoint(&self) -> u64
pub fn write_checkpoint(&self) -> u64
Sourcepub fn restore_checkpoint(&mut self, write_count: u64)
pub fn restore_checkpoint(&mut self, write_count: u64)
pub fn read_buffer_f32(&self, view: &BufferView) -> Result<Vec<f32>, ForgeError>
Sourcepub fn read_buffer_u32_into(
&self,
view: &BufferView,
output: &mut [u32],
) -> Result<(), ForgeError>
pub fn read_buffer_u32_into( &self, view: &BufferView, output: &mut [u32], ) -> Result<(), ForgeError>
Copy a device view into a caller-owned u32 slice.
Unlike Self::read_buffer_f32, this performs no host allocation. It is the decode
token-readback boundary: the four-byte copy also synchronizes all preceding stream work.
Sourcepub fn read_buffer_f64(&self, view: &BufferView) -> Result<Vec<f64>, ForgeError>
pub fn read_buffer_f64(&self, view: &BufferView) -> Result<Vec<f64>, ForgeError>
Double-precision readback, the f64 mirror of Self::read_buffer_f32
(8 bytes/elem). Used by the native CUDA-f64 GEMM path — WGSL has no f64,
so this is CUDA-only by construction.
Trait Implementations§
Source§impl OracleContext for CudaComputeContext
Available on crate feature cuda only.
impl OracleContext for CudaComputeContext
cuda only.Source§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 the kernel’s CUDA-C (NVRTC → PTX, emitted internally by
CudaPipeline::compile_cuda_c) and run the warmup + timed-sample dispatch
loop. Mirrors the wgpu loop shape so the generic oracle is backend-agnostic;
the cross-backend CUDA oracle uses warmups = 0, samples = 1, reproducing the
single dispatch the previous evaluate_*_cuda functions performed.
Source§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>
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.Source§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>
usage is honoured by
the wgpu backend and ignored by CUDA, as for Self::allocate_and_write.Source§fn read_buffer_f32(&self, view: &BufferView) -> Result<Vec<f32>, ForgeError>
fn read_buffer_f32(&self, view: &BufferView) -> Result<Vec<f32>, ForgeError>
f32s.Source§fn clear_transient_allocations(&mut self)
fn clear_transient_allocations(&mut self)
Source§fn adapter(&self) -> &AdapterIdentity
fn adapter(&self) -> &AdapterIdentity
Source§fn constraints(&self) -> &AdapterConstraints
fn constraints(&self) -> &AdapterConstraints
Source§fn timestamp_supported(&self) -> bool
fn timestamp_supported(&self) -> bool
false there).Auto Trait Implementations§
impl !Freeze for CudaComputeContext
impl RefUnwindSafe for CudaComputeContext
impl Send for CudaComputeContext
impl Sync for CudaComputeContext
impl Unpin for CudaComputeContext
impl UnsafeUnpin for CudaComputeContext
impl UnwindSafe for CudaComputeContext
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more