use tenferro_ops::input_key::TensorInputKey;
use crate::compiler::CompilerOptions;
use crate::program::{FrozenProgram, ProgramBindings, SemanticProgram};
#[derive(Clone)]
pub struct CompiledGraph {
pub(crate) frozen: FrozenProgram,
pub(crate) compiler_options: CompilerOptions,
pub(crate) input_keys: Box<[TensorInputKey]>,
}
impl CompiledGraph {
pub(crate) fn new(
frozen: FrozenProgram,
compiler_options: CompilerOptions,
input_keys: impl Into<Box<[TensorInputKey]>>,
) -> Self {
Self {
frozen,
compiler_options,
input_keys: input_keys.into(),
}
}
#[allow(
dead_code,
reason = "Phase 5 runtime-owned execution consumes compiled frozen programs"
)]
pub(crate) fn frozen(&self) -> &FrozenProgram {
&self.frozen
}
#[doc(hidden)]
pub fn frozen_program(&self) -> &FrozenProgram {
&self.frozen
}
pub(crate) fn compiler_options(&self) -> CompilerOptions {
self.compiler_options
}
pub fn program(&self) -> &SemanticProgram {
&self.frozen.program
}
pub fn bindings(&self) -> &ProgramBindings {
&self.frozen.bindings
}
pub fn input_count(&self) -> usize {
self.frozen.program.inputs().len()
}
#[doc(hidden)]
pub fn input_keys(&self) -> &[TensorInputKey] {
&self.input_keys
}
#[doc(hidden)]
pub fn input_key_index(&self, key: &TensorInputKey) -> Option<usize> {
self.input_keys
.iter()
.position(|candidate| candidate == key)
}
pub fn output_count(&self) -> usize {
self.frozen.program.outputs().len()
}
}
impl std::fmt::Debug for CompiledGraph {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("CompiledGraph")
.field("inputs", &self.input_count())
.field("outputs", &self.output_count())
.field("input_keys", &self.input_keys.len())
.field("bindings", &self.bindings().len())
.field(
"semantic_fingerprint",
&self.program().semantic_fingerprint(),
)
.finish()
}
}