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>
impl<T: Copy + 'static> DeviceBuffer2D<T>
Sourcepub async fn new(width: usize, height: usize, num_channels: usize) -> Self
pub async fn new(width: usize, height: usize, num_channels: usize) -> Self
Allocates 2D memory on the device.
§Arguments
width
- Width of 2-dimensional buffer.height
- Height of 2-dimensional buffer.num_channels
- Number of channels per item.
Sourcepub async fn copy_from(
&mut self,
other: &HostBuffer<T>,
stream: &Stream,
) -> Result<(), Error>
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
.
§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.
Sourcepub async unsafe fn copy_from_async(
&mut self,
other: &HostBuffer<T>,
stream: &Stream,
) -> Result<(), Error>
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
.
§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.
Sourcepub async fn copy_to(
&self,
other: &mut HostBuffer<T>,
stream: &Stream,
) -> Result<(), Error>
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.
§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.
Sourcepub async unsafe fn copy_to_async(
&self,
other: &mut HostBuffer<T>,
stream: &Stream,
) -> Result<(), Error>
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
.
§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.
Sourcepub async fn fill_with_byte(
&mut self,
value: u8,
stream: &Stream,
) -> Result<(), Error>
pub async fn fill_with_byte( &mut self, value: u8, stream: &Stream, ) -> Result<(), Error>
Sourcepub fn num_channels(&self) -> usize
pub fn num_channels(&self) -> usize
Get 2D buffer number of channels.
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Get the total number of elements in buffer.
This is equal to: width
times height
times num_channels
.
Sourcepub fn inner(&self) -> &DeviceBuffer2D<T>
pub fn inner(&self) -> &DeviceBuffer2D<T>
Access the inner synchronous implementation of DeviceBuffer2D
.
Sourcepub fn inner_mut(&mut self) -> &mut DeviceBuffer2D<T>
pub fn inner_mut(&mut self) -> &mut DeviceBuffer2D<T>
Access the inner synchronous implementation of DeviceBuffer2D
.