pub struct MappedBuffer<T: Copy> { /* private fields */ }Expand description
A host-allocated, device-mapped (zero-copy) memory buffer.
The host memory is page-locked and accessible from both CPU code and GPU kernels. GPU accesses traverse the PCIe bus, making this suitable for small or infrequently-accessed data where the overhead of explicit transfers is not justified.
The buffer is freed automatically on drop via cuMemFreeHost.
Implementations§
Source§impl<T: Copy> MappedBuffer<T>
impl<T: Copy> MappedBuffer<T>
Sourcepub fn alloc(n: usize) -> CudaResult<Self>
pub fn alloc(n: usize) -> CudaResult<Self>
Allocates a zero-copy host-mapped buffer of n elements.
The allocation uses cuMemAllocHost_v2 (page-locked pinned memory)
and retrieves the corresponding device pointer via
cuMemHostGetDevicePointer_v2. A CUDA context must be current on
the calling thread.
§Errors
Returns a CUDA driver error if allocation or mapping fails.
Sourcepub fn as_device_ptr(&self) -> CUdeviceptr
pub fn as_device_ptr(&self) -> CUdeviceptr
Returns the raw device pointer for use in kernel parameters.
Sourcepub fn as_host_ptr(&self) -> *const T
pub fn as_host_ptr(&self) -> *const T
Returns a raw const pointer to the host-side data.
Sourcepub fn as_host_ptr_mut(&mut self) -> *mut T
pub fn as_host_ptr_mut(&mut self) -> *mut T
Returns a raw mutable pointer to the host-side data.
Sourcepub fn as_host_slice(&self) -> &[T]
pub fn as_host_slice(&self) -> &[T]
Returns a shared slice over the host-side data.
§Safety
The caller must ensure no concurrent GPU writes are in flight.
Sourcepub fn as_host_slice_mut(&mut self) -> &mut [T]
pub fn as_host_slice_mut(&mut self) -> &mut [T]
Returns a mutable slice over the host-side data.
§Safety
The caller must ensure no concurrent GPU reads or writes are in flight.