Skip to main content

tenferro_runtime/
lib.rs

1//! Traced graph runtime and extension dispatch infrastructure for tenferro.
2//!
3//! This crate owns graph construction, lowering to execution IR, graph
4//! execution, and backend-parametric extension runtime dispatch. Standard
5//! operations are lowered through the runtime's internal operation vocabulary;
6//! tensor storage and backend kernels live in `tenferro-tensor`.
7//!
8//! Use this crate directly when you want concrete tensor helpers or reusable
9//! traced graph execution without depending on `tenferro-ad`. Start with
10//! [`TypedTensor`] when the scalar type is fixed in Rust, [`Tensor`] when dtype
11//! is selected at runtime, and [`TracedTensor`] plus [`GraphCompiler`] and
12//! [`Runtime`] when the same expression should be compiled once and run
13//! repeatedly. Operation-family crates such as `tenferro-einsum`,
14//! `tenferro-linalg`, and `tenferro-fft` register extension runtimes through
15//! runtime engine registrations when compiled execution reaches those
16//! operations.
17//!
18//! User-facing guides live at
19//! <https://tensor4all.org/tenferro-rs/guides/choosing-an-api.html> and
20//! <https://tensor4all.org/tenferro-rs/guides/execution-models.html>.
21//!
22//! # Examples
23//!
24//! ```rust
25//! use tenferro_runtime::{GraphCompiler, Runtime, TracedTensor};
26//! use tenferro_cpu::CpuBackend;
27//!
28//! let x = TracedTensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0]).unwrap();
29//! let y = (&x + &x).unwrap();
30//! let mut compiler = GraphCompiler::new();
31//! let program = compiler.compile(&y).unwrap();
32//! let backend = CpuBackend::default();
33//! let mut builder = Runtime::builder();
34//! builder.register_engine(tenferro_cpu::runtime_engine_registration(&backend).unwrap()).unwrap();
35//! let runtime = builder.build().unwrap();
36//! let out = runtime.run_compiled(&program, &[]).unwrap().pop().unwrap();
37//! assert_eq!(out.as_slice::<f64>().unwrap(), &[2.0, 4.0]);
38//! ```
39
40#[doc(hidden)]
41pub mod ad_support;
42mod checkpoint;
43mod compiler;
44#[doc(hidden)]
45pub mod composite;
46pub mod error;
47mod exec;
48pub mod extension;
49pub mod extension_cache;
50mod extension_execution_context;
51pub mod graph;
52mod metadata;
53pub mod prelude;
54pub mod program;
55pub mod runtime;
56#[doc(hidden)]
57pub mod scalar_semantics;
58#[doc(hidden)]
59pub mod scale;
60mod segment;
61mod session_ext;
62mod shape_constraint;
63mod shape_infer;
64mod shape_packing;
65pub mod sym_dim;
66mod tensor;
67mod trace;
68pub mod traced;
69mod typed_session_ext;
70mod typed_tensor;
71
72pub use compiler::{CompilerOptions, OptimizerConfig};
73pub use error::{
74    ContextId, Error, ErrorPhase, Result, RuntimeFailureReasonRef, ShapeConstraintEvalError,
75};
76pub use extension_cache::{
77    ExtensionCacheKey, ExtensionCacheLimits, ExtensionCacheSelector, ExtensionCacheStore,
78};
79pub use extension_execution_context::ExtensionExecutionContext;
80pub use graph::{CompiledGraph, GraphCompiler};
81pub use runtime::{
82    assemble_executable_engine_registration, assemble_preparation_only_engine_registration,
83    CacheInFlightBehavior, CacheOwnerError, CacheOwnerFailure, CacheOwnerId, CoreCapabilityBundle,
84    CoreCapabilityBundleBuilder, CoreCapabilityKind, CorePrepareContext, Determinism,
85    DotGeneralPreparation, DotGeneralPrepareRequest, ElementwisePrepareRequest, ElementwiseRuntime,
86    EngineExecutionContractError, EngineId, EngineRegistration, EngineRegistrationMetadata,
87    EngineSnapshotView, ErasedExecutionContext, EventDomainDriver, EventDomainError, EventDomainId,
88    EventDomainOperation, EventDomainRun, EventToken, ExecutableEngineRegistrationConfig,
89    ExecutionBundle, ExecutionContextIdentity, ExecutionContextMismatch, ExecutionHandle,
90    ExecutionInputs, ExecutionOutcome, ExecutionPolicy, ExecutionPolicyError, ExtensionEngine,
91    ExtensionModule, ExtensionModuleError, ExtensionModuleId, ExtensionModuleRegistrar,
92    ExtensionPlanningConfig, ExtensionPrepareRequest, HardwareClassId, IdentityError, IdentityKind,
93    ImmediateEventDomainDriver, IndexingPrepareRequest, IndexingRuntime, InputIngressContract,
94    InputIngressContractError, InputPlacementContract, InputSignature, InputSignatureContract,
95    InputSignatureEntry, InputSignatureError, InputSpecializationProjection,
96    InputSpecializationRequirements, InputSpecializationRequirementsBuilder,
97    InputSpecializationRequirementsError, LayoutClass, LayoutPrepareRequest, LayoutProjection,
98    LayoutRuntime, LayoutSpecialization, OutputAccessError, OutputExtractError, OutputMetadata,
99    OutputRef, PlacementConstraintError, PlacementProjection, PlacementSpecialization,
100    PreparationKeySummary, PreparationOnlyEngineRegistrationConfig, PrepareCapability,
101    PrepareError, PrepareOptions, PrepareOptionsKey, PreparedCompiledGraph, PreparedOperation,
102    PreparedOperationBinding, PreparedOperationExecutor, PreparedOperationExecutorHandle,
103    PreparedOperationHandle, PreparedOperationPlan, PreparedPlanCacheLimits,
104    PreparedPlanCacheStats, ProgramPlacementConstraint, ProviderContractError,
105    ProviderDeviceIdentity, ProviderId, RankRequirement, ReductionPrepareRequest, ReductionRuntime,
106    RegistrationIdentity, RegistrationKey, ResidentOutputContract, ResolvedPlanningConfig,
107    ResolvedPlanningKey, ResolvedProgramPlacement, Runtime, RuntimeCacheError, RuntimeCacheOwner,
108    RuntimeCacheStats, RuntimeConfigBuilder, RuntimeConfigError, RuntimeConfigSnapshot,
109    RuntimeEpoch, RuntimeId, RuntimeInputContract, RuntimeReconfiguration, RuntimeReconfigureError,
110    RuntimeStateError, ScopedExecutionBundle, ScopedExecutionOutcome, ScopedOutput,
111    ScopedOutputExtractError, ScopedReadBinding, ScopedReadInputs, ScopedSubmitRejected,
112    SpecializationError, SpecializationProjection, SpecializationRequirements, StorageClass,
113    SubmissionError, SubmitError, TransferEndpoint, TransferError, TransferProvider,
114    TransferProviderContractError, TransferRequest, UnsupportedReason,
115};
116pub use session_ext::TensorSessionOpsExt;
117#[doc(hidden)]
118pub use shape_constraint::ShapeGuard;
119pub use shape_packing::TracedSliceBuilder;
120pub use sym_dim::SymDim;
121pub use tenferro_ops::ShapeRelation;
122pub use tenferro_tensor::{
123    BackendSession, BackendSessionHost, CacheStats, CompareDir, DType, DotGeneralConfig,
124    GatherConfig, MemoryKind, PadConfig, ScatterConfig, SliceConfig, Tensor, TensorBackend,
125    TensorRead, TensorScalar, TensorValue, TensorView, TypedTensor, TypedTensorView,
126};
127pub use trace::{TraceContext, TraceValue, TracedGraph};
128pub use typed_session_ext::{TypedTensorMaskSessionOpsExt, TypedTensorSessionOpsExt};
129
130pub use traced::TracedTensor;