pub struct DeviceBuffer<T> { /* private fields */ }Expand description
Struct that owns a buffer allocated on GPU device. The struct only holds the raw pointer and
length, but this struct has a Drop implementation which frees the associated device memory.
Implementations§
Source§impl<T> DeviceBuffer<T>
impl<T> DeviceBuffer<T>
Sourcepub unsafe fn from_raw_parts(ptr: *mut T, len: usize) -> Self
pub unsafe fn from_raw_parts(ptr: *mut T, len: usize) -> Self
§Safety
- The caller must ensure that the pointer
ptris valid forlenelements of typeTin device memory. - Dropping the constructed buffer will attempt to free the memory. As such,
ptrmust either have been allocated by the internal memory manager (VPMM) or the caller must useManuallyDropto prevent double-free.
Sourcepub fn with_capacity_on(len: usize, device_ctx: &GpuDeviceCtx) -> Self
pub fn with_capacity_on(len: usize, device_ctx: &GpuDeviceCtx) -> Self
Allocate device memory for len elements of type T on an explicit stream.
Sourcepub fn fill_zero_on(&self, device_ctx: &GpuDeviceCtx) -> Result<(), CudaError>
pub fn fill_zero_on(&self, device_ctx: &GpuDeviceCtx) -> Result<(), CudaError>
Fills the buffer with zeros on an explicit stream.
The caller should use the same stream that allocated this buffer.
fill_zero is async; same-stream guarantees ordering without explicit sync.
Sourcepub fn fill_zero_suffix_on(
&self,
start_idx: usize,
device_ctx: &GpuDeviceCtx,
) -> Result<(), CudaError>
pub fn fill_zero_suffix_on( &self, start_idx: usize, device_ctx: &GpuDeviceCtx, ) -> Result<(), CudaError>
Fills a suffix of the buffer with zeros on an explicit stream.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the buffer is empty (null pointer or zero length).
Sourcepub fn as_mut_ptr(&self) -> *mut T
pub fn as_mut_ptr(&self) -> *mut T
Returns a raw mutable pointer to the device data (typed).
Sourcepub fn as_mut_raw_ptr(&self) -> *mut c_void
pub fn as_mut_raw_ptr(&self) -> *mut c_void
Returns a *mut c_void (untyped) pointer.
Sourcepub fn as_raw_ptr(&self) -> *const c_void
pub fn as_raw_ptr(&self) -> *const c_void
Returns a *const c_void (untyped) pointer.
Sourcepub fn as_buffer<U>(self) -> DeviceBuffer<U>
pub fn as_buffer<U>(self) -> DeviceBuffer<U>
Converts the buffer to a buffer of different type.
T must be composable of Us.