Struct DeviceBuffer

Source
pub struct DeviceBuffer<T: Copy + 'static> { /* private fields */ }
Expand description

A buffer on the device.

§Example

Copying data from a HostBuffer to a DeviceBuffer:

let stream = Stream::new().await.unwrap();
let all_ones = vec![1_u8; 100];
let host_buffer = HostBuffer::<u8>::from_slice(&all_ones).await;
let mut device_buffer = DeviceBuffer::<u8>::new(100, &stream).await;
device_buffer.copy_from(&host_buffer, &stream).await.unwrap();

Implementations§

Source§

impl<T: Copy + 'static> DeviceBuffer<T>

Source

pub async fn new(num_elements: usize, stream: &Stream) -> Self

Allocates memory on the device.

CUDA documentation

§Stream ordered semantics

This function uses stream ordered semantics. It can only be guaranteed to complete sequentially relative to operations scheduled on the same stream or the default stream.

§Arguments
  • num_elements - Number of elements to allocate.
  • stream - Stream to use.
Source

pub async fn from_slice(slice: &[T], stream: &Stream) -> Result<Self, Error>

Allocate memory on the device, and copy data from host into it.

This function creates a temporary HostBuffer, copies the slice into it, then finally copies the data from the host buffer to the DeviceBuffer.

The given stream is automatically synchronized, since the temporary host buffer might otherwise be dropped before the copy can complete.

§Arguments
  • slice - Data to copy into the buffer.
  • stream - Stream to use.
Source

pub async fn copy_from( &mut self, other: &HostBuffer<T>, stream: &Stream, ) -> Result<(), Error>

Copies memory from the provided pinned host buffer to this buffer.

This function synchronizes the stream implicitly.

CUDA documentation

§Pinned transfer

The other buffer (of type HostBuffer) is always a pinned buffer. This function is guaranteed to produce a pinned transfer on the runtime thread.

§Stream ordered semantics

This function uses stream ordered semantics. It can only be guaranteed to complete sequentially relative to operations scheduled on the same stream or the default stream.

§Arguments
  • other - Buffer to copy from.
  • stream - Stream to use.
Source

pub async unsafe fn copy_from_async( &mut self, other: &HostBuffer<T>, stream: &Stream, ) -> Result<(), Error>

Copies memory from the provided pinned host buffer to this buffer.

CUDA documentation

§Pinned transfer

The other buffer (of type HostBuffer) is always a pinned buffer. This function is guaranteed to produce a pinned transfer on the runtime thread.

§Stream ordered semantics

This function uses stream ordered semantics. It can only be guaranteed to complete sequentially relative to operations scheduled on the same stream or the default stream.

§Safety

This function is unsafe because the operation might not have completed when the function returns, and thus the state of the buffer is undefined.

§Arguments
  • other - Buffer to copy from.
  • stream - Stream to use.
Source

pub async fn copy_to( &self, other: &mut HostBuffer<T>, stream: &Stream, ) -> Result<(), Error>

Copies memory from this buffer to the provided pinned host buffer.

This function synchronizes the stream implicitly.

CUDA documentation

§Pinned transfer

The other buffer (of type HostBuffer) is always a pinned buffer. This function is guaranteed to produce a pinned transfer on the runtime thread.

§Stream ordered semantics

This function uses stream ordered semantics. It can only be guaranteed to complete sequentially relative to operations scheduled on the same stream or the default stream.

§Arguments
  • other - Buffer to copy to.
  • stream - Stream to use.
Source

pub async unsafe fn copy_to_async( &self, other: &mut HostBuffer<T>, stream: &Stream, ) -> Result<(), Error>

Copies memory from this buffer to the provided pinned host buffer.

CUDA documentation

§Pinned transfer

The other buffer (of type HostBuffer) is always a pinned buffer. This function is guaranteed to produce a pinned transfer on the runtime thread.

§Stream ordered semantics

This function uses stream ordered semantics. It can only be guaranteed to complete sequentially relative to operations scheduled on the same stream or the default stream.

§Safety

This function is unsafe because the operation might not have completed when the function returns, and thus the state of the buffer is undefined.

§Arguments
  • other - Buffer to copy to.
  • stream - Stream to use.
Source

pub async fn fill_with_byte( &mut self, value: u8, stream: &Stream, ) -> Result<(), Error>

Fill the entire buffer with the given byte.

CUDA documentation

§Stream ordered semantics

This function uses stream ordered semantics. It can only be guaranteed to complete sequentially relative to operations scheduled on the same stream or the default stream.

§Arguments
  • value - Byte value to fill buffer with.
Source

pub fn num_elements(&self) -> usize

Get number of elements in buffer.

Source

pub fn inner(&self) -> &DeviceBuffer<T>

Access the inner synchronous implementation of DeviceBuffer.

Source

pub fn inner_mut(&mut self) -> &mut DeviceBuffer<T>

Access the inner synchronous implementation of DeviceBuffer.

Auto Trait Implementations§

§

impl<T> Freeze for DeviceBuffer<T>

§

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

§

impl<T> Send for DeviceBuffer<T>

§

impl<T> Sync for DeviceBuffer<T>

§

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

§

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.