#[non_exhaustive]pub struct TieredCache<P: TierPolicy = LruPolicy> { /* private fields */ }Expand description
Generic tiered cache for GPU buffers.
Tracks hot/cold buffers. TierPolicy decides promotion and eviction.
This is the vyre primitive that helix builds inference intelligence on top of.
Implementations§
Source§impl TieredCache<LruPolicy>
impl TieredCache<LruPolicy>
Source§impl<P: TierPolicy> TieredCache<P>
impl<P: TierPolicy> TieredCache<P>
Sourcepub fn with_policy(tiers: Vec<CacheTier>, policy: P) -> Self
pub fn with_policy(tiers: Vec<CacheTier>, policy: P) -> Self
Create a new cache with a custom policy implementation.
Sourcepub fn get(&self, key: u64) -> Option<&CacheEntry>
pub fn get(&self, key: u64) -> Option<&CacheEntry>
Return a reference to the entry with the given key, if it exists.
Sourcepub fn insert(&mut self, key: u64, size: u64) -> Result<(), CacheError>
pub fn insert(&mut self, key: u64, size: u64) -> Result<(), CacheError>
Insert a new entry into the lowest tier that can fit it.
§Errors
Returns CacheError::EntryTooLarge when no tier can hold the entry.
Sourcepub fn record_access(&mut self, key: u64)
pub fn record_access(&mut self, key: u64)
Record an access for the given key.
Sourcepub fn promote(&mut self, key: u64) -> Result<(), CacheError>
pub fn promote(&mut self, key: u64) -> Result<(), CacheError>
Promote the entry to the next faster tier if the policy allows it.
§Errors
Returns CacheError::KeyNotFound when the key does not exist.
Sourcepub fn demote(&mut self, key: u64) -> Result<(), CacheError>
pub fn demote(&mut self, key: u64) -> Result<(), CacheError>
Demote the entry to the next slower tier.
§Errors
Returns CacheError::KeyNotFound when the key does not exist.
Auto Trait Implementations§
impl<P> Freeze for TieredCache<P>where
P: Freeze,
impl<P> RefUnwindSafe for TieredCache<P>where
P: RefUnwindSafe,
impl<P> Send for TieredCache<P>
impl<P> Sync for TieredCache<P>
impl<P> Unpin for TieredCache<P>where
P: Unpin,
impl<P> UnsafeUnpin for TieredCache<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for TieredCache<P>where
P: 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
Mutably borrows from an owned value. Read more