pub struct ArrayObject { /* private fields */ }
Expand description
A CUDA Array. Can be bound to a texture or surface.
Implementations
sourceimpl ArrayObject
impl ArrayObject
sourcepub fn from_descriptor(descriptor: &ArrayDescriptor) -> CudaResult<Self>
pub fn from_descriptor(descriptor: &ArrayDescriptor) -> CudaResult<Self>
Constructs a generic ArrayObject from an ArrayDescriptor
.
sourcepub fn new(
dims: [usize; 3],
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
pub fn new(
dims: [usize; 3],
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
Allocates a new CUDA Array that is up to 3-dimensions.
dims
contains the extents of the array. dims[0]
must be non-zero. dims[1]
must be
non-zero if dims[2]
is non-zero. The rank of the array is equal to the number of non-zero
dims
.
format
determines the data-type of the array.
num_channels
determines the number of channels per array element (1, 2, or 4).
use cust::memory::array::{ArrayObject, ArrayFormat};
let one_dim_array = ArrayObject::new([10, 0, 0], ArrayFormat::F32, 1)?;
let two_dim_array = ArrayObject::new([10, 12, 0], ArrayFormat::F32, 1)?;
let three_dim_array = ArrayObject::new([10, 12, 14], ArrayFormat::F32, 1)?;
sourcepub fn new_1d(
width: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
pub fn new_1d(
width: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
Allocates a new 1D CUDA Array.
width
must be non-zero.
format
determines the data-type of the array.
num_channels
determines the number of channels per array element (1, 2, or 4).
use cust::memory::array::{ArrayObject, ArrayFormat};
// Allocates a 1D array of 10 single-precision, single-channel floating point values.
let one_dim_array = ArrayObject::new_1d(10, ArrayFormat::F32, 1)?;
sourcepub fn new_2d(
dims: [usize; 2],
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
pub fn new_2d(
dims: [usize; 2],
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
Allocates a new CUDA Array that is up to 2-dimensions.
dims
contains the extents of the array. dims[0]
must be non-zero. The rank of the array
is equal to the number of non-zero dims
.
format
determines the data-type of the array.
num_channels
determines the number of channels per array element (1, 2, or 4).
use cust::memory::array::{ArrayObject, ArrayFormat};
// Allocates an 8x24 array of single-precision, single-channel floating point values.
let one_dim_array = ArrayObject::new_2d([8, 24], ArrayFormat::F32, 1)?;
sourcepub fn new_layered(
dims: [usize; 2],
num_layers: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
pub fn new_layered(
dims: [usize; 2],
num_layers: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
Creates a new Layered 1D or 2D CUDA Array.
dims
contains the extents of the array. dims[0]
must be non-zero. The rank of the array
is equivalent to the number of non-zero dimensions.
num_layers
determines the number of layers in the array.
format
determines the data-type of the array.
num_channels
determines the number of channels per array element (1, 2, or 4).
use cust::memory::array::{ArrayObject, ArrayFormat};
// Allocates a 7x8 array with 10 layers of single-precision, single-channel floating
// point values.
let layered_array = ArrayObject::new_layered([7, 8], 10, ArrayFormat::F32, 1)?;
sourcepub fn new_layered_1d(
width: usize,
num_layers: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
pub fn new_layered_1d(
width: usize,
num_layers: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
Creates a new Layered 1D CUDA Array.
width
must be non-zero.
num_layers
determines the number of layers in the array.
format
determines the data-type of the array.
num_channels
determines the number of channels per array element (1, 2, or 4).
use cust::memory::array::{ArrayObject, ArrayFormat};
// Allocates a 5-element array with 10 layers of single-precision, single-channel floating
// point values.
let layered_array = ArrayObject::new_layered_1d(5, 10, ArrayFormat::F32, 1)?;
sourcepub fn new_cubemap(
side: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
pub fn new_cubemap(
side: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
Creates a new Cubemap CUDA Array. The array is represented as 6 side x side 2D arrays.
side
is the length of an edge of the cube.
format
determines the data-type of the array.
num_channels
determines the number of channels per array element (1, 2, or 4).
use cust::memory::array::{ArrayObject, ArrayFormat};
// Allocates an 8x8 Cubemap array of single-precision, single-channel floating point
// numbers.
let layered_array = ArrayObject::new_cubemap(8, ArrayFormat::F32, 1)?;
// All non-layered cubemap arrays have a depth of 6.
assert_eq!(6, layered_array.descriptor()?.depth());
sourcepub fn new_layered_cubemap(
side: usize,
num_layers: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
pub fn new_layered_cubemap(
side: usize,
num_layers: usize,
format: ArrayFormat,
num_channels: c_uint
) -> CudaResult<Self>
Creates a new Layered Cubemap CUDA Array. The array is represented as multiple 6 side x side 2D arrays.
side
is the length of an edge of the cube.
num_layers
is the number of cubemaps in the array. The actual “depth” of the array is
num_layers * 6
.
format
determines the data-type of the array.
num_channels
determines the number of channels per array element (1, 2, or 4).
use cust::memory::array::{ArrayObject, ArrayFormat};
// Allocates an 8x8 Layered Cubemap array of single-precision, single-channel floating point
// values with 5 layers.
let layered_array = ArrayObject::new_layered_cubemap(8, 5, ArrayFormat::F32, 1)?;
// The depth of a layered cubemap array is equal to the number of layers * 6.
assert_eq!(30, layered_array.descriptor()?.depth());
sourcepub fn descriptor(&self) -> CudaResult<ArrayDescriptor>
pub fn descriptor(&self) -> CudaResult<ArrayDescriptor>
Gets the descriptor associated with this array.
sourcepub fn drop(array: ArrayObject) -> DropResult<ArrayObject>
pub fn drop(array: ArrayObject) -> DropResult<ArrayObject>
Try to destroy an ArrayObject
. Can fail - if it does, returns the CUDA error and the
un-destroyed array object
sourcepub fn copy_from<T: ArrayPrimitive, U: AsRef<[T]>>(
&mut self,
val: &U
) -> CudaResult<()>
pub fn copy_from<T: ArrayPrimitive, U: AsRef<[T]>>(
&mut self,
val: &U
) -> CudaResult<()>
Copy data from the host to the array on the device. This will not check if the formats match, it does however check for memory size mismatch.
For example, you can copy a [u32; 2]
value to a [u8; 8]
array just fine, but not to a [u8; 10]
array.
sourcepub fn copy_to<T: ArrayPrimitive, U: AsMut<[T]>>(
&self,
val: &mut U
) -> CudaResult<()>
pub fn copy_to<T: ArrayPrimitive, U: AsMut<[T]>>(
&self,
val: &mut U
) -> CudaResult<()>
Copy data from the array to the host. This will not check if the formats match, it does however check for memory size mismatch.
For example, you can copy a [u32; 2]
value to a [u8; 8]
array just fine, but not to a [u8; 10]
array.
sourcepub fn as_host_vec<T: ArrayPrimitive>(&self) -> CudaResult<Vec<T>>
pub fn as_host_vec<T: ArrayPrimitive>(&self) -> CudaResult<Vec<T>>
Copy data from the array into a vec on the host. This will not check if the formats match, it does however yield a correct vec. Format mismatch and especially format size mismatch may yield incorrect (but not unsound!) behavior
Trait Implementations
sourceimpl Debug for ArrayObject
impl Debug for ArrayObject
sourceimpl Drop for ArrayObject
impl Drop for ArrayObject
impl Send for ArrayObject
impl Sync for ArrayObject
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more