pub struct MetadataInfoCache<V> { /* private fields */ }Expand description
A cache of metadata info buffers keyed by InfoCacheKey, generic over the
value type V (a device buffer handle for a compute backend). Evicting an
entry drops its V; when V is a memory handle that returns the buffer to
the pool, so the cache never pins more device memory than its live entries.
All policy is delegated to MetadataCachePolicy; this type only carries
out its decisions. See the module docs for the intended
should_cache → get → insert flow.
Implementations§
Source§impl<V> MetadataInfoCache<V>
impl<V> MetadataInfoCache<V>
Sourcepub fn new(policy: MetadataCachePolicy) -> Self
pub fn new(policy: MetadataCachePolicy) -> Self
Create a cache governed by policy.
Sourcepub fn mode(&mut self, mode: CacheMode)
pub fn mode(&mut self, mode: CacheMode)
Switch the CacheMode driving the policy (see
MetadataCachePolicy::mode).
Sourcepub fn should_cache(&self, size: usize) -> bool
pub fn should_cache(&self, size: usize) -> bool
Whether an info of size bytes should be cached — see
MetadataCachePolicy::should_cache. When false, skip the cache
entirely and create the value directly.
Source§impl<V: Clone> MetadataInfoCache<V>
impl<V: Clone> MetadataInfoCache<V>
Sourcepub fn get(&mut self, key: &[u64]) -> Option<V>
pub fn get(&mut self, key: &[u64]) -> Option<V>
Look up key, advancing the logical clock by one tick. On a hit the
entry is marked used — its recency resets — and the value is cloned out.
During a capture (pins_entries) a
hit also pins the entry to the graph being recorded, once per capture.
Call only when should_cache is true; on a miss
create the value and hand it to insert.
Sourcepub fn insert(&mut self, key: InfoCacheKey, value: V)
pub fn insert(&mut self, key: InfoCacheKey, value: V)
Store value under key after a get miss. During a
capture the new entry is pinned to the graph being recorded; otherwise it
evicts the least-recently-used unpinned entry first if the cache is at
capacity (a capture is unbounded and
never evicts).
Because the runtime only reaches here on a
should_cache miss, the value it clones in is
always kept — no wasted clones.
Sourcepub fn capture_commit(&mut self, graph: GraphId)
pub fn capture_commit(&mut self, graph: GraphId)
Seal the entries pinned during the just-finished capture under graph,
so graph_release can drop their locks when the
graph is destroyed. Call once from end_capture after the graph is built.
Sourcepub fn capture_discard(&mut self)
pub fn capture_discard(&mut self)
Drop the locks taken during a capture that was abandoned (never turned into a graph), so the touched entries become evictable again. The entries themselves stay as ordinary cached values.
Sourcepub fn graph_release(&mut self, graph: GraphId)
pub fn graph_release(&mut self, graph: GraphId)
Release the entries a destroyed graph pinned. An entry no other live
graph still pins is removed, freeing its buffer — this is how the cache
is cleaned up when a graph is destroyed.
Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for MetadataInfoCache<V>
impl<V> RefUnwindSafe for MetadataInfoCache<V>where
V: RefUnwindSafe,
impl<V> Send for MetadataInfoCache<V>where
V: Send,
impl<V> Sync for MetadataInfoCache<V>where
V: Sync,
impl<V> Unpin for MetadataInfoCache<V>where
V: Unpin,
impl<V> UnsafeUnpin for MetadataInfoCache<V>
impl<V> UnwindSafe for MetadataInfoCache<V>where
V: UnwindSafe,
Blanket Implementations§
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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