Skip to main content

KernelParameters

Struct KernelParameters 

Source
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>

Source

pub const fn new() -> Self

Creates an empty kernel argument list.

Source

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.

Source

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.

Source

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.

Source

pub fn push<A: PushKernelArg>(&mut self, arg: A) -> &mut Self

Appends an argument using its PushKernelArg implementation to encode the kernel ABI value.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for KernelParameters<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for KernelParameters<'_>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a> KernelLaunchArgs<'a> for KernelParameters<'a>

Source§

impl<'a> KernelLaunchArgs<'a> for &mut KernelParameters<'a>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for KernelParameters<'a>

§

impl<'a> !Send for KernelParameters<'a>

§

impl<'a> !Sync for KernelParameters<'a>

§

impl<'a> !UnwindSafe for KernelParameters<'a>

§

impl<'a> Forget for KernelParameters<'a>

§

impl<'a> Freeze for KernelParameters<'a>

§

impl<'a> Move for KernelParameters<'a>

§

impl<'a> Unpin for KernelParameters<'a>

§

impl<'a> UnsafeUnpin for KernelParameters<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.