1#![warn(missing_docs)]
39#![allow(clippy::module_name_repetitions)]
40
41pub mod cache;
42pub mod codegen;
43pub mod compile;
44pub mod error;
45pub mod ir;
46pub mod optimize;
47pub mod trace;
48
49pub use cache::FunctionCache;
50pub use codegen::{CompiledFunction, JitCompiler};
51pub use compile::{
52 compile_fn, compile_fn_with_config, compile_graph, compile_graph_with_config, Backend,
53 CompileConfig, CompileStats, CompiledModel, LazyCompiled, Mode,
54};
55pub use error::{JitError, JitResult};
56pub use ir::{DataType, Graph, Node, NodeId, Op, Shape};
57pub use optimize::{OptimizationPass, Optimizer};
58pub use trace::{trace, TracedValue, Tracer};
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_simple_trace() {
66 let graph = trace(|tracer| {
67 let a = tracer.input("a", &[2, 3]);
68 let b = tracer.input("b", &[2, 3]);
69 let c = a.add(&b);
70 tracer.output("result", c)
71 });
72
73 assert_eq!(graph.inputs().len(), 2);
74 assert_eq!(graph.outputs().len(), 1);
75 }
76
77 #[test]
78 fn test_optimization() {
79 let graph = trace(|tracer| {
80 let a = tracer.input("a", &[2, 3]);
81 let b = tracer.constant(2.0, &[2, 3]);
82 let c = a.mul(&b);
83 tracer.output("result", c)
84 });
85
86 let mut optimizer = Optimizer::new();
87 optimizer.add_pass(OptimizationPass::ConstantFolding);
88 let optimized = optimizer.optimize(graph);
89
90 assert_eq!(optimized.inputs().len(), 1);
92 }
93}