Skip to main content

BucketedCompileCache

Struct BucketedCompileCache 

Source
pub struct BucketedCompileCache { /* private fields */ }

Implementations§

Source§

impl BucketedCompileCache

Source

pub fn new(device: Device, buckets: Vec<Range<u64>>) -> Self

Source

pub fn power_of_two_ladder(device: Device, min: u64, max: u64) -> Self

Power-of-two ladder over [1, max], with extents [min_pow2, 2·min_pow2, 4·min_pow2, …, max_pow2] where min_pow2 = min.next_power_of_two() and max_pow2 is the smallest power of two ≥ max. Each bucket compiles at its upper-bound extent, so an actual value in bucket (prev_extent .. ext] runs kernels at extent ext (not at the worst case of the whole range). Guarantees compute waste from padding ≤2× — actual > ext / 2 for every bucket except possibly the smallest.

Example: power_of_two_ladder(Device::Cpu, 8, 256) yields buckets 1..9, 9..17, 17..33, 33..65, 65..129, 129..257 with compile extents 8, 16, 32, 64, 128, 256. An actual = 17 runs at extent 32 instead of the 255 a single wide 1..256 bucket would compile at — that’s the “skip compute” win, paid for with O(log max) compiled artifacts instead of one.

Source

pub fn power_of_two_ladder_with_policy( device: Device, min: u64, max: u64, policy: Option<PrecisionPolicy>, ) -> Self

Source

pub fn with_policy( device: Device, buckets: Vec<Range<u64>>, policy: Option<PrecisionPolicy>, ) -> Self

Source

pub fn get_or_compile<F: FnOnce(u64) -> Graph>( &mut self, key: u64, build: F, ) -> Option<(u64, &mut CompiledGraph)>

Find the bucket containing key, compile if needed, return (upper, &mut CompiledGraph) where upper = range.end - 1 is the extent the graph was compiled for. Caller pads inputs to upper before calling run. Returns None if key is outside every bucket — caller decides whether to fall back to a one-off compile.

build receives upper and must return a Graph specialized for that extent.

Source

pub fn get_or_compile_with_options<F: FnOnce(u64) -> Graph>( &mut self, key: u64, build: F, options: &CompileOptions, ) -> Option<(u64, &mut CompiledGraph)>

Like Self::get_or_compile with explicit [CompileOptions].

Source

pub fn get_or_compile_hir<F: FnOnce(u64) -> HirModule>( &mut self, key: u64, build: F, ) -> Option<(u64, &mut CompiledGraph)>

Like Self::get_or_compile but builds and compiles HIR directly through the fusion-first pipeline (Session::compile_hir).

Source

pub fn get_or_compile_hir_with_options<F: FnOnce(u64) -> HirModule>( &mut self, key: u64, build: F, options: &CompileOptions, ) -> Option<(u64, &mut CompiledGraph)>

Like Self::get_or_compile_hir with explicit [CompileOptions] (tier-1 profile, fusion target, …).

Source

pub fn bucket_for(&self, key: u64) -> Option<usize>

Index of the bucket containing key, or None if out of range. Linear scan — bucket counts are small in practice.

Source

pub fn buckets(&self) -> impl Iterator<Item = &Range<u64>>

Source

pub fn compiled_count(&self) -> usize

Number of buckets that have been compiled so far (≤ total buckets).

Source

pub fn total_buckets(&self) -> usize

Source

pub fn run_padded<F: FnOnce(u64) -> Graph>( &mut self, key: u64, actual_rows: usize, build: F, inputs: &[(&str, &[f32], usize)], output_inners: &[usize], ) -> Option<(u64, Vec<Vec<f32>>)>

“Compile at max, run at less” convenience for inputs and outputs whose outer dimension is the bucket key:

  1. Find or compile the bucket containing key.
  2. For each input, pad to upper rows along the outer dim using pad_rows (caller passes the inner-dim stride per input; inner = 1 for purely 1D inputs).
  3. Run the compiled graph at full extent.
  4. Slice each output back to actual_rows along its outer dim. Outputs flagged with inner = 0 in output_inners are returned unsliced (use this for extent-independent outputs like a pooled [hidden] embedding). Missing entries past the end of output_inners are also returned unsliced.

Returns (upper, outputs). Returns None if key falls outside every bucket.

Compute scope: kernels execute at the bucket’s compile extent (upper), not at actual_rows. This means smaller buckets directly translate to less padded compute. With power_of_two_ladder the worst- case waste is bounded at 2×; with hand-tuned buckets it can be arbitrarily tight. True active-extent dispatch — one big compile, kernels short-circuit at runtime — is a separate per-backend change.

Source

pub fn ensure_graph_with_params<F>( &mut self, key: u64, build: F, options: &CompileOptions, ) -> Option<(u64, &mut CompiledGraph)>
where F: FnOnce(u64) -> (Graph, HashMap<String, Vec<f32>>),

Like Self::get_or_compile_with_options but also uploads params on first compile.

Source

pub fn ensure_hir_with_params<F>( &mut self, key: u64, build: F, options: &CompileOptions, ) -> Option<(u64, &mut CompiledGraph)>
where F: FnOnce(u64) -> (HirModule, HashMap<String, Vec<f32>>),

Source

pub fn run_padded_mixed<F>( &mut self, key: u64, actual_rows: usize, build: F, inputs: &[CacheRunInput<'_>], output_inners: &[usize], ) -> Option<(u64, Vec<Vec<f32>>)>
where F: FnOnce(u64) -> Graph,

Self::run_padded with per-input optional row padding (CacheRunInput).

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.
Source§

impl<T> WasmNotSend for T
where T: Send,