Skip to main content

Module explicit

Module explicit 

Source
Expand description

Opt-in explicit/concrete execution frontend (issue #859 B1). Opt-in explicit/concrete execution frontend.

This is the second, opt-in frontend of tensor4all-rs#859: a caller-supplied CpuExecutionContext plus one concrete session that a whole stage or batch reuses, instead of the process-global convenience surface in the compatibility entry point. The compatibility frontend keeps its own signatures, defaults and behaviour; nothing here reroutes it.

Properties of this frontend, from the coexistence record (docs/design/859-dual-frontend-coexistence.md):

  • One explicit entry. CpuExecutionContext::with_concrete_session lends the context’s engine for the whole closure, so a stage borrows it once rather than once per operation, and the engine’s prepared plans and buffer pool stay warm.
  • No process-global selector. No route here selects an execution context or backend from a default context, a thread-local override or an environment variable. (Upstream profiling hooks may still read their own environment flags; those do not choose where the work runs.)
  • No eager, trace or AD records. These routes reach only concrete Tensor/engine operations; they never construct EagerTensor, semantic nodes or gradient slots, and they take no eager owner lock. Tracked values are not accepted at all, so no detach can happen implicitly.
  • No implicit fallback. An unsupported dtype or shape returns the backend’s typed error. Nothing here retries on the global or CPU-eager route.
  • Explicit conversion at the boundary. Crossing between this frontend and the compatibility frontend is LogicalTensor, which carries dtype, shape and column-major data and no backend identity.

The session is a borrow of one [tenferro_cpu::CpuEngine], not a value representation: the concrete values stay the ordinary tenferro tensors.

§Examples

use tensor4all_tensorbackend::{CpuExecutionContext, explicit::Session};
use tenferro::Tensor;
use tensor4all_tensorbackend::CpuBackend;

let context = CpuExecutionContext::from_backend(CpuBackend::with_threads(1)?);
let x = Tensor::from_vec_col_major(vec![2, 2], vec![1.0_f64, 2.0, 3.0, 4.0])?;

let product = context.with_concrete_session(|session: &mut Session<'_>| {
    session.qr(&x).map(|(q, _r)| q)
})?;
assert_eq!(product.expect("QR succeeds").shape(), &[2, 2]);

Structs§

PreparedEinsum
One prepared N-ary einsum, reusable across operations of a session.
Session
One explicit concrete session over a caller-held CPU engine.

Enums§

ConversionError
Failure reported by this frontend’s compatibility bridges.

Functions§

detach
Materialize a tracked eager value into a plain concrete value on engine.
lift
Adopt a plain concrete value into context’s eager runtime.