Skip to main content

AlignedBuffer

Struct AlignedBuffer 

Source
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>

Source

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
Source

pub fn as_device_ptr(&self) -> CUdeviceptr

Returns the aligned device pointer.

Source

pub fn len(&self) -> usize

Returns the number of T elements in this buffer.

Source

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.

Source

pub fn alignment(&self) -> &Alignment

Returns a reference to the alignment that was requested.

Source

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>()).

Source

pub fn is_aligned(&self) -> bool

Returns true if the buffer’s device pointer satisfies the requested alignment.

Source

pub fn allocated_bytes(&self) -> usize

Returns the total number of bytes that were allocated (including alignment padding).

Source

pub fn offset(&self) -> usize

Returns the byte offset from the raw allocation base to the aligned pointer.

Trait Implementations§

Source§

impl<T: Copy> Drop for AlignedBuffer<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Copy + Send> Send for AlignedBuffer<T>

Source§

impl<T: Copy + Sync> Sync for AlignedBuffer<T>

Auto Trait Implementations§

§

impl<T> Freeze for AlignedBuffer<T>

§

impl<T> RefUnwindSafe for AlignedBuffer<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for AlignedBuffer<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for AlignedBuffer<T>

§

impl<T> UnwindSafe for AlignedBuffer<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more