pub struct MemoryPool { /* private fields */ }Expand description
Thread-safe memory pool for tensor allocation
Implementations§
Source§impl MemoryPool
impl MemoryPool
Sourcepub fn new(config: PoolConfig) -> Self
pub fn new(config: PoolConfig) -> Self
Create a new memory pool with the given configuration
Sourcepub fn allocate_tensor(
&self,
shape: &[usize],
dtype: DType,
) -> TorshResult<Tensor>
pub fn allocate_tensor( &self, shape: &[usize], dtype: DType, ) -> TorshResult<Tensor>
Allocate a tensor from the pool or create a new one
Sourcepub fn release_tensor(&self, tensor: Tensor)
pub fn release_tensor(&self, tensor: Tensor)
Release a tensor back to the pool for reuse
Sourcepub fn get_analytics(&self) -> MemoryAnalytics
pub fn get_analytics(&self) -> MemoryAnalytics
Get current memory analytics
Sourcepub fn get_pool_stats(&self) -> HashMap<String, usize>
pub fn get_pool_stats(&self) -> HashMap<String, usize>
Get pool statistics
Source§impl MemoryPool
Convenience functions for common memory pool operations
impl MemoryPool
Convenience functions for common memory pool operations
Sourcepub fn global() -> &'static MemoryPool
pub fn global() -> &'static MemoryPool
Create a global memory pool instance
Sourcepub fn allocate_f32(&self, shape: &[usize]) -> TorshResult<Tensor>
pub fn allocate_f32(&self, shape: &[usize]) -> TorshResult<Tensor>
Allocate f32 tensor from pool
Sourcepub fn allocate_i8(&self, shape: &[usize]) -> TorshResult<Tensor>
pub fn allocate_i8(&self, shape: &[usize]) -> TorshResult<Tensor>
Allocate i8 tensor from pool (common for quantized tensors)
Sourcepub fn allocate_u8(&self, shape: &[usize]) -> TorshResult<Tensor>
pub fn allocate_u8(&self, shape: &[usize]) -> TorshResult<Tensor>
Allocate u8 tensor from pool (common for quantized tensors)
Source§impl MemoryPool
Advanced memory pool management methods
impl MemoryPool
Advanced memory pool management methods
Sourcepub fn garbage_collect(&self) -> TorshResult<()>
pub fn garbage_collect(&self) -> TorshResult<()>
Trigger garbage collection to reduce fragmentation
Sourcepub fn check_memory_pressure(&self) -> bool
pub fn check_memory_pressure(&self) -> bool
Check memory pressure and auto-cleanup if needed
Sourcepub fn adaptive_resize(&self) -> TorshResult<()>
pub fn adaptive_resize(&self) -> TorshResult<()>
Adaptively adjust pool sizes based on usage patterns
Sourcepub fn get_utilization_report(&self) -> PoolUtilizationReport
pub fn get_utilization_report(&self) -> PoolUtilizationReport
Get detailed pool utilization report
Sourcepub fn prefetch_for_workload(
&self,
predicted_shapes: &[(Vec<usize>, DType)],
) -> TorshResult<()>
pub fn prefetch_for_workload( &self, predicted_shapes: &[(Vec<usize>, DType)], ) -> TorshResult<()>
Prefetch tensors for predicted workload
Auto Trait Implementations§
impl Freeze for MemoryPool
impl RefUnwindSafe for MemoryPool
impl Send for MemoryPool
impl Sync for MemoryPool
impl Unpin for MemoryPool
impl UnsafeUnpin for MemoryPool
impl UnwindSafe for MemoryPool
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> 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