Skip to main content

Module host_buffer

Module host_buffer 

Source
Expand description

Pinned (page-locked) host memory buffer.

PinnedBuffer<T> allocates host memory via cuMemAllocHost_v2, which pins the pages so that the CUDA driver can perform DMA transfers without an intermediate staging copy. This is the recommended source/destination for asynchronous host-device transfers.

§Deref

PinnedBuffer<T> implements Deref and DerefMut to [T], so it can be used anywhere a slice is expected.

§Ownership

The allocation is freed with cuMemFreeHost on drop. Errors during drop are logged via tracing::warn.

§Example

let mut pinned = PinnedBuffer::<f32>::alloc(256)?;
for (i, v) in pinned.iter_mut().enumerate() {
    *v = i as f32;
}
assert_eq!(pinned.len(), 256);

Structs§

PinnedBuffer
A contiguous buffer of T elements in page-locked (pinned) host memory.