iree icon indicating copy to clipboard operation
iree copied to clipboard

[Epic] Add support for WebGPU

Open ScottTodd opened this issue 2 years ago • 0 comments

Tracking issue for overall WebGPU support in IREE.

Background

WebGPU logo

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 main branch
  • The application at experimental/web/sample_webgpu can 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)
  • A few compiler options are still needed to work around codegen feature gaps

Previous status reports:

2023-05-26

  • The webgpu branch hosting the runtime HAL and a sample webpage (.c, .js, Emscripten) is close to main
    • https://github.com/openxla/iree/pull/13815 gets it ready for merging into experimental/
  • The application at experimental/web/sample_webgpu can run simple_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/ using iree_loop_emscripten
  • A few compiler options are required as workarounds, depending on the input program. Currently these are --iree-codegen-gpu-native-math-precision=true and alias-mutable-bindings (no tool flag, edit in source)

2022-12-14

IREE WebGPU Status 2022-12-14

2022-10-04

IREE WebGPU Status 2022-10-04

ScottTodd avatar May 19 '23 20:05 ScottTodd