Skip to main content

DevSliceArg

Trait DevSliceArg 

Source
pub trait DevSliceArg:
    Send
    + Sync
    + 'static {
    // Required methods
    fn validate(&self) -> Result<Box<dyn Any + Send>, GpuError>;
    fn push<'a>(&'a self, builder: &mut LaunchArgs<'a>) -> Result<(), GpuError>;
    fn dtype(&self) -> Option<DType>;
    fn len(&self) -> usize;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Type-erased typed-device-slice argument for an NVRTC kernel launch.

Boxed as Box<dyn DevSliceArg> inside KernelArg::DevSlice so the per-launch Vec<KernelArg> does not need one variant per dtype. The blanket impl impl<T: CudaDtype> DevSliceArg for GpuRef<T> covers every dtype the runtime understands; raw byte buffers (GpuRef<u8>) are handled by the same impl because u8 is a CudaDtype.

§Object safety

Methods take &self and never return Self so the trait is usable as dyn DevSliceArg.

Required Methods§

Source

fn validate(&self) -> Result<Box<dyn Any + Send>, GpuError>

Validate the underlying GpuRef and return a keep-alive owner. The caller stores this Box<dyn Any + Send> in a Vec to keep the device buffer alive until the kernel completes.

Source

fn push<'a>(&'a self, builder: &mut LaunchArgs<'a>) -> Result<(), GpuError>

Push the device-pointer reference onto builder. Implementors re-access() the GpuRef (cheap — pointer-equality check against DeviceState.generation) and call [PushKernelArg::arg] with &CudaSlice<T>.

The 'a lifetime ties &self to the builder so the pushed device-pointer reference is borrowed from Self for as long as builder lives.

Returns Err(GpuError::GpuRefStale) if the buffer has gone stale between validate and push (rare — only happens if a context rebuild raced inside the actor).

Source

fn dtype(&self) -> Option<DType>

Element dtype for tracing / debugging. Always Some(..) for the default GpuRef<T: CudaDtype> impl.

Source

fn len(&self) -> usize

Length of the underlying slice in elements.

Provided Methods§

Source

fn is_empty(&self) -> bool

True iff the slice has zero elements.

Implementors§

Source§

impl<T> DevSliceArg for GpuRef<T>
where T: CudaDtype,