Expand description
Immutable backend-neutral semantic programs.
Semantic structure freezes separately from tensor defaults and large constants. Builder-issued values and binding keys are opaque and scoped to one builder/program.
§Build, bind, freeze, query, and import
use std::sync::Arc;
use tenferro_ops::dim_expr::DimExpr;
use tenferro_runtime::program::{
CoreSemanticOp, ProgramInputSpec, ProgramQueryError, ProgramImport,
SemanticProgramBuilder,
};
use tenferro_tensor::{DType, Tensor};
let mut builder = SemanticProgramBuilder::new();
let input = builder.input(ProgramInputSpec::new(
DType::F64,
[DimExpr::Const(2)],
))?;
let key = builder.bind_input(
input,
Arc::new(Tensor::from_vec_col_major(vec![2], vec![1.0_f64, 2.0])?),
)?;
let output = builder.add_op(CoreSemanticOp::Neg, &[input])?[0];
let frozen = builder.finish(&[output])?;
assert_eq!(frozen.bindings.iter().count(), 1);
assert!(frozen.bindings.get(key).is_some());
assert_eq!(frozen.program.semantic_fingerprint().as_bytes().len(), 16);
let mut other = SemanticProgramBuilder::new();
let foreign = other.input(ProgramInputSpec::new(
DType::F64,
[DimExpr::Const(2)],
))?;
assert_eq!(
frozen.program.value_metadata(foreign),
Err(ProgramQueryError::ForeignValue),
);
let mut destination = SemanticProgramBuilder::new();
let imported = destination.import(ProgramImport {
program: frozen.program.as_ref(),
bindings: &frozen.bindings,
roots: frozen.program.outputs(),
})?;
let roundtrip = destination.finish(imported.roots())?;
assert!(frozen.program.semantic_eq(roundtrip.program.as_ref()));
assert_eq!(roundtrip.bindings.len(), 1);§Opaque identities
Raw slots and builder nonces are deliberately inaccessible.
ⓘ
use tenferro_runtime::program::ProgramValue;
fn raw_slot(value: ProgramValue) -> u32 {
value.slot
}ⓘ
use tenferro_runtime::program::BindingKey;
fn raw_slot(key: BindingKey) -> u32 {
key.slot
}Frozen operation views expose immutable slices only.
ⓘ
use tenferro_runtime::program::SemanticOperationView;
fn mutate(view: SemanticOperationView<'_>) {
view.outputs()[0] = view.inputs()[0];
}Structured control flow is a typed unsupported case until the reserved region/block model is implemented.
use tenferro_runtime::program::ProgramBuildError;
let error = ProgramBuildError::UnsupportedControlFlow { construct: "while" };
assert!(matches!(
error,
ProgramBuildError::UnsupportedControlFlow { construct: "while" }
));Structs§
- Alias
- Alias contract for one operation output.
- Binding
Key - Opaque lookup key for one frozen tensor binding.
- Effect
- One typed observable state access.
- Effect
Resource - Typed identity of an observable state resource.
- Frozen
Program - One atomically frozen semantic program and its separate tensor bindings.
- Imported
Program Values - Destination-builder values corresponding to requested import roots.
- Program
Bindings - Immutable tensor defaults and large constants kept outside semantic structure.
- Program
Import - Read-only request to import the dependency closure of ordered roots.
- Program
Input Spec - Metadata for one externally supplied semantic-program input.
- Program
Value - An opaque SSA value owned by one semantic-program builder.
- Program
Value Metadata - Dtype and ordered symbolic extents of one semantic SSA value.
- Semantic
Fingerprint - Cached fixed-size identity of normalized semantic program structure.
- Semantic
Operation View - Allocation-free immutable view of one semantic operation.
- Semantic
Placement Constraint - Backend-neutral placement requirement retained for runtime preparation.
- Semantic
Program - Immutable backend-neutral semantic SSA program.
- Semantic
Program Builder - Mutable validation boundary for one semantic program.
- Semantic
Provenance View - Bounded, allocation-free diagnostic provenance view.
- Semantic
Transform Context - Validation-preserving destination transaction exposed to transforms.
- Shape
Guard - A backend-neutral symbolic-shape obligation.
- Transform
Identity - Opaque fixed-size identity of one semantic transform implementation/configuration.
Enums§
- Alias
Kind - Semantic alias class for one operation output.
- Core
Semantic Op - Closed backend-neutral vocabulary of core semantic tensor operations.
- Core
Semantic OpConversion Error - Failure to convert a standard-operation carrier into the closed core semantic vocabulary.
- Effect
Access - Access mode of one semantic effect.
- Effect
Resource Error - Invalid typed effect-resource identity.
- Program
Binding Error - Tensor-binding validation failures detected during atomic freeze.
- Program
Build Error - Errors reported while adding semantic-program structure.
- Program
Finish Error - Errors reported while atomically freezing semantic structure and bindings.
- Program
Query Error - Errors reported while querying an immutable semantic program.
- Program
Shape Relation - Relation enforced between two symbolic dimension expressions.
- Program
Structural Error - Internal structural validation failures detected during atomic freeze.
- Semantic
OpRef - Borrowed semantic operation payload.
- Semantic
Placement Kind - Kind of unresolved semantic placement requirement.
- Semantic
Provenance Kind - Diagnostic origin class of one semantic operation.
- Semantic
Transform Error - Failures produced by a validated semantic transform transaction.
Traits§
- Semantic
Transform - Object-safe transformation over immutable semantic programs and bindings.