Skip to main content

DeviceBuffer

Struct DeviceBuffer 

Source
pub struct DeviceBuffer<T: DeviceRepr> { /* private fields */ }
Expand description

Owned, typed allocation of device memory (Runtime API).

Implementations§

Source§

impl<T: DeviceRepr> DeviceBuffer<T>

Source

pub fn new(len: usize) -> Result<Self>

Allocate an uninitialized buffer of len elements on the current device.

Source

pub fn zeros(len: usize) -> Result<Self>

Allocate and zero-fill.

Source

pub fn from_slice(src: &[T]) -> Result<Self>

Allocate and synchronously copy src from host memory.

Source

pub fn copy_from_host(&self, src: &[T]) -> Result<()>

Synchronous H2D copy.

Source

pub fn copy_to_host(&self, dst: &mut [T]) -> Result<()>

Synchronous D2H copy.

Source

pub fn copy_from_host_async(&self, src: &[T], stream: &Stream) -> Result<()>

Asynchronous H2D copy on stream.

Source

pub fn copy_to_host_async(&self, dst: &mut [T], stream: &Stream) -> Result<()>

Asynchronous D2H copy on stream.

Source

pub fn len(&self) -> usize

Number of elements.

Source

pub fn byte_size(&self) -> usize

Size in bytes.

Source

pub fn is_empty(&self) -> bool

true if zero elements.

Source

pub fn as_raw(&self) -> *mut c_void

Raw device pointer. Use with care.

Source

pub fn as_device_ptr(&self) -> u64

Raw device pointer as the u64 value kernels expect. Convenience wrapper around as_raw.

Source§

impl<T: DeviceRepr> DeviceBuffer<T>

Source

pub fn new_async(len: usize, stream: &Stream) -> Result<Self>

Asynchronously allocate len elements on stream from the device’s default memory pool (CUDA 11.2+).

Source

pub fn free_async(self, stream: &Stream) -> Result<()>

Free this buffer asynchronously on stream. Consumes self so the sync Drop does not also free.

Source

pub fn memset_async(&self, value: u8, stream: &Stream) -> Result<()>

Asynchronous memset of self to byte value value on stream.

Trait Implementations§

Source§

impl<T: DeviceRepr> Debug for DeviceBuffer<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: DeviceRepr> Drop for DeviceBuffer<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: DeviceRepr + Send> Send for DeviceBuffer<T>

Auto Trait Implementations§

§

impl<T> Freeze for DeviceBuffer<T>

§

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

§

impl<T> !Sync for DeviceBuffer<T>

§

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

§

impl<T> UnsafeUnpin for DeviceBuffer<T>

§

impl<T> UnwindSafe for DeviceBuffer<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, 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.