Proposing a host-side design for sharing read-only GPU weights across Wasmtime component instances

Abierto
#15,348 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust, wasm

Línea de trabajo

Read the Wasmtime 46.0.3 ResourceTable, Store::into_data, and ResourceLimiter documentation linked in the issue, then review the linked wasi-webgpu-wasmtime host bindings. The issue asks whether existing host APIs support per-instance resource handles, completion tracking, and tenant-wide quotas, or where an API change is needed. Done means maintainers have enough concrete examples to assess the proposed embedding design; no specific code change or test is identified.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I’m working on a host embedding built on Wasmtime for mutually untrusted components that share a GPU. Wasm isolates instances, but giving each tenant a separate GPU address space can mean uploading the same read-only model weights more than once. A shared CUDA context lets the host keep one copy. Can an embedder use Wasmtime’s existing host APIs to control who can read it, track whose work has finished, and enforce each tenant’s quota? I’m using Wasmtime 46.0.3 with component-model enabled. I’d like to propose the host-side design outlined below: each instance gets its own read-only view of shared GPU weights, waits for work on its own logical stream, and draws from a quota shared by all instances of its tenant. Would this design be useful as a Wasmtime embedding example? I’d also welcome feedback on any part that needs changes to Wasmtime’s host APIs.

Two instances on one GPU

Assume instances A and B belong to different tenants. They use the same weights and have private inputs, intermediate buffers, and outputs. For this example, the embedder puts each instance in its own Store. A tenant can own several such stores.

  • Releasing a view. A and B each hold a local handle to the weights. If A requests release of its handle while a kernel it submitted is still running, that kernel must retain access until it finishes. B must also remain able to use its own handle.
  • Waiting on a stream. A submits work on one logical stream, B submits unrelated work, and A then waits on its stream. The target is the work A had submitted to that stream when the call began. B’s work and A’s later submissions fall outside that target. Contention can still delay A.

Host-side resource management

Object-level sharing. The host creates the read-only allocation and gives each authorized instance a local view. Private buffers stay with their owning instance. The host keeps the shared allocation alive while a view or an outstanding submission still references it.

Tenant quotas and logical streams. All instances of a tenant share limits on private GPU memory, unfinished work, and submission rate. Creating another instance or stream gives the tenant no additional allowance. The scheduler rotates among ready tenants and maps logical streams onto a bounded pool of CUDA streams, preserving submission order within each logical stream. Dispatch is non-preemptive.

Three checks before submission. The host restricts the GPU operations available through imports, checks the kernel and its arguments against an allowlist and manifest, then checks the caller’s permissions and the byte range for each object. These checks assume a trusted host, driver, and hardware, and approved kernels that follow their manifests. A fatal fault in the shared GPU context can affect both tenants.

Where I’d like advice from Wasmtime maintainers

  1. Resource ownership. The out-of-tree wasi-webgpu-wasmtime bindings take a host-provided ResourceTable and a reference to an Arc<wgpu_core::global::Global>. The prototype currently uses instance-local integer handles. For a component-resource version, I’m considering putting an Arc to the same host-managed CUDA allocation in each store’s table, while exposing only read access to the guest. Removing an entry and dropping the returned value would release that store’s clone. Given that ResourceTable::push requires Send + 'static, is this the expected pattern for independently droppable handles? If a guest never calls resource.drop and the host doesn’t remove the entry, does it remain until the table is dropped? Would you use ResourceTable::set_max_capacity to bound total table entries in that case and account for GPU memory separately? Host bindings · ResourceTable

  2. Completion and teardown. Driver acceptance can precede GPU completion. On entry to a wait, I would capture the stream’s submission counter and wait through that target. An Arc held outside A’s store would keep a host service alive. That service would retain each submission’s object references and pending-work charge. Alternatively, if I control teardown, I could consume the live store with Store::into_data to recover its host state. If A traps and the embedder drops its store, is keeping the service alive independently the recommended way to let accepted work finish, or is there a Wasmtime trap or teardown hook I should use? After the call returns, the service would hold only host-owned references and accounting data. Any borrow of A’s guest memory would end within the call. If completion cannot be confirmed, the service would retain the references and charges until it can confirm that the GPU context has been destroyed. Store::into_data

  3. Accounting across stores. I would put a shared tenant-budget handle (for example, an Arc) in each of that tenant’s stores and charge GPU operations when a host function admits them. My reading is that ResourceLimiter limits linear-memory and table growth and the numbers of instances, memories, and tables within a store. The embedder accounts for its own allocations. Is shared host state plus admission checks in the GPU host functions the expected boundary, or should another Wasmtime mechanism be involved? If any of these cases needs a change in Wasmtime, a concrete example of where the current API falls short would help narrow the request. Store data · ResourceLimiter

Lenguaje dominante
Rust
Estrellas
18.9k
Forks
2k
Merge medio
1 d 6 h
PR fusionados (30 d)
238

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bytecodealliance/wasmtime

Todos los issues de bytecodealliance/wasmtime

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.