pub struct CacheKey {
pub tenant_id: u64,
pub blueprint: u64,
pub sm_version: u32,
pub emit_config_hash: u64,
}Expand description
Cache key.
tenant_id is the first field so that it dominates the derived Hash
(field-order) and lexicographic Ord orderings. Keeping the cache keyed
by tenant is the only thing preventing tenant A from looking up — and on
the CUDA path executing — a compiled kernel that tenant B installed
(exec S-7, cross-tenant confused-deputy). Every host-side get / put
MUST therefore include the calling tenant; constructing a key without
one (e.g. directly from guest-supplied bytes) is the bug we are fixing.
Fields§
§tenant_id: u64Owning tenant. Cache lookups MUST be scoped to the caller’s tenant —
see the type-level docs. Use CacheKey::for_tenant to construct.
blueprint: u64TensorWasmKernelBlueprint::fingerprint().
sm_version: u32CUDA compute capability (e.g. 80 for sm_80, 89 for sm_89).
emit_config_hash: u64Hash of the full crate::ptx_emit::EmitConfig used at emit time
(jit S-2). sm_version covers the compute capability number but NOT
the architecture suffix (e.g. "sm_80" vs "sm_80a"), the PTX
language version, or the launch_bounds flag — two EmitConfigs
that differ in any of those produce non-interchangeable PTX. Without
this field two such configs would collide on the same key and the
second caller would silently get the first caller’s PTX.
Callers that don’t have an EmitConfig (rewriter pre-population,
benches) pass 0. Construct via CacheKey::for_tenant (defaults
to 0) or CacheKey::for_tenant_with_emit_config (computes a
stable hash over the config).
Implementations§
Source§impl CacheKey
impl CacheKey
Sourcepub fn for_tenant(tenant_id: TenantId, blueprint: u64, sm_version: u32) -> Self
pub fn for_tenant(tenant_id: TenantId, blueprint: u64, sm_version: u32) -> Self
Construct a tenant-scoped cache key with no EmitConfig hash.
Equivalent to passing emit_config_hash: 0 — appropriate for the
rewriter and bench paths that use the default emitter config. The
tenant_id MUST come from trusted store state (e.g.
InstanceState::tenant_id), never from guest-supplied fingerprint
bytes. See the CacheKey docs for the confused-deputy primitive
this guards against.
Sourcepub fn for_tenant_with_emit_config(
tenant_id: TenantId,
blueprint: u64,
sm_version: u32,
cfg: &EmitConfig,
) -> Self
pub fn for_tenant_with_emit_config( tenant_id: TenantId, blueprint: u64, sm_version: u32, cfg: &EmitConfig, ) -> Self
Construct a tenant-scoped cache key that also covers the emitter config. Use this when the lookup must distinguish between PTX-version variants, target-architecture suffixes, or launch-bounds settings (jit S-2).
Cost note: each call builds a fresh blake3::Hasher and finalises
over a handful of bytes. The amortised wall cost is ~µs on a
modern x86-64 box — negligible compared to a kernel dispatch but
non-zero on the hot path. Callers that resolve the same
EmitConfig for every lookup (the typical pattern: emit-config is
pinned at instance-spawn time) should hash it once at spawn and
reuse the CacheKey rather than re-deriving it for every
dispatch. The hasher itself is intentionally inline here (not
memoised) so the function stays pure and Send-friendly for the
rewriter’s rayon::par_iter callers.
Trait Implementations§
impl Copy for CacheKey
impl Eq for CacheKey
Source§impl Ord for CacheKey
impl Ord for CacheKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for CacheKey
impl PartialOrd for CacheKey
impl StructuralPartialEq for CacheKey
Auto Trait Implementations§
impl Freeze for CacheKey
impl RefUnwindSafe for CacheKey
impl Send for CacheKey
impl Sync for CacheKey
impl Unpin for CacheKey
impl UnsafeUnpin for CacheKey
impl UnwindSafe for CacheKey
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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