Skip to main content

TensorBackend

Trait TensorBackend 

Source
pub trait TensorBackend {
Show 54 methods // Required methods fn add(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>; fn mul(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>; fn neg(&mut self, input: &Tensor) -> Result<Tensor>; fn conj(&mut self, input: &Tensor) -> Result<Tensor>; fn div(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>; fn abs(&mut self, input: &Tensor) -> Result<Tensor>; fn sign(&mut self, input: &Tensor) -> Result<Tensor>; fn maximum(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>; fn minimum(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>; fn compare( &mut self, lhs: &Tensor, rhs: &Tensor, dir: &CompareDir, ) -> Result<Tensor>; fn select( &mut self, pred: &Tensor, on_true: &Tensor, on_false: &Tensor, ) -> Result<Tensor>; fn clamp( &mut self, input: &Tensor, lower: &Tensor, upper: &Tensor, ) -> Result<Tensor>; fn exp(&mut self, input: &Tensor) -> Result<Tensor>; fn log(&mut self, input: &Tensor) -> Result<Tensor>; fn sin(&mut self, input: &Tensor) -> Result<Tensor>; fn cos(&mut self, input: &Tensor) -> Result<Tensor>; fn tanh(&mut self, input: &Tensor) -> Result<Tensor>; fn sqrt(&mut self, input: &Tensor) -> Result<Tensor>; fn rsqrt(&mut self, input: &Tensor) -> Result<Tensor>; fn pow(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>; fn expm1(&mut self, input: &Tensor) -> Result<Tensor>; fn log1p(&mut self, input: &Tensor) -> Result<Tensor>; fn transpose(&mut self, input: &Tensor, perm: &[usize]) -> Result<Tensor>; fn reshape(&mut self, input: &Tensor, shape: &[usize]) -> Result<Tensor>; fn broadcast_in_dim( &mut self, input: &Tensor, shape: &[usize], dims: &[usize], ) -> Result<Tensor>; fn convert(&mut self, input: &Tensor, to: DType) -> Result<Tensor>; fn extract_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>; fn embed_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>; fn tril(&mut self, input: &Tensor, k: i64) -> Result<Tensor>; fn triu(&mut self, input: &Tensor, k: i64) -> Result<Tensor>; fn reduce_sum(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>; fn reduce_prod(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>; fn reduce_max(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>; fn reduce_min(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>; fn dot_general( &mut self, lhs: &Tensor, rhs: &Tensor, config: &DotGeneralConfig, ) -> Result<Tensor>; fn gather( &mut self, operand: &Tensor, start_indices: &Tensor, config: &GatherConfig, ) -> Result<Tensor>; fn scatter( &mut self, operand: &Tensor, scatter_indices: &Tensor, updates: &Tensor, config: &ScatterConfig, ) -> Result<Tensor>; fn slice(&mut self, input: &Tensor, config: &SliceConfig) -> Result<Tensor>; fn dynamic_slice( &mut self, input: &Tensor, starts: &Tensor, slice_sizes: &[usize], ) -> Result<Tensor>; fn pad(&mut self, input: &Tensor, config: &PadConfig) -> Result<Tensor>; fn concatenate(&mut self, inputs: &[&Tensor], axis: usize) -> Result<Tensor>; fn reverse(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>; fn cholesky(&mut self, input: &Tensor) -> Result<Tensor>; fn triangular_solve( &mut self, a: &Tensor, b: &Tensor, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<Tensor>; fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>; fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>; fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>; fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>; fn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>>; fn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor>; // Provided methods fn with_exec_session<R: Send>( &mut self, f: impl FnOnce(&mut dyn TensorExec) -> R + Send, ) -> R { ... } fn download_to_host(&mut self, tensor: &Tensor) -> Result<Tensor> { ... } fn upload_host_tensor(&mut self, tensor: &Tensor) -> Result<Tensor> { ... } fn reclaim_buffer(&mut self, _tensor: Tensor) { ... }
}
Expand description

Standard runtime backend over dynamic Tensor values.

§Examples

use tenferro_tensor::{cpu::CpuBackend, TensorBackend};

let mut backend = CpuBackend::new();

Required Methods§

Source

