pub struct LayerPager { /* private fields */ }Expand description
LRU weight pager — evicts cold tensors to free RAM, loads from source on demand.
§Pinned tensors
Tensors whose TensorId is in the pinned set are never evicted.
If pinned tensors alone exceed the budget, eviction will exhaust all
non-pinned candidates and then stop (no error); the budget acts as a
best-effort target.
§Acquiring tensors
Call acquire to get an Arc<ResidentTensor> for a
tensor by ID. The result shares ownership with the pager’s resident map, so
the bytes stay alive as long as either the pager or the caller holds a
reference — eviction only removes the pager’s entry, not the data itself.
Implementations§
Source§impl LayerPager
impl LayerPager
Sourcepub fn new(
source: Arc<dyn PagerSource>,
tensor_map: HashMap<TensorId, TensorEntry>,
budget_bytes: u64,
pinned: HashSet<TensorId>,
) -> Self
pub fn new( source: Arc<dyn PagerSource>, tensor_map: HashMap<TensorId, TensorEntry>, budget_bytes: u64, pinned: HashSet<TensorId>, ) -> Self
Sourcepub fn acquire(
&self,
id: &TensorId,
) -> Result<Arc<ResidentTensor>, RuntimeError>
pub fn acquire( &self, id: &TensorId, ) -> Result<Arc<ResidentTensor>, RuntimeError>
Acquire a tensor, loading it from the source if not currently resident.
The LRU order is updated on every successful acquire. If the tensor
must be loaded, the pager first evicts non-pinned tensors until the
budget allows the new allocation, then reads the bytes from source.
§Errors
RuntimeError::TensorNotFound—idis not in the tensor map.RuntimeError::LockPoisoned— an internal lock was poisoned.RuntimeError::OffloadEof/RuntimeError::Io— source read failed.
Sourcepub fn resident_bytes(&self) -> u64
pub fn resident_bytes(&self) -> u64
Return the number of bytes currently resident in RAM.
Sourcepub fn resident_count(&self) -> usize
pub fn resident_count(&self) -> usize
Return the number of tensors currently resident in RAM.
Sourcepub fn budget_bytes(&self) -> u64
pub fn budget_bytes(&self) -> u64
Return the configured RAM budget in bytes.
Sourcepub fn is_resident(&self, id: &TensorId) -> bool
pub fn is_resident(&self, id: &TensorId) -> bool
Check whether a tensor is currently resident.
Auto Trait Implementations§
impl !Freeze for LayerPager
impl !RefUnwindSafe for LayerPager
impl Send for LayerPager
impl Sync for LayerPager
impl Unpin for LayerPager
impl UnsafeUnpin for LayerPager
impl !UnwindSafe for LayerPager
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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