DerivedWeights

Struct DerivedWeights 

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

Per-model memo of derived weight encodings.

One map per derivation rather than one keyed by (ptr, kind): the value types differ, and a wrong-kind hit would be exactly the class of bug this type exists to remove.

Implementations§

Source§

impl DerivedWeights

Source

pub fn new() -> Self

Source

pub fn get_ptr(&self, kind: Derivation, key: u64) -> Option<u64>

Raw memo read. get_or_build_ptr is the form to prefer; this pair exists because the dispatch helpers allocate and launch between the lookup and the store, and expressing that as a closure would mean indenting several hundred lines of kernel-launch code for no gain.

Source

pub fn insert_ptr(&self, kind: Derivation, key: u64, value: u64)

Source

pub fn get_pair(&self, kind: Derivation, key: u64) -> Option<(u64, u64)>

Source

pub fn insert_pair(&self, kind: Derivation, key: u64, value: (u64, u64))

Source

pub fn get_or_build_ptr( &self, kind: Derivation, key: u64, build: impl FnOnce() -> Result<u64>, ) -> Result<u64>

Look up a single-pointer derivation, computing it on a miss.

build runs outside the lock: it launches kernels and allocates, and holding a Mutex across that would serialise every layer’s first touch of a weight behind one another. A duplicate build under a race wastes an allocation, which is why the loser’s value is kept rather than swapped — the first writer’s pointer is the one other threads may already hold.

Source

pub fn get_or_build_pair( &self, kind: Derivation, key: u64, build: impl FnOnce() -> Result<(u64, u64)>, ) -> Result<(u64, u64)>

Look up a pair-valued derivation, computing it on a miss.

Source

pub fn len(&self) -> usize

Total memoized entries, for diagnostics and for asserting in tests that a fresh model starts empty.

Source

pub fn is_empty(&self) -> bool

Trait Implementations§

Source§

impl Debug for DerivedWeights

Source§

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

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

impl Default for DerivedWeights

Source§

fn default() -> DerivedWeights

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

impl ModelResource<dyn GpuBackend> for DerivedWeights

Release every derived allocation.

The KEYS are the original weight pointers — owned by the WeightStore and freed by it. Only the VALUES are derivations this cache allocated, so only those are freed here. Freeing a key would be a double-free of a weight.

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