pub struct JitCompiler {
pub hot_threshold: usize,
/* private fields */
}Expand description
JIT compiler with hot-path detection and pre-optimized graph caching.
§Example
use tensorlogic_compiler::JitCompiler;
use tensorlogic_ir::{TLExpr, Term};
let jit = JitCompiler::new(3);
let expr = TLExpr::pred("knows", vec![Term::var("x"), Term::var("y")]);
for _ in 0..5 {
let graph = jit.compile(&expr).expect("compile");
let _ = graph;
}
let stats = jit.stats();
assert_eq!(jit.hot_path_count(), 1);
assert!(stats.jit_hits > 0);Fields§
§hot_threshold: usizeNumber of compilations required before an expression is promoted.
Implementations§
Source§impl JitCompiler
impl JitCompiler
Sourcepub fn new(hot_threshold: usize) -> Self
pub fn new(hot_threshold: usize) -> Self
Create a new JIT compiler with default CompilationConfig.
hot_threshold is the number of compilations an expression must
accumulate before it is promoted to the hot-path cache.
Sourcepub fn with_config(config: CompilationConfig, hot_threshold: usize) -> Self
pub fn with_config(config: CompilationConfig, hot_threshold: usize) -> Self
Create a new JIT compiler with a custom CompilationConfig.
Sourcepub fn compile(&self, expr: &TLExpr) -> Result<Arc<EinsumGraph>, JitError>
pub fn compile(&self, expr: &TLExpr) -> Result<Arc<EinsumGraph>, JitError>
Compile expr, returning a shared Arc<EinsumGraph>.
- On the first
hot_thresholdcalls the expression is compiled via the normal cold path. - When the call count reaches
hot_thresholdthe expression is optimised with an aggressive expression-level pass and recompiled; the result is inserted into the hot-path cache. - All subsequent calls for the same expression return the cached graph directly without invoking the compiler.
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Evict all cached hot-path graphs and reset all counters.
After this call the JIT compiler behaves as if it were freshly constructed.
Sourcepub fn hot_path_count(&self) -> usize
pub fn hot_path_count(&self) -> usize
Return the number of distinct expressions currently in the hot-path cache.
Sourcepub fn call_count(&self, expr: &TLExpr) -> usize
pub fn call_count(&self, expr: &TLExpr) -> usize
Return the total number of times expr has been compiled via this instance.
Returns 0 if expr has never been seen.
Auto Trait Implementations§
impl Freeze for JitCompiler
impl RefUnwindSafe for JitCompiler
impl Send for JitCompiler
impl Sync for JitCompiler
impl Unpin for JitCompiler
impl UnsafeUnpin for JitCompiler
impl UnwindSafe for JitCompiler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more