Skip to main content

JitCompiler

Struct JitCompiler 

Source
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: usize

Number of compilations required before an expression is promoted.

Implementations§

Source§

impl JitCompiler

Source

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.

Source

pub fn with_config(config: CompilationConfig, hot_threshold: usize) -> Self

Create a new JIT compiler with a custom CompilationConfig.

Source

pub fn compile(&self, expr: &TLExpr) -> Result<Arc<EinsumGraph>, JitError>

Compile expr, returning a shared Arc<EinsumGraph>.

  • On the first hot_threshold calls the expression is compiled via the normal cold path.
  • When the call count reaches hot_threshold the 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.
Source

pub fn stats(&self) -> JitStats

Return a snapshot of the current JIT statistics.

Source

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.

Source

pub fn hot_path_count(&self) -> usize

Return the number of distinct expressions currently in the hot-path cache.

Source

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.

Source

pub fn threshold(&self) -> usize

Return the hot-path threshold used by this instance.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.