pub enum KernelArgs<const N: usize> {
    Index1D(usize),
    IndexND([usize; N]),
    Handle,
}
Expand description

Kernel argument enum

In the Kokkos library, there is a finite number of kernel signatures. Each is associated to/determined by a given execution policy. In order to have kernel genericity in Rust, without introducing overhead due to downcasting, the solution was to define kernel arguments as a struct-like enum.

Example

One-dimensional kernel:

// Range is defined in the execution policy
use poc_kokkos_rs::functor::KernelArgs;

let kern = |arg: KernelArgs<1>| match arg {
        KernelArgs::Index1D(i) => {
            // body of the kernel
            println!("Hello from iteration {i}")
        },
        KernelArgs::IndexND(_) => unimplemented!(),
        KernelArgs::Handle => unimplemented!(),
    };

3D kernel:

use poc_kokkos_rs::functor::KernelArgs;

// Use the array
let kern = |arg: KernelArgs<3>| match arg {
        KernelArgs::Index1D(_) => unimplemented!(),
        KernelArgs::IndexND(idx) => { // idx: [usize; 3]
            // body of the kernel
            println!("Hello from iteration {idx:?}")
        },
        KernelArgs::Handle => unimplemented!(),
    };

// Decompose the array
let kern = |arg: KernelArgs<3>| match arg {
        KernelArgs::Index1D(_) => unimplemented!(),
        KernelArgs::IndexND([i, j, k]) => { // i,j,k: usize
            // body of the kernel
            println!("Hello from iteration {i},{j},{k}");
        },
        KernelArgs::Handle => unimplemented!(),
    };

Variants§

§

Index1D(usize)

Arguments of a one-dimensionnal kernel (e.g. a RangePolicy).

§

IndexND([usize; N])

Arguments of a N-dimensionnal kernel (e.g. a MDRangePolicy).

§

Handle

Arguments of a team-based kernel.

Auto Trait Implementations§

§

impl<const N: usize> RefUnwindSafe for KernelArgs<N>

§

impl<const N: usize> Send for KernelArgs<N>

§

impl<const N: usize> Sync for KernelArgs<N>

§

impl<const N: usize> Unpin for KernelArgs<N>

§

impl<const N: usize> UnwindSafe for KernelArgs<N>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.