pub struct TensorBlockPool { /* private fields */ }Expand description
Pre-allocated memory pool for tensor operations to reduce allocation overhead.
All blocks share a single configured size. The pool supports allocation, deallocation, reservation, defragmentation, and shrink-to-fit.
Implementations§
Source§impl TensorBlockPool
impl TensorBlockPool
Sourcepub fn new(config: PoolConfig) -> Self
pub fn new(config: PoolConfig) -> Self
Create a new block pool, pre-allocating config.initial_blocks blocks.
Sourcepub fn allocate(&mut self, owner: &str) -> Result<u64, String>
pub fn allocate(&mut self, owner: &str) -> Result<u64, String>
Allocate a free block, marking it as BlockStatus::Allocated and
assigning it to owner.
If no free block is available and allow_growth is true, a new block is
created (up to max_blocks). Returns an error if the pool is exhausted.
Sourcepub fn deallocate(&mut self, block_id: u64) -> Result<(), String>
pub fn deallocate(&mut self, block_id: u64) -> Result<(), String>
Deallocate the block with the given block_id, marking it
BlockStatus::Free, clearing its owner, and incrementing its
generation.
Sourcepub fn reserve(&mut self, block_id: u64, owner: &str) -> Result<(), String>
pub fn reserve(&mut self, block_id: u64, owner: &str) -> Result<(), String>
Reserve a free block for future use.
Transitions a block from BlockStatus::Free to
BlockStatus::Reserved.
Sourcepub fn release_reservation(&mut self, block_id: u64) -> Result<(), String>
pub fn release_reservation(&mut self, block_id: u64) -> Result<(), String>
Release a reservation, returning the block to BlockStatus::Free.
Sourcepub fn get_block(&self, block_id: u64) -> Option<&MemoryBlock>
pub fn get_block(&self, block_id: u64) -> Option<&MemoryBlock>
Look up a block by ID.
Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of free blocks.
Sourcepub fn allocated_count(&self) -> usize
pub fn allocated_count(&self) -> usize
Number of allocated blocks.
Sourcepub fn utilization(&self) -> f64
pub fn utilization(&self) -> f64
Fraction of blocks currently allocated (allocated / total).
Returns 0.0 if the pool is empty.
Sourcepub fn defragment(&mut self) -> usize
pub fn defragment(&mut self) -> usize
Compact the block list: move all BlockStatus::Free blocks to the
end. Resets the generation of relocated free blocks to zero.
Returns the number of free blocks that were relocated.
Sourcepub fn shrink_to_fit(&mut self) -> usize
pub fn shrink_to_fit(&mut self) -> usize
Remove trailing BlockStatus::Free blocks from the pool, shrinking
it. Returns the number of blocks removed.
Sourcepub fn block_stats(&self) -> BlockPoolStats
pub fn block_stats(&self) -> BlockPoolStats
Return a snapshot of pool statistics.
Auto Trait Implementations§
impl Freeze for TensorBlockPool
impl RefUnwindSafe for TensorBlockPool
impl Send for TensorBlockPool
impl Sync for TensorBlockPool
impl Unpin for TensorBlockPool
impl UnsafeUnpin for TensorBlockPool
impl UnwindSafe for TensorBlockPool
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