pub struct AlignedBuffer<T: Copy> { /* private fields */ }Expand description
A device memory buffer whose starting address is guaranteed to meet the
requested Alignment.
Internally this may over-allocate by up to alignment - 1 extra bytes and
offset the user-visible pointer so that it lands on an aligned boundary.
The extra bytes (if any) are reported by wasted_bytes.
The buffer frees the original (unaligned) allocation on Drop.
Implementations§
Source§impl<T: Copy> AlignedBuffer<T>
impl<T: Copy> AlignedBuffer<T>
Sourcepub fn alloc(n: usize, alignment: Alignment) -> CudaResult<Self>
pub fn alloc(n: usize, alignment: Alignment) -> CudaResult<Self>
Allocates an aligned device buffer capable of holding n elements of
type T.
The returned buffer’s device pointer is guaranteed to be aligned to
alignment.bytes(). The allocation may be slightly larger than
n * size_of::<T>() to accommodate the alignment offset.
§Errors
CudaError::InvalidValueifnis zero, alignment is invalid, or the byte-size computation overflows.CudaError::OutOfMemoryif the GPU cannot satisfy the allocation.
Sourcepub fn as_device_ptr(&self) -> CUdeviceptr
pub fn as_device_ptr(&self) -> CUdeviceptr
Returns the aligned device pointer.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the buffer contains zero elements.
In practice this is always false because alloc
rejects zero-length allocations.
Sourcepub fn wasted_bytes(&self) -> usize
pub fn wasted_bytes(&self) -> usize
Returns the number of bytes wasted for alignment padding.
This is the difference between the total allocation size and the
minimum required (len * size_of::<T>()).
Sourcepub fn is_aligned(&self) -> bool
pub fn is_aligned(&self) -> bool
Returns true if the buffer’s device pointer satisfies the requested
alignment.
Sourcepub fn allocated_bytes(&self) -> usize
pub fn allocated_bytes(&self) -> usize
Returns the total number of bytes that were allocated (including alignment padding).