pub struct MemoryPool { /* private fields */ }Expand description
Memory pool for efficient GPU memory management
Implementations§
Source§impl MemoryPool
impl MemoryPool
Sourcepub fn new(
device: Arc<Device>,
pool_size: u64,
usage: BufferUsages,
) -> Result<Self>
pub fn new( device: Arc<Device>, pool_size: u64, usage: BufferUsages, ) -> Result<Self>
Create a new memory pool
Sourcepub fn with_config(
device: Arc<Device>,
pool_size: u64,
usage: BufferUsages,
defrag_config: DefragConfig,
) -> Result<Self>
pub fn with_config( device: Arc<Device>, pool_size: u64, usage: BufferUsages, defrag_config: DefragConfig, ) -> Result<Self>
Create a new memory pool with custom defragmentation configuration
Sourcepub fn allocate(
self: &Arc<Self>,
size: u64,
alignment: u64,
) -> Result<MemoryAllocation>
pub fn allocate( self: &Arc<Self>, size: u64, alignment: u64, ) -> Result<MemoryAllocation>
Allocate memory from the pool
Sourcepub fn get_allocation_offset(&self, alloc_id: u64) -> Option<u64>
pub fn get_allocation_offset(&self, alloc_id: u64) -> Option<u64>
Get the current offset for an allocation ID Returns None if the allocation is not found
Sourcepub fn pin_allocation(&self, alloc_id: u64) -> Result<()>
pub fn pin_allocation(&self, alloc_id: u64) -> Result<()>
Pin an allocation to prevent it from being moved during defragmentation
Sourcepub fn unpin_allocation(&self, alloc_id: u64) -> Result<()>
pub fn unpin_allocation(&self, alloc_id: u64) -> Result<()>
Unpin an allocation to allow it to be moved during defragmentation
Sourcepub fn set_defrag_config(&self, config: DefragConfig)
pub fn set_defrag_config(&self, config: DefragConfig)
Set the defragmentation configuration
Sourcepub fn get_defrag_config(&self) -> DefragConfig
pub fn get_defrag_config(&self) -> DefragConfig
Get the current defragmentation configuration
Sourcepub fn plan_defragmentation(&self) -> DefragmentationPlan
pub fn plan_defragmentation(&self) -> DefragmentationPlan
Create a defragmentation plan without executing it
This analyzes the current memory layout and creates a plan for compacting allocations. The plan can be inspected before executing.
Sourcepub fn defragment(&self) -> Result<DefragmentationResult>
pub fn defragment(&self) -> Result<DefragmentationResult>
Defragment the pool (logical defragmentation - metadata only)
This method updates the block metadata without performing GPU memory copies. It’s useful for testing or when you plan to recreate the data anyway.
For actual GPU memory defragmentation with data preservation, use
defragment_with_queue() instead.
Sourcepub fn defragment_with_queue(
&self,
queue: &Queue,
) -> Result<DefragmentationResult>
pub fn defragment_with_queue( &self, queue: &Queue, ) -> Result<DefragmentationResult>
Sourcepub fn needs_defragmentation(&self) -> bool
pub fn needs_defragmentation(&self) -> bool
Check if defragmentation is needed based on current configuration
Sourcepub fn get_fragmentation(&self) -> f64
pub fn get_fragmentation(&self) -> f64
Get fragmentation level (0.0 - 1.0)
Sourcepub fn get_total_bytes_defragged(&self) -> u64
pub fn get_total_bytes_defragged(&self) -> u64
Get total bytes defragmented across all defragmentation operations
Sourcepub fn time_since_last_defrag(&self) -> Option<Duration>
pub fn time_since_last_defrag(&self) -> Option<Duration>
Get the time since the last defragmentation
Sourcepub fn get_available_memory(&self) -> u64
pub fn get_available_memory(&self) -> u64
Get available memory
Sourcepub fn get_current_usage(&self) -> u64
pub fn get_current_usage(&self) -> u64
Get current memory usage
Sourcepub fn get_peak_usage(&self) -> u64
pub fn get_peak_usage(&self) -> u64
Get peak memory usage
Sourcepub fn get_stats(&self) -> MemoryPoolStats
pub fn get_stats(&self) -> MemoryPoolStats
Get memory statistics
Sourcepub fn print_stats(&self)
pub fn print_stats(&self)
Print pool statistics