pub struct KernelParameters<'a> { /* private fields */ }Expand description
Dynamically built CUDA kernel argument list.
Use this builder when the argument list depends on runtime conditions:
let mut params = KernelParameters::new();
params.arg(&input_ptr).arg(&output_ptr).push(len);
// SAFETY: the buffers match the kernel's parameters and outlive the launch.
unsafe { function.launch_async(&config, params, &stream)? };For fixed argument lists, passing a tuple of references directly to KernelFunction::launch_async avoids building a dynamic list:
// SAFETY: the buffers match the kernel's parameters and outlive the launch.
unsafe { function.launch_async(&config, (&input_ptr, &mut output_ptr, &len), &stream)? };Borrowed arguments are tied to the lifetime of this list.
Owned scalar and pointer arguments pushed with Self::push or Self::owned_arg are stored inline when they fit, so ordinary kernel launches do not allocate per argument.
Implementations§
Source§impl<'a> KernelParameters<'a>
impl<'a> KernelParameters<'a>
Sourcepub fn arg<T: 'a>(&mut self, value: &'a T) -> &mut Self
pub fn arg<T: 'a>(&mut self, value: &'a T) -> &mut Self
Appends a borrowed argument value without converting its Rust representation.
The value stays borrowed for this list’s lifetime. If it contains a device pointer, the borrow covers the pointer value rather than the pointed-to allocation.
Sourcepub fn arg_mut<T: 'a>(&mut self, value: &'a mut T) -> &mut Self
pub fn arg_mut<T: 'a>(&mut self, value: &'a mut T) -> &mut Self
Appends an exclusively borrowed argument value without converting its Rust representation.
CUDA reads the value as a kernel argument; this does not request a write back to the host argument slot. A pointer argument still needs the pointee lifetime and access guarantees required by the launch.
Sourcepub fn owned_arg<T: Copy + 'static>(&mut self, value: T) -> &mut Self
pub fn owned_arg<T: Copy + 'static>(&mut self, value: T) -> &mut Self
Pushes a copied kernel argument whose storage is owned by this list.
Small scalar and pointer values are stored inline. Larger values fall back to heap storage, while keeping the argument pointee stable until CUDA has copied it during launch or graph-node creation.
Sourcepub fn push<A: PushKernelArg>(&mut self, arg: A) -> &mut Self
pub fn push<A: PushKernelArg>(&mut self, arg: A) -> &mut Self
Appends an argument using its PushKernelArg implementation to encode the kernel ABI value.
Sourcepub fn device_input<T: DeviceRepr, S: DeviceRange<T> + ?Sized>(
&mut self,
slice: &S,
) -> &mut Self
pub fn device_input<T: DeviceRepr, S: DeviceRange<T> + ?Sized>( &mut self, slice: &S, ) -> &mut Self
Encodes a device input address, including deferred graph inputs.
This copies metadata only. The launch contract determines when the pointed-to values must be initialized and how access is ordered.
Sourcepub fn device_slice_mut<T: DeviceRepr, S: DeviceSliceMut<T> + ?Sized>(
&mut self,
slice: &mut S,
) -> &mut Self
pub fn device_slice_mut<T: DeviceRepr, S: DeviceSliceMut<T> + ?Sized>( &mut self, slice: &mut S, ) -> &mut Self
Appends a copied device address for a mutable slice.
This does not append the slice length or retain the allocation. Keep the allocation alive and preserve exclusive writable access for every execution that uses the copied pointer.