Skip to main content

CompileCache

Struct CompileCache 

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

Implementations§

Source§

impl CompileCache

Source

pub fn new(device: Device, capacity: usize) -> Self

Source

pub fn with_policy( device: Device, capacity: usize, policy: Option<PrecisionPolicy>, ) -> Self

Cache that compiles every entry with the given precision policy. Use this when the cached entries should differ from CPU-default F32 — e.g., PrecisionPolicy::AutoMixed for f16 compute on Metal.

Source

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

Compile if not present, then return a mutable reference. The borrow lifetime is tied to &mut self so callers naturally serialize their use of any one entry — the cache is single-owner today.

Source

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

Like Self::get_or_compile with explicit CompileOptions.

Source

pub fn ensure_with_params( &mut self, key: u64, graph: Graph, params: &HashMap<String, Vec<f32>>, options: &CompileOptions, ) -> &mut CompiledGraph

Compile key if absent, then give it weights — retaining another entry’s uploaded buffer when the layout matches, and uploading params only when it does not.

The point of the cache is holding several shapes of one model at once, so without sharing its own hit rate is what costs the memory: each extra prompt length is another full copy of the weights, host and device.

Source

pub fn try_share_params_from_donor(&mut self, dst_key: u64) -> bool

Retain another entry’s weight buffer for dst_key. False when there is no compatible entry and the caller must upload.

Source

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

Like Self::get_or_compile_with_options but builds and compiles HIR directly.

Source

pub fn len(&self) -> usize

Number of entries currently cached. Useful for tests + diagnostics.

Source

pub fn is_empty(&self) -> bool

Source

pub fn contains(&self, key: u64) -> bool

Was this key already compiled? Doesn’t change recency.

Source

pub fn clear(&mut self)

Drop all cached compiled graphs (free weight params).

Source

pub fn sync_all(&mut self)

Drain in-flight GPU work on every cached entry (Metal commit_no_wait paths).

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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,