Skip to main content

CpuBackend

Struct CpuBackend 

Source
pub struct CpuBackend { /* private fields */ }
Expand description

CPU execution backend.

§Examples

use tenferro_tensor::cpu::CpuBackend;

let backend = CpuBackend::new();

Implementations§

Source§

impl CpuBackend

Source

pub fn new() -> CpuBackend

Create a CPU backend using the environment-driven CPU context.

§Examples
use tenferro_tensor::cpu::CpuBackend;

let backend = CpuBackend::new();
Source

pub fn try_new() -> Result<CpuBackend, Error>

Try to create a CPU backend using RAYON_NUM_THREADS.

§Examples
use tenferro_tensor::cpu::CpuBackend;

let backend = CpuBackend::try_new().unwrap();
let _ = backend.num_threads();
Source

pub fn from_context(ctx: Arc<CpuContext>) -> CpuBackend

Create a CPU backend from an existing context.

§Examples
use std::sync::Arc;
use tenferro_tensor::cpu::{CpuBackend, CpuContext};

let ctx = Arc::new(CpuContext::with_threads(2));
let backend = CpuBackend::from_context(ctx);
assert_eq!(backend.num_threads(), 2);
Source

pub fn with_threads(num_threads: usize) -> CpuBackend

Create a CPU backend with a custom thread count.

§Examples
use tenferro_tensor::cpu::CpuBackend;

let backend = CpuBackend::with_threads(2);
assert_eq!(backend.num_threads(), 2);
Source

pub fn num_threads(&self) -> usize

Return the number of threads in this backend’s CPU context.

§Examples
use tenferro_tensor::cpu::CpuBackend;

let backend = CpuBackend::with_threads(2);
assert_eq!(backend.num_threads(), 2);
Source

pub fn buffer_pool_len(&self) -> usize

Number of retained typed host buffers currently held by this backend.

§Examples
use tenferro_tensor::cpu::CpuBackend;

let backend = CpuBackend::new();
assert_eq!(backend.buffer_pool_len(), 0);
Source

pub fn install<R>(&self, op: impl FnOnce() -> R + Send) -> R
where R: Send,

Run a closure inside this backend’s shared rayon thread pool.

§Examples
use tenferro_tensor::cpu::CpuBackend;

let backend = CpuBackend::with_threads(1);
let value = backend.install(|| 1 + 1);
assert_eq!(value, 2);

Trait Implementations§

Source§

impl Default for CpuBackend

Source§

fn default() -> CpuBackend

Returns the “default value” for a type. Read more
Source§

impl<Alg> SemiringBackend<Alg> for CpuBackend
where Alg: Semiring,

Source§

fn batched_gemm( &mut self, lhs: &TypedTensor<<Alg as Algebra>::Scalar>, rhs: &TypedTensor<<Alg as Algebra>::Scalar>, config: &DotGeneralConfig, ) -> Result<TypedTensor<<Alg as Algebra>::Scalar>, Error>

Source§

fn add( &mut self, lhs: &TypedTensor<<Alg as Algebra>::Scalar>, rhs: &TypedTensor<<Alg as Algebra>::Scalar>, ) -> Result<TypedTensor<<Alg as Algebra>::Scalar>, Error>

Source§

fn mul( &mut self, lhs: &TypedTensor<<Alg as Algebra>::Scalar>, rhs: &TypedTensor<<Alg as Algebra>::Scalar>, ) -> Result<TypedTensor<<Alg as Algebra>::Scalar>, Error>

Source§

fn reduce_sum( &mut self, input: &TypedTensor<<Alg as Algebra>::Scalar>, axes: &[usize], ) -> Result<TypedTensor<<Alg as Algebra>::Scalar>, Error>

Source§

impl TensorBackend for CpuBackend

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Execute a batch of operations inside the backend’s execution context. Read more
Source§

fn reclaim_buffer(&mut self, tensor: Tensor)

Reclaim a tensor buffer for backend-specific reuse. Read more
Source§

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

Materialize a backend tensor into host memory. Read more
Source§

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

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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

§

impl<T> MaybeSend for T

§

impl<T> MaybeSendSync for T

§

impl<T> MaybeSync for T