pub struct DeviceArray<T: CugraphElement> { /* private fields */ }Expand description
An owning device (GPU) array with compile-time element type T.
Allocates GPU memory on creation and frees it on drop. Create a
DeviceArrayView via view() for zero-copy access.
§Example
let runtime = std::sync::Arc::new(Runtime::new().unwrap());
let handle =
ResourceHandle::for_runtime(std::sync::Arc::clone(&runtime)).unwrap();
let entered = handle.enter("DeviceArray docs").unwrap();
let arr = DeviceArray::from_slice(&entered, &[0i32, 1, 2]).unwrap();
let ids: Vec<i32> = arr.view().unwrap().to_vec(&entered).unwrap();
assert_eq!(ids, vec![0, 1, 2]);Implementations§
Source§impl<T: CugraphElement> DeviceArray<T>
impl<T: CugraphElement> DeviceArray<T>
Sourcepub fn new(handle: &EnteredContext<'_>, len: usize) -> Result<Self>
pub fn new(handle: &EnteredContext<'_>, len: usize) -> Result<Self>
Allocate a new device array with len elements of type T.
Sourcepub fn from_slice(handle: &EnteredContext<'_>, data: &[T]) -> Result<Self>
pub fn from_slice(handle: &EnteredContext<'_>, data: &[T]) -> Result<Self>
Create a device array from a host slice, copying the data to the GPU.
This is the primary constructor for typed device arrays.
§Example
let runtime = std::sync::Arc::new(Runtime::new().unwrap());
let handle =
ResourceHandle::for_runtime(std::sync::Arc::clone(&runtime)).unwrap();
let entered = handle.enter("DeviceArray::from_slice docs").unwrap();
let arr = DeviceArray::from_slice(&entered, &[1i32, 2, 3]).unwrap();
assert_eq!(arr.view().unwrap().len(), 3);Sourcepub fn view(&self) -> Result<DeviceArrayView<'_, T>>
pub fn view(&self) -> Result<DeviceArrayView<'_, T>>
Create a non-owning typed view of this array.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for DeviceArray<T>
impl<T> !Send for DeviceArray<T>
impl<T> !Sync for DeviceArray<T>
impl<T> !UnwindSafe for DeviceArray<T>
impl<T> Freeze for DeviceArray<T>where
PhantomData<T>: Freeze,
impl<T> Unpin for DeviceArray<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for DeviceArray<T>where
PhantomData<T>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more