pub struct TensorMemoryPool {
pub slots: HashMap<u64, PoolSlot>,
pub next_slot_id: u64,
pub max_slots: usize,
pub total_allocations: u64,
pub total_deallocations: u64,
}Expand description
A slab-based memory pool that pre-allocates tensor buffers organised into size-class buckets to minimise allocation overhead on hot inference paths.
Fields§
§slots: HashMap<u64, PoolSlot>All slots, keyed by slot_id.
next_slot_id: u64Counter used to generate unique slot IDs.
max_slots: usizeHard upper bound on the number of slots the pool may hold.
total_allocations: u64Total successful allocations since creation.
total_deallocations: u64Total successful deallocations since creation.
Implementations§
Source§impl TensorMemoryPool
impl TensorMemoryPool
Sourcepub fn allocate(&mut self, requested_bytes: u64, tick: u64) -> Option<u64>
pub fn allocate(&mut self, requested_bytes: u64, tick: u64) -> Option<u64>
Attempt to check out a slot suitable for requested_bytes at the given
logical tick.
Sourcepub fn deallocate(&mut self, slot_id: u64, tick: u64) -> bool
pub fn deallocate(&mut self, slot_id: u64, tick: u64) -> bool
Return slot slot_id to the pool at the given tick.
Returns false if the slot does not exist or was already free.
Sourcepub fn evict_idle(&mut self, tick: u64, idle_ticks: u64)
pub fn evict_idle(&mut self, tick: u64, idle_ticks: u64)
Evict every free slot whose last-used tick is at least idle_ticks
ticks in the past.
Sourcepub fn slots_for_class(&self, class: SizeClass) -> Vec<&PoolSlot>
pub fn slots_for_class(&self, class: SizeClass) -> Vec<&PoolSlot>
Return all slots belonging to class, sorted by slot_id ascending.
Sourcepub fn stats(&self) -> MemoryPoolStats
pub fn stats(&self) -> MemoryPoolStats
Compute aggregate statistics for the current pool state.
Auto Trait Implementations§
impl Freeze for TensorMemoryPool
impl RefUnwindSafe for TensorMemoryPool
impl Send for TensorMemoryPool
impl Sync for TensorMemoryPool
impl Unpin for TensorMemoryPool
impl UnsafeUnpin for TensorMemoryPool
impl UnwindSafe for TensorMemoryPool
Blanket Implementations§
impl<T> Allocation for T
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> 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