Skip to main content

oxfuse_runtime/
evaluator.rs

1//! Constant evaluation with the reference kernels, so a folded constant is
2//! bit-identical to the value the run-time path computes.
3
4use crate::kernels;
5use oxfuse_core::passes::ConstEvaluator;
6use oxfuse_core::{Error, Op, TensorType};
7
8pub struct ReferenceEvaluator;
9
10impl ConstEvaluator for ReferenceEvaluator {
11    fn eval(&self, op: &Op, inputs: &[(&TensorType, &[f32])]) -> Result<Vec<f32>, Error> {
12        let data: Vec<&[f32]> = inputs.iter().map(|(_, data)| *data).collect();
13        let shapes: Vec<&[usize]> = inputs.iter().map(|(ty, _)| ty.shape.as_slice()).collect();
14        Ok(kernels::apply(op, &data, &shapes))
15    }
16}