pub struct MemoryPool { /* private fields */ }Expand description
A stream-ordered memory pool (CUDA 11.2+).
Implementations§
Source§impl MemoryPool
impl MemoryPool
Sourcepub fn new(device_ordinal: i32) -> CudaResult<Self>
pub fn new(device_ordinal: i32) -> CudaResult<Self>
Creates a new memory pool on the given device.
This retains the device’s primary context for the lifetime of the pool (released when the pool is dropped), and binds every subsequent allocation and free issued through this pool to that context, so the pool is safe to share across threads without mixing pointers from different devices.
§Errors
CudaError::InvalidDeviceifdevice_ordinalis negative.CudaError::NotInitializedif no CUDA driver is available.- Other
CudaErrorvariants ifcuDevicePrimaryCtxRetainfails (e.g. an out-of-range device ordinal).
Sourcepub fn raw_handle(&self) -> u64
pub fn raw_handle(&self) -> u64
Sourcepub fn device_ordinal(&self) -> i32
pub fn device_ordinal(&self) -> i32
Returns the device ordinal this pool targets.
Sourcepub fn stats(&self) -> PoolStats
pub fn stats(&self) -> PoolStats
Returns current pool statistics.
The statistics track allocation behaviour over the pool’s lifetime.
Sourcepub fn trim(&mut self, min_bytes: usize) -> CudaResult<()>
pub fn trim(&mut self, min_bytes: usize) -> CudaResult<()>
Trims the pool, releasing unused memory back to the OS.
Attempts to release memory such that the pool retains at most
min_bytes of unused memory.
§Errors
Sourcepub fn set_threshold(&mut self, bytes: usize) -> CudaResult<()>
pub fn set_threshold(&mut self, bytes: usize) -> CudaResult<()>
Sets the threshold at which the pool will automatically release memory back to the OS.
When the pool’s unused memory exceeds bytes, subsequent frees
will trigger automatic trimming.