Skip to main content

TensorWasmMemoryCreator

Struct TensorWasmMemoryCreator 

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

A MemoryCreator that hands out TensorWasmLinearMemory instances.

Wrap in Arc and pass to wasmtime::Config::with_host_memory.

Implementations§

Source§

impl TensorWasmMemoryCreator

Source

pub fn new(device_id: DeviceId) -> Self

Construct without an underlying pool. New memories allocate fresh UnifiedBuffers on every new_memory call. Uses the default MemoryCreatorConfig (per-instance cap = HARD_MAX_LINEAR_MEMORY_BYTES).

Source

pub fn with_config(device_id: DeviceId, config: MemoryCreatorConfig) -> Self

Construct without an underlying pool, with a custom MemoryCreatorConfig (e.g. a tighter per-instance cap for multi-tenant deployments). The configured cap is clamped to HARD_MAX_LINEAR_MEMORY_BYTES — see MemoryCreatorConfig::effective_max_linear_memory_bytes.

Source

pub fn with_tenant_context( device_id: DeviceId, tenant_ctx: Arc<TenantContext>, ) -> Self

Construct a tenant-aware creator that accounts every fresh UnifiedBuffer against the tenant’s GPU memory cap.

Roadmap feature #8 builder: holds an Arc<TenantContext> and routes the no-pool / pool-fallback allocation paths through UnifiedBuffer::new_on_with_tenant_context. On a cap violation the underlying error is tensor_wasm_core::error::TensorWasmError::GpuMemoryExhausted; it surfaces here as a String because Wasmtime’s MemoryCreator::new_memory returns Result<_, String>.

Pool-carved memories are intentionally unmetered — see the note on MemoryCreatorState::tenant_ctx for the rationale and the v0.4 follow-up.

Source

pub fn with_pool_and_tenant_context( device_id: DeviceId, pool: Arc<UnifiedMemoryPool>, tenant_ctx: Arc<TenantContext>, ) -> Self

Tenant-aware variant of Self::with_pool.

Behaves like Self::with_pool for the pool-carve hot path (no extra counter traffic) and like Self::with_tenant_context for the fallback fresh-allocation path.

Source

pub fn with_pool(device_id: DeviceId, pool: Arc<UnifiedMemoryPool>) -> Self

Construct with a pre-allocated pool. new_memory carves out of this slab; on exhaustion it falls back to a fresh UnifiedBuffer so a short slab does not turn into a fatal error.

Lifetime contract. Pool-backed linear memories form an all-or-nothing batch: the caller must drop every Wasm instance handed out by this creator before dropping the last Arc<UnifiedMemoryPool> reference and calling UnifiedMemoryPool::reset. See new_memory for the unsafe rationale.

Source

pub fn with_pool_and_config( device_id: DeviceId, pool: Arc<UnifiedMemoryPool>, config: MemoryCreatorConfig, ) -> Self

Construct with both a pre-allocated pool and a custom MemoryCreatorConfig.

Source

pub fn device_id(&self) -> DeviceId

The device this creator targets.

Source

pub fn pool(&self) -> Option<&Arc<UnifiedMemoryPool>>

The underlying pool, if one was provided at construction.

Source

pub fn config(&self) -> &MemoryCreatorConfig

The tunable configuration handed to this creator.

Trait Implementations§

Source§

impl Clone for TensorWasmMemoryCreator

Source§

fn clone(&self) -> TensorWasmMemoryCreator

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 Default for TensorWasmMemoryCreator

Source§

fn default() -> Self

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

impl MemoryCreator for TensorWasmMemoryCreator

Source§

fn new_memory( &self, _ty: MemoryType, minimum: usize, maximum: Option<usize>, reserved_size_in_bytes: Option<usize>, guard_size_in_bytes: usize, ) -> Result<Box<dyn LinearMemory>, String>

Create a new LinearMemory object from the specified parameters. 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> 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> 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