Skip to main content

Backend

Trait Backend 

Source
pub trait Backend {
    // Required methods
    fn add(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>;
    fn mul(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>;
    fn matmul(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>;
    fn sum_all(a: &Tensor) -> EtensorResult<Tensor>;
    fn mean_all(a: &Tensor) -> EtensorResult<Tensor>;
    fn max_all(a: &Tensor) -> EtensorResult<Tensor>;
    fn relu(a: &Tensor) -> EtensorResult<Tensor>;
    fn sigmoid(a: &Tensor) -> EtensorResult<Tensor>;
    fn add_relu(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>;
    fn linear(x: &Tensor, w: &Tensor, b: &Tensor) -> EtensorResult<Tensor>;
}
Expand description

The foundational contract that all physical hardware backends must fulfill.

Required Methods§

Source

fn add(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>

Executes an element-wise addition (a + b) and returns a dynamically allocated output tensor.

Source

fn mul(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>

Executes an element-wise multiplication (a * b) and returns a dynamically allocated output tensor.

Source

fn matmul(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>

Executes matrix multiplication (a @ b) and returns a dynamically allocated output tensor.

Source

fn sum_all(a: &Tensor) -> EtensorResult<Tensor>

Executes a global sum reduction, collapsing the tensor into a single scalar.

Source

fn mean_all(a: &Tensor) -> EtensorResult<Tensor>

Executes a global mean reduction, collapsing the tensor into a single scalar.

Source

fn max_all(a: &Tensor) -> EtensorResult<Tensor>

Executes a global max reduction, collapsing the tensor into a single scalar.

Source

fn relu(a: &Tensor) -> EtensorResult<Tensor>

Executes the Rectified Linear Unit (ReLU) activation function.

Source

fn sigmoid(a: &Tensor) -> EtensorResult<Tensor>

Executes the Sigmoid activation function.

Source

fn add_relu(a: &Tensor, b: &Tensor) -> EtensorResult<Tensor>

Executes Fused Addition and ReLU: f(A, B) = max(0, A + B)

Source

fn linear(x: &Tensor, w: &Tensor, b: &Tensor) -> EtensorResult<Tensor>

Executes Fused Linear Layer: y = X @ W + b

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§