1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 Craton Software Company
//! Multi-tenant CUDA context management for Craton TensorWasm.
//!
//! This crate owns the per-tenant runtime handle ([`TenantContext`]) and the
//! concurrent registry that maps a [`tensor_wasm_core::types::TenantId`] to it
//! ([`TenantRegistry`]). The registry also decides between MPS-backed shared
//! contexts and per-tenant `cuCtxCreate` fallback via a filesystem probe — see
//! `docs/MPS-SETUP.md` for daemon configuration and `SECURITY.md` for the
//! threat model that motivates the [`IsolationKind`] taxonomy.
//!
//! # Quick start
//!
//! Two distinct capability primitives:
//!
//! * [`TenantCapability`] — minted per-tenant by
//! [`TenantRegistry::register_with_capability`], required to drive that
//! tenant's quota counters (`consume_bytes_with_capability` /
//! `release_bytes_with_capability`). Holding an `Arc<TenantContext>` for
//! tenant A grants no power to mutate tenant B's accounting.
//! * [`RegistryAdminCapability`] — minted once by [`TenantRegistry::new`],
//! required to invoke registry-wide admin operations
//! ([`TenantRegistry::get`], [`TenantRegistry::unregister`],
//! [`TenantRegistry::tenants`], [`TenantRegistry::len`]). Without it, any
//! holder of an `Arc<TenantRegistry>` could enumerate or evict tenants.
//!
//! ```
//! # #[cfg(not(feature = "cuda"))]
//! # fn main() {
//! use tensor_wasm_core::types::TenantId;
//! use tensor_wasm_tenant::{TenantContext, TenantRegistry};
//!
//! let (reg, admin_cap) = TenantRegistry::new();
//! let (ctx, tenant_cap) = reg
//! .register_with_capability(TenantContext::builder(TenantId(1)).build())
//! .unwrap();
//! ctx.consume_bytes_with_capability(&tenant_cap, 4096).unwrap();
//! assert_eq!(ctx.bytes_in_use(), 4096);
//! // Admin cap is required to look the tenant up again by id.
//! assert!(reg.get(TenantId(1), &admin_cap).is_some());
//! # }
//! # #[cfg(feature = "cuda")]
//! # fn main() {}
//! ```
pub use ;
pub use ;