pub struct OpCache { /* private fields */ }Expand description
Memoized kernel handles and scratch allocations for one backend.
Implementations§
Source§impl OpCache
impl OpCache
pub fn new() -> Self
Sourcepub fn kernel(
&self,
gpu: &dyn GpuBackend,
module: &'static str,
func: &'static str,
) -> Result<KernelHandle>
pub fn kernel( &self, gpu: &dyn GpuBackend, module: &'static str, func: &'static str, ) -> Result<KernelHandle>
Resolve module::func, memoized. Equivalent to gpu.kernel(..) on a
miss; a map read on a hit.
Sourcepub fn scratch(
&self,
gpu: &dyn GpuBackend,
tag: &'static str,
bytes: usize,
) -> Result<DevicePtr>
pub fn scratch( &self, gpu: &dyn GpuBackend, tag: &'static str, bytes: usize, ) -> Result<DevicePtr>
A scratch allocation of at least bytes, memoized under tag.
Grow-only: a request larger than the current buffer allocates a new one and abandons the old, which is bounded because the sizes that drive it (batch × hidden) have a ceiling per model. The abandoned block is reclaimed when the context goes, which is the point of scoping the cache to the backend.
Sourcepub fn alloc_fell_back(&self) -> bool
pub fn alloc_fell_back(&self) -> bool
Has device allocation already failed on this backend?
Retrying a failing cuMemAlloc per tensor wastes minutes of load time
and fragments what is left, so the first failure latches the loader
onto managed memory. Per BACKEND rather than per process: after a
model is unloaded the pressure is gone, and the next model’s load
should try device memory again instead of inheriting a UVM sentence
from a model that is no longer resident.
Sourcepub fn note_alloc_fallback(&self)
pub fn note_alloc_fallback(&self)
Latch the managed-memory fallback for the rest of this model’s load.
Sourcepub fn first_n(&self, key: &'static str, n: u32) -> bool
pub fn first_n(&self, key: &'static str, n: u32) -> bool
true for the first n times this backend reaches key.
For the diagnostics that report the first few of something and then go quiet. Counted per backend, so a second model reports its own.
Trait Implementations§
Source§impl ModelResource<dyn GpuBackend> for OpCache
Release the scratch allocations.
impl ModelResource<dyn GpuBackend> for OpCache
Release the scratch allocations.
The kernel handles are not freed here: they are module-scoped and die with
the AtlasRegistry the backend holds, which cuda_host::release unloads
once every handle to it is gone. Freeing them here would be a double-unload.