pub struct TensorWasmLinearMemory { /* private fields */ }Expand description
A Wasm linear memory backed by UnifiedBuffer.
The buffer is allocated at construction time with the requested maximum
(or DEFAULT_MAX_BYTES) so grow_to becomes a size check. This avoids
the cost of cudaMemcpy on every memory.grow and keeps the kernel-side
pointer stable across growth events.
Implementations§
Source§impl TensorWasmLinearMemory
impl TensorWasmLinearMemory
Sourcepub fn new(
minimum_bytes: usize,
maximum_bytes: Option<usize>,
) -> Result<Self, UnifiedError>
pub fn new( minimum_bytes: usize, maximum_bytes: Option<usize>, ) -> Result<Self, UnifiedError>
Create a new linear memory.
minimum_bytes: initial visible size (Wasm pages × 65 536).maximum_bytes: cap on growth. IfNone,DEFAULT_MAX_BYTESis used.
Sourcepub fn new_on(
minimum_bytes: usize,
maximum_bytes: Option<usize>,
device_id: DeviceId,
) -> Result<Self, UnifiedError>
pub fn new_on( minimum_bytes: usize, maximum_bytes: Option<usize>, device_id: DeviceId, ) -> Result<Self, UnifiedError>
Same as new but on a specific device.
Fails with UnifiedError::TooLarge when maximum_bytes (or the
minimum_bytes floor) would exceed HARD_MAX_LINEAR_MEMORY_BYTES.
This closes mem-H5 / exec-S-2 / exec-S-10: Wasmtime’s
wasmtime::ResourceLimiter::memory_growing only fires on
memory.grow, so a guest declaring (memory 1 65536) would
otherwise force a 4 GiB allocation at instantiation. The hard cap
is enforced before the backing allocator is invoked.
Sourcepub fn new_on_with_tenant_context(
minimum_bytes: usize,
maximum_bytes: Option<usize>,
device_id: DeviceId,
tenant_ctx: Arc<TenantContext>,
) -> Result<Self, TensorWasmError>
pub fn new_on_with_tenant_context( minimum_bytes: usize, maximum_bytes: Option<usize>, device_id: DeviceId, tenant_ctx: Arc<TenantContext>, ) -> Result<Self, TensorWasmError>
Tenant-aware variant of Self::new_on.
Routes the underlying UnifiedBuffer allocation through
UnifiedBuffer::new_with_visible_window_on_with_tenant_context
so the tenant’s GPU memory cap is consulted before allocation
and release_gpu_bytes(cap) is called on Drop. The same
HARD_MAX_LINEAR_MEMORY_BYTES ceiling and min > max checks
run first so a cap violation never races against a guest-bug
rejection.
Roadmap feature #8 path: invoked by
TensorWasmMemoryCreator::with_tenant_context /
TensorWasmMemoryCreator::with_pool_and_tenant_context whenever
they fall through to the no-pool fresh-allocation branch.
Sourcepub fn current_size(&self) -> usize
pub fn current_size(&self) -> usize
Current logical size in bytes.
Sourcepub fn is_uvm_backed(&self) -> bool
pub fn is_uvm_backed(&self) -> bool
Whether the underlying linear-memory backing is CUDA Unified Memory.
Returns true when the crate was compiled with EITHER
--features unified-memory (cust path) OR --features cudarc-backend
(the W1.2 spike, used as the Backing::Cudarc variant when
unified-memory is off — see the precedence table in
crate::unified). This is the compile-time probe that closes the
v0.3.2 audit’s “wasm linear memory not UVM-backed” gap: a guest
pointer resolved through the W1.1 wasi-cuda kernel-args pipeline
doubles as a device pointer iff this returns true. The pool-backed
PooledLinearMemory path also goes through UnifiedBuffer under
the hood, so it shares this property regardless of which CUDA
backing feature is active.
§Memory-growth semantics
cuMemAllocManaged returns a fixed-size allocation that cannot be
resized in place. We therefore pre-allocate the requested
maximum_bytes (or DEFAULT_MAX_BYTES) at construction time and
treat LinearMemory::grow_to as a logical-size bump up to that
cap (option (a) from the v0.3.3 design tracker). This matches
Wasmtime’s static memory model, keeps the kernel-side pointer
stable across growth events, and keeps the hot path zero-copy at
the cost of reserving the worst-case footprint up front. Growing
the physical allocation (option (b): allocate-copy-free) is a
v0.4 follow-up tracked in docs/RISKS.md.
Trait Implementations§
Source§impl Debug for TensorWasmLinearMemory
impl Debug for TensorWasmLinearMemory
Source§impl LinearMemory for TensorWasmLinearMemory
impl LinearMemory for TensorWasmLinearMemory
Source§fn byte_size(&self) -> usize
fn byte_size(&self) -> usize
Source§fn byte_capacity(&self) -> usize
fn byte_capacity(&self) -> usize
Auto Trait Implementations§
impl !RefUnwindSafe for TensorWasmLinearMemory
impl !UnwindSafe for TensorWasmLinearMemory
impl Freeze for TensorWasmLinearMemory
impl Send for TensorWasmLinearMemory
impl Sync for TensorWasmLinearMemory
impl Unpin for TensorWasmLinearMemory
impl UnsafeUnpin for TensorWasmLinearMemory
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> 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