Skip to main content

CudaArray

Struct CudaArray 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub unsafe fn copy_to_host_raw( &self, dst: *mut c_void, byte_count: usize, ) -> CudaRtResult<()>

Copy the entire array into a host buffer (synchronous, raw pointer).

Mirrors cudaMemcpyFromArray (array-to-host).

§Errors

Returns an error if cuMemcpyAtoH_v2 is absent or the copy fails.

§Safety

dst must be valid for writing byte_count bytes.

Source

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.

Source

pub unsafe fn copy_from_host_async_raw( &self, src: *const c_void, byte_count: usize, stream: CudaStream, ) -> CudaRtResult<()>

Asynchronously copy a host buffer into the array on stream.

Mirrors cudaMemcpyToArrayAsync.

§Errors

Returns an error if cuMemcpyHtoAAsync_v2 is absent.

§Safety

The caller must ensure src remains valid until the stream operation completes (i.e., until the stream is synchronized).

Source

pub fn raw(&self) -> CUarray

Returns the raw CUarray handle (for use in resource descriptors).

Source

pub const fn width(&self) -> usize

Width of the array in elements.

Source

pub const fn height(&self) -> usize

Height of the array in elements (0 for 1-D arrays).

Source

pub const fn format(&self) -> ArrayFormat

Element format of this array.

Source

pub const fn num_channels(&self) -> u32

Number of channels (1, 2, or 4).

Trait Implementations§

Source§

impl Drop for CudaArray

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more