pub struct UnifiedBuffer<T: Copy> { /* private fields */ }Expand description
A contiguous buffer of T elements in CUDA unified (managed) memory.
Unified memory is accessible from both the host CPU and the GPU device. The CUDA driver transparently migrates pages between host and device as needed. This simplifies programming at the cost of potential migration overhead compared to explicit device buffers.
Implementations§
Source§impl<T: Copy> UnifiedBuffer<T>
impl<T: Copy> UnifiedBuffer<T>
Sourcepub fn alloc(n: usize) -> CudaResult<Self>
pub fn alloc(n: usize) -> CudaResult<Self>
Allocates a unified memory buffer capable of holding n elements of
type T.
The memory is allocated with CU_MEM_ATTACH_GLOBAL, making it
accessible from any stream on any device in the system.
§Errors
CudaError::InvalidValueifnis zero.CudaError::OutOfMemoryif the allocation fails.- Other driver errors from
cuMemAllocManaged.
Sourcepub fn as_device_ptr(&self) -> CUdeviceptr
pub fn as_device_ptr(&self) -> CUdeviceptr
Returns the raw CUdeviceptr handle for use in kernel launches
and other device-side operations.
Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns a shared slice over the buffer’s host-accessible contents.
§Safety note
This is only safe to call when no GPU kernel is concurrently reading or writing this buffer. Synchronise the relevant stream or context before calling this method.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice over the buffer’s host-accessible contents.
§Safety note
This is only safe to call when no GPU kernel is concurrently reading or writing this buffer. Synchronise the relevant stream or context before calling this method.