Skip to main content

ModuleBinaryCache

Struct ModuleBinaryCache 

Source
pub struct ModuleBinaryCache { /* private fields */ }
Expand description

An in-memory cache mapping (SPIR-V, build flags) to compiled native binaries, with hit/miss accounting.

A backend looks up a key before calling zeModuleCreate; on a miss it JITs the SPIR-V, retrieves the native binary, and inserts it so later identical modules skip the JIT. The cache is the host-side half of zeModuleGetNativeBinary persistence — serialising the map to disk (a trivial extension) gives cross-run reuse.

Implementations§

Source§

impl ModuleBinaryCache

Source

pub fn new() -> Self

An empty cache.

Source

pub fn len(&self) -> usize

Number of cached binaries.

Source

pub fn is_empty(&self) -> bool

true when nothing is cached.

Source

pub fn hits(&self) -> u64

Cumulative cache hits.

Source

pub fn misses(&self) -> u64

Cumulative cache misses.

Source

pub fn hit_rate(&self) -> f64

Hit rate in [0, 1]; 0.0 when there have been no lookups.

Source

pub fn lookup( &mut self, spirv: &[u32], build_flags: &str, ) -> Option<&NativeBinary>

Look up a compiled binary for spirv + build_flags, recording a hit or miss. Returns None on a miss (the caller must JIT and insert).

Source

pub fn insert(&mut self, spirv: &[u32], binary: NativeBinary) -> u64

Insert a compiled native binary for spirv, returning its cache key.

The binary’s own build_flags are folded into the key so two builds of the same SPIR-V with different flags do not collide.

Source

pub fn get(&self, key: u64) -> Option<&NativeBinary>

Fetch a binary by its precomputed key without affecting statistics.

Source

pub fn clear(&mut self)

Remove all cached binaries (statistics are preserved).

Source

pub fn total_bytes(&self) -> usize

Total bytes occupied by all cached native binaries.

Trait Implementations§

Source§

impl Debug for ModuleBinaryCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModuleBinaryCache

Source§

fn default() -> ModuleBinaryCache

Returns the “default value” for a type. Read more

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more