Skip to main content

MetadataInfoCache

Struct MetadataInfoCache 

Source
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_cachegetinsert flow.

Implementations§

Source§

impl<V> MetadataInfoCache<V>

Source

pub fn new(policy: MetadataCachePolicy) -> Self

Create a cache governed by policy.

Source

pub fn mode(&mut self, mode: CacheMode)

Switch the CacheMode driving the policy (see MetadataCachePolicy::mode).

Source

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

pub fn len(&self) -> usize

Number of entries currently cached.

Source

pub fn is_empty(&self) -> bool

Whether the cache holds no entries.

Source

pub fn clear(&mut self)

Drop every cached entry (releasing every held V).

Source§

impl<V: Clone> MetadataInfoCache<V>

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl<V: Debug> Debug for MetadataInfoCache<V>

Source§

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

Formats the value using the given formatter. Read more

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.