OpCache

Struct OpCache 

Source
pub struct OpCache { /* private fields */ }
Expand description

Memoized kernel handles and scratch allocations for one backend.

Implementations§

Source§

impl OpCache

Source

pub fn new() -> Self

Source

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.

Source

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.

Source

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.

Source

pub fn note_alloc_fallback(&self)

Latch the managed-memory fallback for the rest of this model’s load.

Source

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.

Source

pub fn once(&self, key: &'static str) -> bool

true the first time this backend reaches key, false after.

For the log/dump gates whose call site holds a GpuBackend and nothing else. Backend-scoped, so a second model re-arms them.

Source

pub fn first_shape(&self, name: &str, m: u32, n: u32, k: u32) -> bool

true the first time this backend dispatches (name, m, n, k). Diagnostic de-duplication for the GEMM route/shape log lines.

Trait Implementations§

Source§

impl Debug for OpCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OpCache

Source§

fn default() -> OpCache

Returns the “default value” for a type. Read more
Source§

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.

Source§

fn label(&self) -> &'static str

Human name, for the teardown report and for attributing a failure.
Source§

fn release(&mut self, gpu: &dyn GpuBackend) -> Result<()>

Release everything this owns. Must be idempotent: the host calls it, and a Drop backstop may call it again.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more