Trait KernelExecutor

Source
pub trait KernelExecutor<F> {
    type Mem: ComputeMemory<F>;
    type Value;
    type ExprEval: Sync;

    // Required methods
    fn decl_value(&mut self, init: F) -> Result<Self::Value, Error>;
    fn sum_composition_evals(
        &mut self,
        inputs: &SlicesBatch<<Self::Mem as ComputeMemory<F>>::FSlice<'_>>,
        composition: &Self::ExprEval,
        batch_coeff: F,
        accumulator: &mut Self::Value,
    ) -> Result<(), Error>;
    fn add(
        &mut self,
        log_len: usize,
        src1: <Self::Mem as ComputeMemory<F>>::FSlice<'_>,
        src2: <Self::Mem as ComputeMemory<F>>::FSlice<'_>,
        dst: &mut <Self::Mem as ComputeMemory<F>>::FSliceMut<'_>,
    ) -> Result<(), Error>;
    fn add_assign(
        &mut self,
        log_len: usize,
        src: <Self::Mem as ComputeMemory<F>>::FSlice<'_>,
        dst: &mut <Self::Mem as ComputeMemory<F>>::FSliceMut<'_>,
    ) -> Result<(), Error>;
}
Expand description

An interface for defining execution kernels.

A kernel is a program that executes synchronously in one thread, with access to local memory buffers.

See ComputeLayer::accumulate_kernels for more information.

Required Associated Types§

Source

type Mem: ComputeMemory<F>

The type for kernel-local memory buffers.

Source

type Value

The kernel(core)-level operation (scalar) type. This is a promise for a returned value.

Source

type ExprEval: Sync

The evaluator for arithmetic expressions (polynomials).

Required Methods§

Source

fn decl_value(&mut self, init: F) -> Result<Self::Value, Error>

Declares a kernel-level value.

Source

fn sum_composition_evals( &mut self, inputs: &SlicesBatch<<Self::Mem as ComputeMemory<F>>::FSlice<'_>>, composition: &Self::ExprEval, batch_coeff: F, accumulator: &mut Self::Value, ) -> Result<(), Error>

A kernel-local operation that evaluates a composition polynomial over several buffers, row-wise, and returns the sum of the evaluations, scaled by a batching coefficient.

Mathematically, let there be $m$ input buffers, $P_0, \ldots, P_{m-1}$, each of length $2^n$ elements. Let $c$ be the scaling coefficient (batch_coeff) and $C(X_0, \ldots, X_{m-1})$ be the composition polynomial. The operation computes

$$ \sum_{i=0}^{2^n - 1} c C(P_0[i], \ldots, P_{m-1}[i]). $$

The result is added back to an accumulator value.

§Arguments
  • log_len - the binary logarithm of the number of elements in each input buffer.
  • inputs - the input buffers. Each row contains the values for a single variable.
  • composition - the compiled composition polynomial expression. This is an output of ComputeLayer::compile_expr.
  • batch_coeff - the scaling coefficient.
  • accumulator - the output where the result is accumulated to.
Source

fn add( &mut self, log_len: usize, src1: <Self::Mem as ComputeMemory<F>>::FSlice<'_>, src2: <Self::Mem as ComputeMemory<F>>::FSlice<'_>, dst: &mut <Self::Mem as ComputeMemory<F>>::FSliceMut<'_>, ) -> Result<(), Error>

A kernel-local operation that performs point-wise addition of two input buffers into an output buffer.

§Arguments
  • log_len - the binary logarithm of the number of elements in all three buffers.
  • src1 - the first input buffer.
  • src2 - the second input buffer.
  • dst - the output buffer that receives the element-wise sum.
Source

fn add_assign( &mut self, log_len: usize, src: <Self::Mem as ComputeMemory<F>>::FSlice<'_>, dst: &mut <Self::Mem as ComputeMemory<F>>::FSliceMut<'_>, ) -> Result<(), Error>

A kernel-local operation that adds a source buffer into a destination buffer, in place.

§Arguments
  • log_len - the binary logarithm of the number of elements in the two buffers.
  • src - the source buffer.
  • dst - the destination buffer.

Implementors§