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
impl CpuExecutionContext
Sourcepub fn from_backend(backend: CpuBackend) -> Self
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.
Sourcepub fn with_backend<R>(&self, f: impl FnOnce(&mut CpuBackend) -> R) -> R
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.
Sourcepub fn compile_graph(
&self,
graph: &TracedGraph,
) -> Result<CompiledGraph, CpuExecutionContextError>
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.
Sourcepub fn run_graph(
&self,
graph: &CompiledGraph,
inputs: &[&Tensor],
) -> Result<Vec<Tensor>, CpuExecutionContextError>
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.
Sourcepub fn eager_runtime(
&self,
) -> Result<Arc<EagerRuntime>, CpuExecutionContextError>
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.
Sourcepub fn graph_cache_stats(
&self,
) -> Result<RuntimeCacheStats, CpuExecutionContextError>
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.
Sourcepub fn graph_buffer_pool_stats(
&self,
) -> Result<BufferPoolStats, CpuExecutionContextError>
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.
Sourcepub fn reset_graph_buffer_pool(&self) -> Result<(), CpuExecutionContextError>
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.
Sourcepub fn reset_graph_runtime(&self) -> Result<(), CpuExecutionContextError>
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
impl CpuExecutionContext
Sourcepub fn reconstruct(
&self,
tensor: &LogicalTensor,
) -> Result<Tensor, LogicalTensorError>
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§
Auto Trait Implementations§
impl !Freeze for CpuExecutionContext
impl !RefUnwindSafe for CpuExecutionContext
impl !UnwindSafe for CpuExecutionContext
impl Send for CpuExecutionContext
impl Sync for CpuExecutionContext
impl Unpin for CpuExecutionContext
impl UnsafeUnpin for CpuExecutionContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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