Skip to main content

Engine

Struct Engine 

Source
pub struct Engine<B: TensorBackend> { /* private fields */ }
Expand description

Execution engine holding the backend and compile caches.

§Examples

use tenferro_tensor::cpu::CpuBackend;
use tenferro::engine::Engine;

let mut engine = Engine::new(CpuBackend::new());

Implementations§

Source§

impl<B: TensorBackend> Engine<B>

Source

pub fn new(backend: B) -> Self

Create a new engine with the given backend.

§Examples
use tenferro_tensor::cpu::CpuBackend;
use tenferro::engine::Engine;

let engine = Engine::new(CpuBackend::new());
Source

pub fn backend(&self) -> &B

Borrow the backend used by this engine.

§Examples
use tenferro::{CpuBackend, Engine};

let engine = Engine::new(CpuBackend::new());
let _backend = engine.backend();
Source

pub fn einsum_cache_len(&self) -> usize

Number of cached einsum contraction trees currently retained by the engine.

§Examples
use tenferro::{CpuBackend, Engine};

let engine = Engine::new(CpuBackend::new());
assert_eq!(engine.einsum_cache_len(), 0);
Source

pub fn with_einsum_cache_capacity(backend: B, capacity: NonZeroUsize) -> Self

Construct a new engine with an explicit einsum_cache capacity.

§Examples
use std::num::NonZeroUsize;
use tenferro::{CpuBackend, Engine};

let engine = Engine::with_einsum_cache_capacity(
    CpuBackend::new(),
    NonZeroUsize::new(64).unwrap(),
);
Source

pub fn einsum_cache_capacity(&self) -> NonZeroUsize

Current capacity of the einsum contraction-tree cache.

§Examples
use tenferro::{CpuBackend, Engine};

let engine = Engine::new(CpuBackend::new());
assert_eq!(engine.einsum_cache_capacity().get(), tenferro::engine::DEFAULT_EINSUM_CACHE_CAPACITY);
Source

pub fn set_einsum_cache_capacity(&mut self, capacity: NonZeroUsize)

Resize the einsum contraction-tree cache.

Shrinking below the current length evicts least-recently-used entries.

§Examples
use std::num::NonZeroUsize;
use tenferro::{CpuBackend, Engine};

let mut engine = Engine::new(CpuBackend::new());
engine.set_einsum_cache_capacity(NonZeroUsize::new(32).unwrap());
Source

pub fn einsum_cache_contains(&self, key: &(String, Vec<Vec<usize>>)) -> bool

Returns true if the einsum cache contains a tree for key.

Does not modify LRU recency.

§Examples
use tenferro::{CpuBackend, Engine};

let engine = Engine::new(CpuBackend::new());
let key = ("ij,jk->ik".to_string(), vec![vec![2, 3], vec![3, 4]]);
assert!(!engine.einsum_cache_contains(&key));
Source

pub fn eval_exec_ir( &mut self, program: &ExecProgram, inputs: Vec<Tensor>, ) -> Result<Vec<Tensor>>

Evaluate an ExecProgram through this engine, reusing the persistent einsum_cache for any NaryEinsum ops encountered in the program.

§Examples
use tenferro::{CpuBackend, Engine};
use tenferro::exec::ExecProgram;

let mut engine = Engine::new(CpuBackend::new());
// let outputs = engine.eval_exec_ir(&program, inputs)?;
Source§

impl Engine<CpuBackend>

Source

pub fn buffer_pool_len(&self) -> usize

Number of reusable typed host buffers currently retained by the CPU backend.

§Examples
use tenferro::{CpuBackend, Engine};

let engine = Engine::new(CpuBackend::new());
assert_eq!(engine.buffer_pool_len(), 0);

Auto Trait Implementations§

§

impl<B> Freeze for Engine<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Engine<B>
where B: RefUnwindSafe,

§

impl<B> Send for Engine<B>
where B: Send,

§

impl<B> Sync for Engine<B>
where B: Sync,

§

impl<B> Unpin for Engine<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for Engine<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for Engine<B>
where B: UnwindSafe,

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