fn add(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>

Source

fn mul(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>

Source

fn neg(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn conj(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn div(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>

Source

fn abs(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn sign(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn maximum(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>

Source

fn minimum(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>

Source

fn compare( &mut self, lhs: &Tensor, rhs: &Tensor, dir: &CompareDir, ) -> Result<Tensor>

Source

fn select( &mut self, pred: &Tensor, on_true: &Tensor, on_false: &Tensor, ) -> Result<Tensor>

Source

fn clamp( &mut self, input: &Tensor, lower: &Tensor, upper: &Tensor, ) -> Result<Tensor>

Source

fn exp(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn log(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn sin(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn cos(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn tanh(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn sqrt(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn rsqrt(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn pow(&mut self, lhs: &Tensor, rhs: &Tensor) -> Result<Tensor>

Source

fn expm1(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn log1p(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn transpose(&mut self, input: &Tensor, perm: &[usize]) -> Result<Tensor>

Source

fn reshape(&mut self, input: &Tensor, shape: &[usize]) -> Result<Tensor>

Source

fn broadcast_in_dim( &mut self, input: &Tensor, shape: &[usize], dims: &[usize], ) -> Result<Tensor>

Source

fn convert(&mut self, input: &Tensor, to: DType) -> Result<Tensor>

Source

fn extract_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Source

fn embed_diagonal( &mut self, input: &Tensor, axis_a: usize, axis_b: usize, ) -> Result<Tensor>

Source

fn tril(&mut self, input: &Tensor, k: i64) -> Result<Tensor>

Source

fn triu(&mut self, input: &Tensor, k: i64) -> Result<Tensor>

Source

fn reduce_sum(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>

Source

fn reduce_prod(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>

Source

fn reduce_max(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>

Source

fn reduce_min(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>

Source

fn dot_general( &mut self, lhs: &Tensor, rhs: &Tensor, config: &DotGeneralConfig, ) -> Result<Tensor>

Source

fn gather( &mut self, operand: &Tensor, start_indices: &Tensor, config: &GatherConfig, ) -> Result<Tensor>

Source

fn scatter( &mut self, operand: &Tensor, scatter_indices: &Tensor, updates: &Tensor, config: &ScatterConfig, ) -> Result<Tensor>

Source

fn slice(&mut self, input: &Tensor, config: &SliceConfig) -> Result<Tensor>

Source

fn dynamic_slice( &mut self, input: &Tensor, starts: &Tensor, slice_sizes: &[usize], ) -> Result<Tensor>

Source

fn pad(&mut self, input: &Tensor, config: &PadConfig) -> Result<Tensor>

Source

fn concatenate(&mut self, inputs: &[&Tensor], axis: usize) -> Result<Tensor>

Source

fn reverse(&mut self, input: &Tensor, axes: &[usize]) -> Result<Tensor>

Source

fn cholesky(&mut self, input: &Tensor) -> Result<Tensor>

Source

fn triangular_solve( &mut self, a: &Tensor, b: &Tensor, left_side: bool, lower: bool, transpose_a: bool, unit_diagonal: bool, ) -> Result<Tensor>

Source

fn lu(&mut self, input: &Tensor) -> Result<Vec<Tensor>>

Source

fn svd(&mut self, input: &Tensor) -> Result<Vec<Tensor>>

Source

fn qr(&mut self, input: &Tensor) -> Result<Vec<Tensor>>

Source

fn eigh(&mut self, input: &Tensor) -> Result<Vec<Tensor>>

Source

fn eig(&mut self, input: &Tensor) -> Result<Vec<Tensor>>

Source

fn solve(&mut self, a: &Tensor, b: &Tensor) -> Result<Tensor>

Provided Methods§

Source

fn with_exec_session<R: Send>( &mut self, f: impl FnOnce(&mut dyn TensorExec) -> R + Send, ) -> R

Execute a batch of operations inside the backend’s execution context.

Backends can override this to establish one shared scope for many ops, such as a rayon pool install on CPU.

§Examples
use tenferro_tensor::{cpu::CpuBackend, TensorBackend};

let mut backend = CpuBackend::new();
let _value = backend.with_exec_session(|_exec| 1usize);
Source

fn download_to_host(&mut self, tensor: &Tensor) -> Result<Tensor>

Materialize a backend tensor into host memory.

Backends that already operate on host tensors can keep the default implementation, which clones the input tensor.

§Examples
use tenferro_tensor::{cpu::CpuBackend, Tensor, TensorBackend, TypedTensor};

let mut backend = CpuBackend::new();
let tensor = Tensor::F64(TypedTensor::from_vec(vec![2], vec![1.0, 2.0]));
let host = backend.download_to_host(&tensor).unwrap();
assert_eq!(host.shape(), &[2]);
Source

fn upload_host_tensor(&mut self, tensor: &Tensor) -> Result<Tensor>

Upload a host tensor into backend-owned storage when needed.

Backends that already use host tensors can keep the default implementation, which clones the input tensor.

§Examples
use tenferro_tensor::{cpu::CpuBackend, Tensor, TensorBackend, TypedTensor};

let mut backend = CpuBackend::new();
let tensor = Tensor::F64(TypedTensor::from_vec(vec![2], vec![1.0, 2.0]));
let uploaded = backend.upload_host_tensor(&tensor).unwrap();
assert_eq!(uploaded.shape(), &[2]);
Source

fn reclaim_buffer(&mut self, _tensor: Tensor)

Reclaim a tensor buffer for backend-specific reuse.

Backends that do not pool buffers can ignore the tensor and let it drop.

§Examples
use tenferro_tensor::{cpu::CpuBackend, Tensor, TensorBackend, TypedTensor};

let mut backend = CpuBackend::new();
let tensor = Tensor::F64(TypedTensor::from_vec(vec![2], vec![1.0, 2.0]));
backend.reclaim_buffer(tensor);

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§