pub struct NativeMemoryPool { /* private fields */ }Expand description
Thin wrapper around the CUDA driver’s stream-ordered memory pool
(cuMemPoolCreate / cuMemPoolDestroy).
Allocations are issued via NativeMemoryPool::alloc_async which
invokes cuMemAllocFromPoolAsync; frees are issued via
NativeMemoryPool::free_async which invokes cuMemFreeAsync.
§Stream-ordering
The CUDA stream-ordered pool API requires the caller to ensure all
outstanding work on the stream has completed before destroying the
pool. The Drop implementation calls cuMemPoolDestroy and
silently swallows any error to honour the standard Drop convention.
Call NativeMemoryPool::destroy explicitly to surface destruction
errors.
§Status
On systems without a CUDA driver (e.g. macOS), NativeMemoryPool::new
fails with CudaError::NotInitialized. On older drivers that lack
the pool entry points it fails with CudaError::NotSupported.
Implementations§
Source§impl NativeMemoryPool
impl NativeMemoryPool
Sourcepub fn new(props: NativeMemoryPoolProps) -> CudaResult<Self>
pub fn new(props: NativeMemoryPoolProps) -> CudaResult<Self>
Creates a new native memory pool on the device described by props.
§Errors
CudaError::InvalidValueifdevice_ordinalis negative.CudaError::NotInitializedif no CUDA driver is available.CudaError::NotSupportedif the driver does not exportcuMemPoolCreate.- Other
CudaErrorvariants on driver failure.
Sourcepub fn raw(&self) -> CUmemoryPool
pub fn raw(&self) -> CUmemoryPool
Returns the raw CUmemoryPool handle.
Sourcepub fn device_ordinal(&self) -> i32
pub fn device_ordinal(&self) -> i32
Returns the device ordinal that backs this pool.
Sourcepub fn alloc_async(
&self,
bytes: usize,
stream: &Stream,
) -> CudaResult<CUdeviceptr>
pub fn alloc_async( &self, bytes: usize, stream: &Stream, ) -> CudaResult<CUdeviceptr>
Asynchronously allocates bytes of memory from the pool, ordered
against stream.
§Errors
CudaError::InvalidValueifbytesis zero.CudaError::NotInitializedif no CUDA driver is available.CudaError::NotSupportedif the driver does not exportcuMemAllocFromPoolAsync.- Other
CudaErrorvariants on driver failure.
Sourcepub fn free_async(&self, ptr: CUdeviceptr, stream: &Stream) -> CudaResult<()>
pub fn free_async(&self, ptr: CUdeviceptr, stream: &Stream) -> CudaResult<()>
Asynchronously frees a pointer previously returned by
alloc_async, ordered against stream.
§Errors
CudaError::NotInitializedif no CUDA driver is available.CudaError::NotSupportedif the driver does not exportcuMemFreeAsync.- Other
CudaErrorvariants on driver failure.
Sourcepub fn destroy(self) -> CudaResult<()>
pub fn destroy(self) -> CudaResult<()>
Destroys the pool, returning any driver error to the caller.
The caller is responsible for ensuring all outstanding work on
streams that allocated from this pool has completed before calling
destroy.
After this call returns, the Drop implementation will be a
no-op.
§Errors
CudaError::NotInitializedif no CUDA driver is available.CudaError::NotSupportedif the driver does not exportcuMemPoolDestroy.- Other
CudaErrorvariants on driver failure.