pub struct DeviceView<'a, T: DeviceRepr> { /* private fields */ }Expand description
An immutable borrow of typed CUDA storage, including its allocation identity.
Implementations§
Source§impl<'a, T: DeviceRepr> DeviceView<'a, T>
impl<'a, T: DeviceRepr> DeviceView<'a, T>
Sourcepub fn into_region(self) -> DeviceRegion<'a>
pub fn into_region(self) -> DeviceRegion<'a>
Consumes the typed borrow into allocation metadata without granting new access.
Sourcepub unsafe fn from_raw_parts(
region: DeviceRegion<'a>,
length: usize,
) -> Result<Self>
pub unsafe fn from_raw_parts( region: DeviceRegion<'a>, length: usize, ) -> Result<Self>
Borrows a region containing length values of T.
§Safety
The region must contain valid T values for the returned lifetime.
Access through other aliases must respect this shared borrow and CUDA ordering.
§Errors
Returns an error if length * size_of::<T>() overflows or differs from the region’s byte length, or a nonempty region has a zero-sized element type or insufficient alignment.
Sourcepub fn from_memory(memory: &'a DeviceMemory<T>) -> Self
pub fn from_memory(memory: &'a DeviceMemory<T>) -> Self
Borrows every initialized element of a device allocation without copying data.
Sourcepub fn from_buffer<B: DeviceSlice<T> + ?Sized>(buffer: &'a B) -> Self
pub fn from_buffer<B: DeviceSlice<T> + ?Sized>(buffer: &'a B) -> Self
Borrows any typed provider that also retains allocation metadata.
Sourcepub fn as_ptr(&self) -> *const T
pub fn as_ptr(&self) -> *const T
Returns the CUDA-accessible element pointer.
An empty view returns an aligned dangling pointer. This pointer does not grant host access.
Sourcepub fn context(&self) -> &'a Arc<Context> ⓘ
pub fn context(&self) -> &'a Arc<Context> ⓘ
Returns the context associated with the viewed allocation.
Sourcepub const fn region(&self) -> DeviceRegion<'a>
pub const fn region(&self) -> DeviceRegion<'a>
Returns the view’s exact byte range and allocation identity.
Sourcepub fn copy_to_host(&self, destination: &mut [T]) -> Result<()>where
T: AnyBitPatternDeviceRepr,
pub fn copy_to_host(&self, destination: &mut [T]) -> Result<()>where
T: AnyBitPatternDeviceRepr,
Copies every viewed element into a host slice and waits for completion.
§Errors
Returns an error for unequal element counts or byte-size overflow. Also propagates access-tracking, readiness synchronization, context binding, stream-capture, CUDA copy, and stream synchronization errors. A nonempty synchronous transfer is rejected during stream capture.
Sourcepub fn copy_to_host_vec(&self) -> Result<Vec<T>>where
T: AnyBitPatternDeviceRepr,
pub fn copy_to_host_vec(&self) -> Result<Vec<T>>where
T: AnyBitPatternDeviceRepr,
Copies every viewed element into a new host vector and waits for completion.
§Errors
Propagates byte-size overflow, access-tracking, readiness synchronization, context-binding, stream-capture, CUDA copy, and stream synchronization errors. A nonempty synchronous transfer is rejected during stream capture.
Sourcepub fn slice<R: RangeBounds<usize>>(self, range: R) -> Result<Self>
pub fn slice<R: RangeBounds<usize>>(self, range: R) -> Result<Self>
Returns a view of an element subrange, preserving allocation identity and readiness.
§Errors
Returns an error if the element range is reversed, exceeds this range’s bounds, or an inclusive bound cannot be converted without overflow.
Sourcepub fn cast<U: AnyBitPatternDeviceRepr>(self) -> Result<DeviceView<'a, U>>where
T: NoUninitDeviceRepr,
pub fn cast<U: AnyBitPatternDeviceRepr>(self) -> Result<DeviceView<'a, U>>where
T: NoUninitDeviceRepr,
Reinterprets initialized bytes as values accepting every bit pattern.
§Errors
Returns an error if U is zero-sized, the region’s byte length is not divisible by size_of::<U>(), or a nonempty region is not aligned for U.
Sourcepub unsafe fn cast_unchecked<U: DeviceRepr>(self) -> Result<DeviceView<'a, U>>
pub unsafe fn cast_unchecked<U: DeviceRepr>(self) -> Result<DeviceView<'a, U>>
Reinterprets a region with a caller-established initialization contract.
§Safety
Every destination element must be initialized and valid for U.
Alignment and byte length are checked by this method.
§Errors
Returns an error if U is zero-sized, the region’s byte length is not divisible by size_of::<U>(), or a nonempty region is not aligned for U.