1#![warn(missing_docs)]
39#![allow(clippy::module_name_repetitions)]
40
41pub mod ir;
42pub mod trace;
43pub mod optimize;
44pub mod codegen;
45pub mod cache;
46pub mod compile;
47pub mod error;
48
49pub use ir::{Graph, Node, NodeId, Op, DataType, Shape};
50pub use trace::{Tracer, TracedValue, trace};
51pub use optimize::{Optimizer, OptimizationPass};
52pub use codegen::{JitCompiler, CompiledFunction};
53pub use cache::FunctionCache;
54pub use compile::{
55 compile_fn, compile_fn_with_config, compile_graph, compile_graph_with_config,
56 Backend, CompileConfig, CompiledModel, CompileStats, LazyCompiled, Mode,
57};
58pub use error::{JitError, JitResult};
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}