Skip to main content

Module program

Module program 

Source
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.
BindingKey
Opaque lookup key for one frozen tensor binding.
Effect
One typed observable state access.
EffectResource
Typed identity of an observable state resource.
FrozenProgram
One atomically frozen semantic program and its separate tensor bindings.
ImportedProgramValues
Destination-builder values corresponding to requested import roots.
ProgramBindings
Immutable tensor defaults and large constants kept outside semantic structure.
ProgramImport
Read-only request to import the dependency closure of ordered roots.
ProgramInputSpec
Metadata for one externally supplied semantic-program input.
ProgramValue
An opaque SSA value owned by one semantic-program builder.
ProgramValueMetadata
Dtype and ordered symbolic extents of one semantic SSA value.
SemanticFingerprint
Cached fixed-size identity of normalized semantic program structure.
SemanticOperationView
Allocation-free immutable view of one semantic operation.
SemanticPlacementConstraint
Backend-neutral placement requirement retained for runtime preparation.
SemanticProgram
Immutable backend-neutral semantic SSA program.
SemanticProgramBuilder
Mutable validation boundary for one semantic program.
SemanticProvenanceView
Bounded, allocation-free diagnostic provenance view.
SemanticTransformContext
Validation-preserving destination transaction exposed to transforms.
ShapeGuard
A backend-neutral symbolic-shape obligation.
TransformIdentity
Opaque fixed-size identity of one semantic transform implementation/configuration.

Enums§

AliasKind
Semantic alias class for one operation output.
CoreSemanticOp
Closed backend-neutral vocabulary of core semantic tensor operations.
CoreSemanticOpConversionError
Failure to convert a standard-operation carrier into the closed core semantic vocabulary.
EffectAccess
Access mode of one semantic effect.
EffectResourceError
Invalid typed effect-resource identity.
ProgramBindingError
Tensor-binding validation failures detected during atomic freeze.
ProgramBuildError
Errors reported while adding semantic-program structure.
ProgramFinishError
Errors reported while atomically freezing semantic structure and bindings.
ProgramQueryError
Errors reported while querying an immutable semantic program.
ProgramShapeRelation
Relation enforced between two symbolic dimension expressions.
ProgramStructuralError
Internal structural validation failures detected during atomic freeze.
SemanticOpRef
Borrowed semantic operation payload.
SemanticPlacementKind
Kind of unresolved semantic placement requirement.
SemanticProvenanceKind
Diagnostic origin class of one semantic operation.
SemanticTransformError
Failures produced by a validated semantic transform transaction.

Traits§

SemanticTransform
Object-safe transformation over immutable semantic programs and bindings.