teeny_core/graph/compiler.rs
1/*
2 * Copyright (c) 2026 Teenygrad.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use crate::compiler::Target;
18use crate::errors::Result;
19use crate::graph::Graph;
20use crate::model::{Lowering, LoweringMode, Model};
21
22/// Compiles a [`Graph`] into a runnable [`Model`], given a [`Lowering`] and [`Target`].
23pub trait GraphCompiler {
24 /// Compiles `graph` for `target` using `lowering`/`mode`. `force` recompiles even if a
25 /// cached artifact exists.
26 fn compile<'a, L: Lowering<'a>, T: Target>(
27 &self,
28 graph: &Graph,
29 lowering: &L,
30 target: &T,
31 mode: LoweringMode,
32 force: bool,
33 ) -> Result<impl Model<'a>>;
34}