tree: 3cf2b3e029e54056a909de8532be527ff69dbb5d [path history] [tgz]
  1. build_sample.sh
  2. CMakeLists.txt
  3. device_webgpu.c
  4. index.html
  5. iree_api_webgpu.js
  6. main.c
  7. multiple_results.mlir
  8. README.md
  9. serve_sample.sh
experimental/web/sample_webgpu/README.md

WebGPU Sample

This experimental sample demonstrates one way to target the web platform with IREE, using WebGPU. The output artifact is a web page that loads separately provided IREE .vmfb (compiled ML model) files and allows for calling functions on them.

Quickstart

Note: you will need a WebGPU-compatible browser. Chrome Canary with the #enable-unsafe-webgpu flag is a good choice (you may need the flag or an origin trial token for localhost).

  1. Install IREE's host tools (e.g. by building the install target with CMake)
  2. Install the Emscripten SDK by following these directions
  3. Initialize your Emscripten environment (e.g. run emsdk_env.bat)
  4. From this directory, run bash ./build_sample.sh [path to install] && bash ./serve_sample.sh
  5. Open the localhost address linked in the script output

To rebuild most parts of the sample (C runtime, sample HTML, CMake config, etc.), just control + C to stop the local webserver and rerun the script.

How it works

Emscripten is used (via the emcmake CMake wrapper) to compile the runtime into WebAssembly and JavaScript files.

Any supported IREE program, such as simple_abs.mlir, is compiled using the WebGPU compiler target. This generates WGSL shader code and IREE VM bytecode, which the IREE runtime is able to load and run using the browser's WebGPU APIs.

Asynchronous API

iree_api_webgpu.js

  • exposes a Promise-based API to the hosting application in index.html
  • preinitializes a WebGPU adapter and device
  • includes Emscripten's JS code and instantiates the WebAssembly module