pub struct CompileCache { /* private fields */ }Implementations§
Source§impl CompileCache
impl CompileCache
pub fn new(device: Device, capacity: usize) -> Self
Sourcepub fn with_policy(
device: Device,
capacity: usize,
policy: Option<PrecisionPolicy>,
) -> Self
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.
Sourcepub fn get_or_compile<F: FnOnce() -> Graph>(
&mut self,
key: u64,
build: F,
) -> &mut CompiledGraph
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.
Sourcepub fn get_or_compile_with_options<F: FnOnce() -> Graph>(
&mut self,
key: u64,
build: F,
options: &CompileOptions,
) -> &mut CompiledGraph
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.
Sourcepub fn ensure_with_params(
&mut self,
key: u64,
graph: Graph,
params: &HashMap<String, Vec<f32>>,
options: &CompileOptions,
) -> &mut CompiledGraph
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.
Retain another entry’s weight buffer for dst_key. False when there is no
compatible entry and the caller must upload.
Sourcepub fn get_or_compile_hir_with_options<F: FnOnce() -> HirModule>(
&mut self,
key: u64,
build: F,
options: &CompileOptions,
) -> &mut CompiledGraph
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.
pub fn is_empty(&self) -> bool
Auto Trait Implementations§
impl !RefUnwindSafe for CompileCache
impl !Sync for CompileCache
impl !UnwindSafe for CompileCache
impl Freeze for CompileCache
impl Send for CompileCache
impl Unpin for CompileCache
impl UnsafeUnpin for CompileCache
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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