Struct DeviceBuffer2D

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

A buffer on the device.

§Example

Copying data from a HostBuffer to a DeviceBuffer2D:

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

Implementations§

Source§

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

Source

pub async fn new(width: usize, height: usize, num_channels: usize) -> Self

Allocates 2D memory on the device.

CUDA documentation

§Arguments
  • width - Width of 2-dimensional buffer.
  • height - Height of 2-dimensional buffer.
  • num_channels - Number of channels per item.
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 2D buffer.

This function synchronizes the stream implicitly.

The host buffer must be of the same size. For the 2D buffer, the total number of elements is width times height times num_channels.

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 2D buffer.

The host buffer must be of the same size. For the 2D buffer, the total number of elements is width times height times num_channels.

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 2D buffer to the provided pinned host buffer.

The host buffer must be of the same size. For the 2D buffer, the total number of elements is width times height times num_channels.

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 2D buffer to the provided pinned host buffer.

The host buffer must be of the same size. For the 2D buffer, the total number of elements is width times height times num_channels.

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 width(&self) -> usize

Get 2D buffer width.

Source

pub fn height(&self) -> usize

Get 2D buffer height.

Source

pub fn num_channels(&self) -> usize

Get 2D buffer number of channels.

Source

pub fn num_elements(&self) -> usize

Get the total number of elements in buffer.

This is equal to: width times height times num_channels.

Source

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

Access the inner synchronous implementation of DeviceBuffer2D.

Source

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

Access the inner synchronous implementation of DeviceBuffer2D.

Auto Trait Implementations§

§

impl<T> Freeze for DeviceBuffer2D<T>

§

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

§

impl<T> Send for DeviceBuffer2D<T>

§

impl<T> Sync for DeviceBuffer2D<T>

§

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

§

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