Back to Runanywhere Sdks

Why WASM *and* WebGPU?

sdk/runanywhere-web/docs/WASM_AND_WEBGPU.md

0.20.122.2 KB
Original Source

Why WASM and WebGPU?

Short answer: WebGPU accelerates the math; WASM runs the engine that owns the model.

text
Browser tab
  TS facade → BackendWorker
                 │
                 ▼
        ┌─────────────────────┐
        │  WASM module        │  llama.cpp / ORT+Sherpa
        │  weights, graph,    │  C++ via Emscripten
        │  tokenizer, I/O     │
        └─────────┬───────────┘
                  │ ggml / ORT EP
                  ▼
        ┌─────────────────────┐
        │  WebGPU (GPU)       │  optional accelerator
        │  or CPU threads     │
        └─────────────────────┘

Roles

LayerJob
WASMPortable C++ runtime in the browser: load GGUF/ONNX, tokenize, session state, streaming callbacks, pthread pools, OPFS hydrate. Without this you rewrite the whole engine in JS.
WebGPUBrowser GPU API. llama.cpp’s ggml-webgpu (and eventually ORT’s WebGPU EP) submit shaders from inside that WASM. It does not replace the engine.
BackendWorkerDedicatedWorker so inference does not block the UI thread. Hosts the WASM heap.

Why not “just WebGPU”?

WebGPU alone has no Whisper/Piper/GGUF loader, no Sherpa transducer decoding, no llama.cpp sampling loop. Those live in C++. Compiling that C++ to WASM is how we share one codebase with iOS/Android/desktop.

Native mobile uses CoreML / NNAPI / Metal from the same C++ via different EPs. On Web the EP is CPU (SIMD/threads) or WebGPU.

Per-backend today

BackendWASM artifactAccelerator
LLM/VLMracommons-llamacpp + -webgpuWebGPU (ggml) when available
Speech / ONNX emb / RAGracommons-onnx-sherpa + -webgpu twinORT WebGPU EP when probe succeeds; else CPU (+ threads). Same BackendWorker for speech + embeddings.
Diffusion / seg / diarNo browser engine yet

Inspect live status: RunAnywhere.runtime.modalities / RunAnywhere.runtime.speech. Release and vendor details: ONNX_WEBGPU.md.