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
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§
Sourcefn with_exec_session<R: Send>(
&mut self,
f: impl FnOnce(&mut dyn TensorExec) -> R + Send,
) -> R
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);Sourcefn download_to_host(&mut self, tensor: &Tensor) -> Result<Tensor>
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]);Sourcefn upload_host_tensor(&mut self, tensor: &Tensor) -> Result<Tensor>
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]);Sourcefn reclaim_buffer(&mut self, _tensor: Tensor)
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.