pub struct PooledBuffer<T: Copy> { /* private fields */ }Expand description
A device buffer allocated from a MemoryPool.
Unlike DeviceBuffer, a PooledBuffer is freed
asynchronously — the free operation is enqueued on the stream rather
than blocking the CPU. This enables overlap of allocation, computation,
and deallocation across multiple stream operations.
§Stream-ordering
Dropping a PooledBuffer does not immediately reuse its device pointer.
Instead, a CU_EVENT_DISABLE_TIMING event is recorded on the stream the
buffer was allocated on (the stream argument to
alloc_async); the pointer is only handed back out
to a later alloc_async call once that event has completed, i.e. once
all work enqueued on the stream before the drop has actually finished
executing on the device. A PooledBuffer must therefore not outlive its
stream. If the recycle event cannot be created or recorded, Drop falls
back to a blocking cuStreamSynchronize on the owning stream before
freeing the pointer directly, so correctness is preserved at the cost of
losing the pool’s overlap benefits for that allocation.
§Status
This type allocates from an in-process memory pool and returns buffers to that pool on drop.
Implementations§
Source§impl<T: Copy> PooledBuffer<T>
impl<T: Copy> PooledBuffer<T>
Sourcepub fn alloc_async(
pool: &MemoryPool,
n: usize,
stream: &Stream,
) -> CudaResult<Self>
pub fn alloc_async( pool: &MemoryPool, n: usize, stream: &Stream, ) -> CudaResult<Self>
Asynchronously allocates a buffer of n elements from the given pool.
The allocation is ordered relative to other operations on stream;
stream is also recorded against so that Drop can establish that
all work using this buffer has completed before its pointer is
recycled to a later caller (see the type-level docs).
§Errors
CudaError::InvalidValueifnis zero orn * size_of::<T>()overflows.- Other
CudaErrorvariants if the underlying allocation fails.
Sourcepub fn as_device_ptr(&self) -> CUdeviceptr
pub fn as_device_ptr(&self) -> CUdeviceptr
Returns the raw CUdeviceptr handle.