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

オープン
#15,348 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust, wasm

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
18.9k
フォーク
2k
平均マージ
1日 6時間
マージ済み PR(30日)
238

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bytecodealliance/wasmtime のほかの issue

bytecodealliance/wasmtime の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。