Trait ComputeLayer

Source
pub trait ComputeLayer<F: Field> {
    type DevMem: ComputeMemory<F>;
    type Exec<'a>: ComputeLayerExecutor<F, DevMem = Self::DevMem>
       where Self: 'a;

    // Required methods
    fn copy_h2d(
        &self,
        src: &[F],
        dst: &mut FSliceMut<'_, F, Self>,
    ) -> Result<(), Error>;
    fn copy_d2h(
        &self,
        src: FSlice<'_, F, Self>,
        dst: &mut [F],
    ) -> Result<(), Error>;
    fn copy_d2d(
        &self,
        src: FSlice<'_, F, Self>,
        dst: &mut FSliceMut<'_, F, Self>,
    ) -> Result<(), Error>;
    fn compile_expr(
        &self,
        expr: &ArithCircuit<F>,
    ) -> Result<<Self::Exec<'_> as ComputeLayerExecutor<F>>::ExprEval, Error>;
    fn execute<'a, 'b>(
        &'b self,
        f: impl FnOnce(&mut Self::Exec<'a>) -> Result<Vec<<Self::Exec<'a> as ComputeLayerExecutor<F>>::OpValue>, Error>,
    ) -> Result<Vec<F>, Error>
       where 'b: 'a;
    fn fill(
        &self,
        slice: &mut <Self::DevMem as ComputeMemory<F>>::FSliceMut<'_>,
        value: F,
    ) -> Result<(), Error>;
}
Expand description

A hardware abstraction layer (HAL) for compute operations.

Required Associated Types§

Source

type DevMem: ComputeMemory<F>

The device memory.

Source

type Exec<'a>: ComputeLayerExecutor<F, DevMem = Self::DevMem> where Self: 'a

The executor that can execute operations on the device.

Required Methods§

Source

fn copy_h2d( &self, src: &[F], dst: &mut FSliceMut<'_, F, Self>, ) -> Result<(), Error>

Copy data from the host to the device.

§Preconditions
  • src and dst must have the same length.
Source

fn copy_d2h(&self, src: FSlice<'_, F, Self>, dst: &mut [F]) -> Result<(), Error>

Copy data from the device to the host.

§Preconditions
  • src and dst must have the same length.
Source

fn copy_d2d( &self, src: FSlice<'_, F, Self>, dst: &mut FSliceMut<'_, F, Self>, ) -> Result<(), Error>

Copy data between disjoint device buffers.

§Preconditions
  • src and dst must have the same length.
Source

fn compile_expr( &self, expr: &ArithCircuit<F>, ) -> Result<<Self::Exec<'_> as ComputeLayerExecutor<F>>::ExprEval, Error>

Compiles an arithmetic expression to the evaluator.

Source

fn execute<'a, 'b>( &'b self, f: impl FnOnce(&mut Self::Exec<'a>) -> Result<Vec<<Self::Exec<'a> as ComputeLayerExecutor<F>>::OpValue>, Error>, ) -> Result<Vec<F>, Error>
where 'b: 'a,

Executes an operation.

A HAL operation is an abstract function that runs with an executor reference.

Source

fn fill( &self, slice: &mut <Self::DevMem as ComputeMemory<F>>::FSliceMut<'_>, value: F, ) -> Result<(), Error>

Fills a mutable slice of field elements with a given value.

This operation takes a mutable slice (FSliceMut<F>) and a field element value, and sets each element in the slice to the given value.

§Arguments
  • slice - A mutable slice of field elements to be filled.
  • value - The field element used to fill each position in the slice.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§