pub struct CudaSlice<T> { /* private fields */ }
Expand description
Contains a reference counted pointer to both
device and host memory allocated for type T
.
Host data
This owns the host data it is associated with. However it is possible to create device memory without having a corresponding host memory, so the host memory is actually Option.
Reclaiming host data
To reclaim the host data for this device data, use CudaDevice::sync_reclaim(). This will perform necessary synchronization to ensure that the device data finishes copying over.
Mutating device data
This can only be done by launching kernels via
crate::driver::LaunchAsync which is implemented
by CudaDevice. Pass &mut CudaSlice<T>
if you want to mutate the rc, and &CudaSlice<T>
otherwise.
Unfortunately, &CudaSlice<T>
can still be mutated
by the CudaFunction.
Implementations§
source§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
sourcepub fn leak(self) -> CUdeviceptr
pub fn leak(self) -> CUdeviceptr
Takes ownership of the underlying sys::CUdeviceptr. It is up to the owner to free this value.
Drops the underlying host_buf if there is one.
source§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
sourcepub fn device(&self) -> Arc<CudaDevice>
pub fn device(&self) -> Arc<CudaDevice>
Get a clone of the underlying CudaDevice.
source§impl<T: DeviceRepr> CudaSlice<T>
impl<T: DeviceRepr> CudaSlice<T>
sourcepub fn try_clone(&self) -> Result<Self, DriverError>
pub fn try_clone(&self) -> Result<Self, DriverError>
Allocates copy of self and schedules a device to device copy of memory.
source§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
sourcepub fn slice(&self, range: impl RangeBounds<usize>) -> CudaView<'_, T>
pub fn slice(&self, range: impl RangeBounds<usize>) -> CudaView<'_, T>
Creates a CudaView at the specified offset from the start of self
.
Returns None
if range.start >= self.len
sourcepub fn try_slice(
&self,
range: impl RangeBounds<usize>
) -> Option<CudaView<'_, T>>
pub fn try_slice( &self, range: impl RangeBounds<usize> ) -> Option<CudaView<'_, T>>
Fallible version of CudaSlice::slice
sourcepub unsafe fn transmute<S>(&self, len: usize) -> Option<CudaView<'_, S>>
pub unsafe fn transmute<S>(&self, len: usize) -> Option<CudaView<'_, S>>
Reinterprets the slice of memory into a different type. len
is the number
of elements of the new type S
that are expected. If not enough bytes
are allocated in self
for the view, then this returns None
.
Safety
This is unsafe because not the memory for the view may not be a valid interpretation
for the type S
.
source§impl<T> CudaSlice<T>
impl<T> CudaSlice<T>
sourcepub fn slice_mut(
&mut self,
range: impl RangeBounds<usize>
) -> CudaViewMut<'_, T>
pub fn slice_mut( &mut self, range: impl RangeBounds<usize> ) -> CudaViewMut<'_, T>
Creates a CudaViewMut at the specified offset from the start of self
.
Returns None
if offset >= self.len
sourcepub fn try_slice_mut(
&mut self,
range: impl RangeBounds<usize>
) -> Option<CudaViewMut<'_, T>>
pub fn try_slice_mut( &mut self, range: impl RangeBounds<usize> ) -> Option<CudaViewMut<'_, T>>
Fallible version of CudaSlice::slice_mut
sourcepub unsafe fn transmute_mut<S>(
&mut self,
len: usize
) -> Option<CudaViewMut<'_, S>>
pub unsafe fn transmute_mut<S>( &mut self, len: usize ) -> Option<CudaViewMut<'_, S>>
Reinterprets the slice of memory into a different type. len
is the number
of elements of the new type S
that are expected. If not enough bytes
are allocated in self
for the view, then this returns None
.
Safety
This is unsafe because not the memory for the view may not be a valid interpretation
for the type S
.