pub struct PoolAllocator { /* private fields */ }Expand description
LRU memory pool for CPU tensor buffers.
Buffers are keyed by (numel, dtype). When a caller returns a buffer, it
can be re-acquired on the next allocation of the same size, avoiding heap
malloc/free on the hot path.
Implementations§
Source§impl PoolAllocator
impl PoolAllocator
pub fn new(capacity_bytes: usize) -> Self
Sourcepub fn acquire(&self, numel: usize, dtype: DType) -> Option<BufferHandle>
pub fn acquire(&self, numel: usize, dtype: DType) -> Option<BufferHandle>
Try to acquire a buffer for numel elements of dtype.
Returns None if the pool has no suitable entry — caller should
allocate fresh.
Sourcepub fn release(&self, handle: BufferHandle, numel: usize, dtype: DType)
pub fn release(&self, handle: BufferHandle, numel: usize, dtype: DType)
Return a buffer to the pool after use.
If the pool is over capacity, evict the least-recently-used entries.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Total bytes currently pooled.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PoolAllocator
impl !RefUnwindSafe for PoolAllocator
impl Send for PoolAllocator
impl Sync for PoolAllocator
impl Unpin for PoolAllocator
impl UnsafeUnpin for PoolAllocator
impl !UnwindSafe for PoolAllocator
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
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>
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 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>
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