iree
iree copied to clipboard
[Epic] Add support for WebGPU
Tracking issue for overall WebGPU support in IREE.
Background
WebGPU is a recently released API for running graphics and compute workloads on Graphics Processing Units in web browsers. It is similar to modern graphics/compute APIs like Vulkan, D3D12, and Metal, making it a promising target for IREE.
At a high level, we need:
- IREE's compiler to generate WGSL code
- IREE's runtime to have a WebGPU HAL implementation and general web platform support
The details can get tricky though:
- WGSL is more restrictive than SPIR-V
- WebGPU's compute API is more restrictive than Vulkan
- Runtime support requires compiling from C to JavaScript/WebAssembly (e.g. via Emscripten and some libraries)
Task breakdown
Compiler tasks
- [x] https://github.com/openxla/iree/issues/7840
- [ ] https://github.com/openxla/iree/issues/10906
- [x] https://github.com/openxla/iree/issues/10908
- [x] https://github.com/openxla/iree/issues/10142
- [x] https://github.com/openxla/iree/issues/10145
- [x] https://github.com/openxla/iree/pull/10224
- [ ] https://github.com/openxla/iree/issues/11054
- [x] https://github.com/openxla/iree/issues/11229
- [ ] https://github.com/openxla/iree/issues/11321
- [ ] https://github.com/openxla/iree/issues/12509
- [x] https://github.com/openxla/iree/pull/13965
Runtime tasks
- [x] https://github.com/openxla/iree/pull/13952
- [x] https://github.com/openxla/iree/pull/13669
- [ ] https://github.com/openxla/iree/issues/13809
- [x] https://github.com/openxla/iree/pull/13962
- [ ] Web Workers for threading (optional)
- [ ] Implement semaphores and use for asynchronous queue execution callbacks
Infrastructure / developer experience tasks
- [x] WebGPU/WGSL compiler builds and tests running on presubmit
- [x] General Wasm/Emscripten runtime build running on postsubmit
- [ ] WebGPU runtime build running on postsubmit
- [ ] All web builds running on presubmit (move out of
experimental/) - [ ] Write async unit tests, runnable in some way
- [ ] Integrate tests into CI
- [ ] Document how to use Wasm/WebGPU builds
Other related issues
- [ ] https://github.com/openxla/iree/issues/6499
- [ ] https://github.com/openxla/iree/issues/8327
# Status
last updated 2023-08-03
- All code is merged onto the
mainbranch - The application at
experimental/web/sample_webgpucan programs in web browsers without crashing but with incorrect results- multiple_results.mlir:
absf(-1.23, -4.56)returns(4.56, 0)at first, then(1.23, 4.56)on future calls with the same loaded program state - mobilebert, posenet, mobilessd: no errors, correct number of outputs, incorrect numerical results (way off llvm-cpu/local-task, stable across runs)
- multiple_results.mlir:
- A few compiler options are still needed to work around codegen feature gaps
Previous status reports:
2023-05-26
- The
webgpubranch hosting the runtime HAL and a sample webpage (.c, .js, Emscripten) is close tomain- https://github.com/openxla/iree/pull/13815 gets it ready for merging into
experimental/
- https://github.com/openxla/iree/pull/13815 gets it ready for merging into
- The application at
experimental/web/sample_webgpucan runsimple_abs,fullyconnected, and MobileSSD using WebGPU in web browsers- tested Chrome 113 on Windows and Chrome Dev on Linux with Vulkan launch flags
- Posenet, MobileBERT, and other programs with more than one output hit https://github.com/openxla/iree/issues/13809
- https://github.com/openxla/iree/pull/13820 will async-ify
experimental/web/sample_webgpu/usingiree_loop_emscripten - A few compiler options are required as workarounds, depending on the input program. Currently these are
--iree-codegen-gpu-native-math-precision=trueandalias-mutable-bindings(no tool flag, edit in source)