Skip to main content

CpuExecutionContext

Struct CpuExecutionContext 

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

Caller-owned CPU execution domain for plain, graph, and eager-AD work.

The supplied backend is the only source of CPU execution resources. Backend clones preserve its runtime identity; this constructor never uses CpuBackend::new, CpuContext::from_env, or a process-global fallback. Graph preparation caches and the eager runtime are owned by this context and are released when it is dropped.

§Examples

use tensor4all_tensorbackend::CpuExecutionContext;
use tenferro_cpu::CpuBackend;

let context = CpuExecutionContext::from_backend(CpuBackend::with_threads(1)?);
let threads = context.with_backend(|backend| backend.num_threads());
assert_eq!(threads, 1);

Implementations§

Source§

impl CpuExecutionContext

Source

pub fn from_backend(backend: CpuBackend) -> Self

Create an execution context from a caller-selected CPU backend.

Runtime construction is lazy, so creating a context cannot fail and does not allocate another executor or consult environment configuration.

Source

pub fn with_backend<R>(&self, f: impl FnOnce(&mut CpuBackend) -> R) -> R

Run a plain tensor operation with this context’s backend.

The closure runs while the context-local backend lock is held. A poisoned lock is recovered because tenferro validates every new backend session.

Source

pub fn compile_graph( &self, graph: &TracedGraph, ) -> Result<CompiledGraph, CpuExecutionContextError>

Compile a backend-neutral traced graph using this context’s compiler cache.

§Errors

Returns CpuExecutionContextError when graph-runtime initialization or graph compilation fails.

Source

pub fn run_graph( &self, graph: &CompiledGraph, inputs: &[&Tensor], ) -> Result<Vec<Tensor>, CpuExecutionContextError>

Execute a compiled graph in this context’s runtime and prepared-plan cache.

CompiledGraph is backend-neutral. Backend-prepared executables and workspaces never leave this context-owned runtime.

§Errors

Returns CpuExecutionContextError when runtime initialization, preparation, or execution fails.

Source

pub fn eager_runtime( &self, ) -> Result<Arc<EagerRuntime>, CpuExecutionContextError>

Return this context’s eager reverse-AD runtime.

Repeated calls return the same runtime and therefore the same eager compilation cache.

§Errors

Returns CpuExecutionContextError when linalg AD-rule or eager-runtime registration fails.

Source

pub fn graph_cache_stats( &self, ) -> Result<RuntimeCacheStats, CpuExecutionContextError>

Return statistics for this context’s runtime-owned graph caches.

§Errors

Returns CpuExecutionContextError when graph initialization or the cache statistics query fails.

Source

pub fn graph_buffer_pool_stats( &self, ) -> Result<BufferPoolStats, CpuExecutionContextError>

Return retained-buffer statistics for this context’s graph backend.

§Errors

Returns CpuExecutionContextError when graph initialization or the backend statistics query fails.

Source

pub fn reset_graph_buffer_pool(&self) -> Result<(), CpuExecutionContextError>

Release retained buffers owned by this context’s graph backend.

§Errors

Returns CpuExecutionContextError when graph initialization or reset fails.

Source

pub fn reset_graph_runtime(&self) -> Result<(), CpuExecutionContextError>

Recreate this context’s graph runtime and release its prepared caches.

§Errors

Returns CpuExecutionContextError when runtime reconstruction or buffer release fails.

Source§

impl CpuExecutionContext

Source

pub fn reconstruct( &self, tensor: &LogicalTensor, ) -> Result<Tensor, LogicalTensorError>

Reconstruct a logical host tensor in this receiving execution domain.

The returned value carries only host tensor data. Its first plain, graph, or eager operation must use this same explicit context.

§Errors

Returns LogicalTensorError if tenferro rejects the validated shape or dtype payload.

Trait Implementations§

Source§

impl Debug for CpuExecutionContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

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> MaybeSend for T
where T: Send,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

§

impl<T> MaybeSync for T
where T: Sync,

§

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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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