Skip to main content

Module buffer_view

Module buffer_view 

Source
Expand description

Type-safe buffer reinterpretation for device memory.

This module provides BufferView and BufferViewMut, which allow reinterpreting a DeviceBuffer<T> as a different element type U without copying data. This is useful for viewing a buffer of f32 values as u32 (e.g., for bitwise operations in a kernel), or for interpreting raw byte buffers as structured types.

§Size constraints

The total byte size of the original buffer must be evenly divisible by std::mem::size_of::<U>(). If not, the view creation returns CudaError::InvalidValue.

§Example

let buf = DeviceBuffer::<f32>::alloc(256)?;
// Reinterpret as u32 (same size, different type)
let view: BufferView<'_, u32> = buf.view_as::<u32>()?;
assert_eq!(view.len(), 256);

Structs§

BufferView
An immutable, type-reinterpreted view into a DeviceBuffer.
BufferViewMut
A mutable, type-reinterpreted view into a DeviceBuffer.