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
impl DerivedWeights
pub fn new() -> Self
Sourcepub fn get_ptr(&self, kind: Derivation, key: u64) -> Option<u64>
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.
pub fn insert_ptr(&self, kind: Derivation, key: u64, value: u64)
pub fn get_pair(&self, kind: Derivation, key: u64) -> Option<(u64, u64)>
pub fn insert_pair(&self, kind: Derivation, key: u64, value: (u64, u64))
Sourcepub fn get_or_build_ptr(
&self,
kind: Derivation,
key: u64,
build: impl FnOnce() -> Result<u64>,
) -> Result<u64>
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.
Sourcepub fn get_or_build_pair(
&self,
kind: Derivation,
key: u64,
build: impl FnOnce() -> Result<(u64, u64)>,
) -> Result<(u64, u64)>
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.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Total memoized entries, for diagnostics and for asserting in tests that a fresh model starts empty.
pub fn is_empty(&self) -> bool
Trait Implementations§
Source§impl Debug for DerivedWeights
impl Debug for DerivedWeights
Source§impl Default for DerivedWeights
impl Default for DerivedWeights
Source§fn default() -> DerivedWeights
fn default() -> DerivedWeights
Source§impl ModelResource<dyn GpuBackend> for DerivedWeights
Release every derived allocation.
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.