Skip to main content

KernelOpsDispatch

Struct KernelOpsDispatch 

Source
pub struct KernelOpsDispatch<'a> { /* private fields */ }
Expand description

Dispatch wrapper that tries KernelOps first, then falls back to TensorOps for operations that have a TensorOps equivalent.

This enables gradual migration: callers use the dispatch without caring which path actually runs.

Implementations§

Source§

impl<'a> KernelOpsDispatch<'a>

Source

pub fn new( kernel_ops: Option<&'a dyn KernelOps>, tensor_ops: &'a dyn TensorOps, ) -> Self

Source

pub fn rms_norm( &self, input: &TensorRef, weight: &TensorRef, eps: f32, ) -> Result<TensorRef>

RMS norm: prefer KernelOps::NormOps, fall back to TensorOps::rms_norm.

Source

pub fn gelu(&self, input: &TensorRef) -> Result<TensorRef>

GELU: prefer KernelOps::ActivationOps, fall back to TensorOps::gelu.

Source

pub fn silu(&self, input: &TensorRef) -> Result<TensorRef>

SiLU: prefer KernelOps::ActivationOps::silu_mul is fused so there is no direct TensorOps equivalent. This helper exposes the non-fused TensorOps::silu for callers that only need plain SiLU.

Source

pub fn silu_mul(&self, gate: &TensorRef, up: &TensorRef) -> Result<TensorRef>

Fused SiLU-multiply (SwiGLU building block). Falls back to silu(gate) * up via TensorOps when kernel is unavailable.

Source

pub fn linear(&self, input: &TensorRef, weight: &TensorRef) -> Result<TensorRef>

Dense linear (no bias). Falls back to TensorOps::matmul.

Source

pub fn softmax(&self, input: &TensorRef, dim: i32) -> Result<TensorRef>

Softmax: always via TensorOps (no kernel sub-trait for plain softmax).

Source

pub fn kernel_ops(&self) -> Option<&'a dyn KernelOps>

Access the underlying KernelOps (if any) for ops that have no TensorOps fallback (e.g. rotary_embedding, attention, sampling).

Source

pub fn tensor_ops(&self) -> &'a dyn TensorOps

Access the underlying TensorOps.

Auto Trait Implementations§

§

impl<'a> Freeze for KernelOpsDispatch<'a>

§

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

§

impl<'a> Send for KernelOpsDispatch<'a>

§

impl<'a> Sync for KernelOpsDispatch<'a>

§

impl<'a> Unpin for KernelOpsDispatch<'a>

§

impl<'a> UnsafeUnpin for KernelOpsDispatch<'a>

§

impl<'a> !UnwindSafe for KernelOpsDispatch<'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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V