pub struct CudaArray { /* private fields */ }Expand description
RAII wrapper for a CUDA array (1-D or 2-D).
Created by CudaArray::create_1d or CudaArray::create_2d; freed by Drop.
A CudaArray can be bound to a CudaTextureObject or
CudaSurfaceObject for hardware-accelerated sampling.
Implementations§
Source§impl CudaArray
impl CudaArray
Sourcepub fn create_1d(
width: usize,
format: ArrayFormat,
num_channels: u32,
) -> CudaRtResult<Self>
pub fn create_1d( width: usize, format: ArrayFormat, num_channels: u32, ) -> CudaRtResult<Self>
Allocate a 1-D CUDA array with width elements of the given format and
channel count (num_channels must be 1, 2, or 4).
Mirrors cudaMallocArray (1-D form).
§Errors
Returns CudaRtError::NotSupported if the driver does not expose
cuArrayCreate_v2, or propagates driver errors.
Sourcepub fn create_2d(
width: usize,
height: usize,
format: ArrayFormat,
num_channels: u32,
) -> CudaRtResult<Self>
pub fn create_2d( width: usize, height: usize, format: ArrayFormat, num_channels: u32, ) -> CudaRtResult<Self>
Allocate a 2-D CUDA array with width × height elements.
Mirrors cudaMallocArray (2-D form).
§Errors
Returns CudaRtError::NotSupported if cuArrayCreate_v2 is absent.
Sourcepub unsafe fn copy_from_host_raw(
&self,
src: *const c_void,
byte_count: usize,
) -> CudaRtResult<()>
pub unsafe fn copy_from_host_raw( &self, src: *const c_void, byte_count: usize, ) -> CudaRtResult<()>
Copy a contiguous host buffer into the entire array (synchronous).
data must contain exactly width * height.max(1) * num_channels
elements of the appropriate type.
Mirrors cudaMemcpyToArray (host-to-array).
§Errors
Returns an error if the driver does not support cuMemcpyHtoA_v2 or if
the copy fails.
§Safety
src must be valid for reading byte_count bytes.
Sourcepub fn copy_from_host<T: Copy>(&self, src: &[T]) -> CudaRtResult<()>
pub fn copy_from_host<T: Copy>(&self, src: &[T]) -> CudaRtResult<()>
Copy a typed host slice into the array (synchronous, type-safe helper).
§Errors
Forwards errors from Self::copy_from_host_raw.
Sourcepub unsafe fn copy_to_host_raw(
&self,
dst: *mut c_void,
byte_count: usize,
) -> CudaRtResult<()>
pub unsafe fn copy_to_host_raw( &self, dst: *mut c_void, byte_count: usize, ) -> CudaRtResult<()>
Sourcepub fn copy_to_host<T: Copy>(&self, dst: &mut [T]) -> CudaRtResult<()>
pub fn copy_to_host<T: Copy>(&self, dst: &mut [T]) -> CudaRtResult<()>
Copy the entire array into a typed host slice (synchronous, type-safe).
§Errors
Forwards errors from Self::copy_to_host_raw.
Sourcepub unsafe fn copy_from_host_async_raw(
&self,
src: *const c_void,
byte_count: usize,
stream: CudaStream,
) -> CudaRtResult<()>
pub unsafe fn copy_from_host_async_raw( &self, src: *const c_void, byte_count: usize, stream: CudaStream, ) -> CudaRtResult<()>
Sourcepub const fn format(&self) -> ArrayFormat
pub const fn format(&self) -> ArrayFormat
Element format of this array.
Sourcepub const fn num_channels(&self) -> u32
pub const fn num_channels(&self) -> u32
Number of channels (1, 2, or 4).