Skip to main content

KernelCacheConfig

Struct KernelCacheConfig 

Source
pub struct KernelCacheConfig {
    pub capacity: usize,
    pub max_total_bytes: Option<u64>,
    pub verify_on_get: bool,
    pub registry: Option<Arc<dyn KernelRegistry>>,
}
Expand description

Construction-time configuration for KernelCache.

Holds the small set of policy knobs the cache supports today: capacity (count cap) and whether to recompute the per-entry BLAKE3 integrity hash on every get. Future knobs (per-byte cap, eviction policy choice) will land here without breaking the existing KernelCache::with_capacity / KernelCache::with_disk_persistence shorthands — those construct an equivalent KernelCacheConfig under the hood.

Construct via KernelCacheConfig::default (which mirrors the historical defaults — capacity DEFAULT_CAPACITY, verify-on-get true) and refine with the with_* builders, then hand the config to KernelCache::with_config.

Fields§

§capacity: usize

Soft maximum L1 entry count. Clamped to >= 1 inside the cache.

§max_total_bytes: Option<u64>

Optional soft maximum on the total bytes of cached PTX text held in L1, summed across every live entry (each entry contributes cached.ptx.text.len()). When Some(cap), KernelCache::put evicts LRU entries — using the same eviction queue the count cap drives — until the running byte total fits under cap, after admitting the new entry. The count cap (Self::capacity) still applies independently; whichever cap binds first wins.

Why this exists: the count cap alone is a DoS vector. A 256-slot cache fed adversarial multi-MB PTX blueprints (a deliberately unrolled kernel can emit 10 MB of PTX) reaches ~2.5 GB of resident L1 — see the memory-ceiling note on DEFAULT_CAPACITY. The byte cap bounds the worst case regardless of per-entry size.

A single entry larger than cap is still admitted (the cache never refuses an insert outright — it would otherwise wedge the dispatch path) but it will evict every other entry first; the byte total may transiently exceed cap by at most one such oversized entry.

Default None (preserves the historical count-only behaviour). Set via Self::with_max_total_bytes. Track the live total via KernelCache::total_bytes.

§verify_on_get: bool

When true (the default), KernelCache::get recomputes a BLAKE3 over the cached ptx.text on every L1 hit and compares the result against the entry’s stored integrity_hash (jit S-3 in-mem poisoning defence). When false, the recompute is skipped — the cache still refuses entries whose stored hash is all-zero (the construction signal for “built without CachedKernel::new”) as defence-in-depth.

The recompute costs ~10 µs over a typical multi-KB PTX blob; skipping it shaves that off every L1 hit at the cost of widening the in-memory poisoning window from “one get call” to “the lifetime of the entry in L1”. Operators on a high-QPS path with multi-MB PTX where the recompute dominates can opt out, but the safe default is verify-on-get.

§registry: Option<Arc<dyn KernelRegistry>>

Optional registry consulted on L1+L2 miss. v0.4 path: caller resolves (tenant, blueprint, sm_version) → (name, version) via an external lookup, then KernelCache::get_with_registry_fallback consults the registry by that pair. v0.3.8 ships a resolve_by_blueprint_hint trait method on the cache config for the resolver step; the in-memory test impl resolves blueprint fingerprint → name@version directly via a HashMap.

Implementations§

Source§

impl KernelCacheConfig

Source

pub fn with_capacity(self, capacity: usize) -> Self

Override the L1 entry count cap. Clamped to >= 1 at cache construction time; values below 1 are silently raised.

Source

pub fn with_max_total_bytes(self, max_total_bytes: u64) -> Self

Set the soft total-bytes cap on resident L1 PTX. None (the default) preserves the historical count-only behaviour; Some(cap) makes KernelCache::put evict LRU entries until the running PTX byte total fits under cap. See the field-level docs on Self::max_total_bytes for the DoS-mitigation rationale and the single-oversized-entry caveat.

Source

pub fn with_verify_on_get(self, on: bool) -> Self

Toggle the per-get BLAKE3 recompute. Default true; setting false is the high-QPS opt-out. See the field-level docs on Self::verify_on_get for the threat-model trade-off.

Source

pub fn with_registry(self, reg: Arc<dyn KernelRegistry>) -> Self

Attach a KernelRegistry as the L3 fallback consulted by KernelCache::get_with_registry_fallback on an L1+L2 miss. Default is None (registry path disabled). See the field-level docs on Self::registry for the resolution contract.

Trait Implementations§

Source§

impl Clone for KernelCacheConfig

Source§

fn clone(&self) -> KernelCacheConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KernelCacheConfig

Source§

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

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

impl Default for KernelCacheConfig

Source§

fn default() -> Self

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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> 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