use std::sync::Arc;
use tenferro_ops::dim_expr::DimExpr;
use tenferro_ops::input_key::TensorInputKey;
use tenferro_tensor::{DType, Tensor};
use crate::exec::ExecProgram;
use crate::graph::lowering_view::GraphProgramLoweringView;
#[derive(Clone, Debug)]
pub struct GraphProgram {
pub(crate) exec: ExecProgram,
pub(crate) inputs: Vec<GraphProgramInput>,
}
impl GraphProgram {
pub(crate) fn new(exec: ExecProgram, inputs: Vec<GraphProgramInput>) -> Self {
Self { exec, inputs }
}
#[inline(never)]
pub fn input_count(&self) -> usize {
self.inputs.len()
}
#[inline(never)]
pub fn output_count(&self) -> usize {
self.exec.output_slots.len()
}
#[inline(never)]
pub fn input_specs(&self) -> &[GraphProgramInput] {
&self.inputs
}
#[inline(never)]
pub fn lowering_view(&self) -> GraphProgramLoweringView<'_> {
GraphProgramLoweringView::new(&self.exec)
}
}
#[derive(Clone, Debug)]
pub struct GraphProgramInput {
pub(crate) key: TensorInputKey,
pub(crate) dtype: DType,
pub(crate) shape: Vec<usize>,
#[allow(dead_code)]
pub(crate) dim_expr_shape: Vec<DimExpr>,
pub(crate) default_tensor: Option<Arc<Tensor>>,
}
impl GraphProgramInput {
pub(crate) fn new(
key: TensorInputKey,
dtype: DType,
shape: Vec<usize>,
dim_expr_shape: Vec<DimExpr>,
default_tensor: Option<Arc<Tensor>>,
) -> Self {
Self {
key,
dtype,
shape,
dim_expr_shape,
default_tensor,
}
}
#[inline(never)]
pub fn dtype(&self) -> DType {
self.dtype
}
#[inline(never)]
pub fn shape(&self) -> &[usize] {
&self.shape
}
}