[DISCUSS] WebGPU native support?

Hello! TVM looks like a nice project and is very exciting. I am keen to start a discussion around WebGPU native support: is there interest in it? how hard would it be to add? is anyone else keen to work on/collaborate on this?

For context; WebGPU native provides the same benefits as WebGPU in the browser, but natively on Windows/Linux/Mac/Android/iOS/etc. and is quickly rising as an appreciated graphics abstraction API for native applications.

I am specifically interested in this as we’re building a game engine and desktop/mobile app framework in Zig which uses WebGPU native as our graphics backend, it’d be nice to be able to use TVM with games and apps built with it.

My understanding is that TVM today has a web/ backend which can produce WGSL code on its own; I also found the web/emcc directory which appears to be a TVM backend directing calls through emscripten to JS. tvm/web/src/runtime.ts seems to be the bulk of the implementation otherwise which I assume would need to be ported to C/C++.

To complicate matters a bit, although WebGPU native implementations generally share the same native APIs, they do differ somewhat. The Rust/Mozilla wgpu-native webgpu.h API is not exactly the same as the Dawn/Chrome webgpu.h API-the biggest differences are around initialization of how WebGPU gets set up, so I think if it was usable in library form (desirable anyway) then it would mostly be fine as the compute APIs should be the same otherwise. The most ideal setup would be if the user could supply their own webgpu.h header as part of compilation to ensure the implementation is compatible with what TVM targets.

I’m also curious if this has to be implemented in the TVM source tree, or if it is reasonable to implement as a separate project which depends on TVM?

Thanks for your time/thoughts

Thank you for reaching out, yes this is something that is definitely interesting. Love to see TVM with games and webgpu native is definitely something fun to add support for.

I think we mostly need something along the line of the current vulkan runtime that depends on webgpu.h, being able to link to the webgpu runtime that zig builds sounds like a good bonus.

Love to help and collaborate on this. As a matter of fact, I started to do a bit of poc several weeks ago that sets up the basic scaffolds(based on on dawn) Commits · tqchen/tvm · GitHub but did not get too far due to other working items. Happy to discuss implementation strategy on this item and spend sometime on it, or work together to add the general support

Here is a possible action plan:

  • Add runtime/webgpu_native folder
    • Add possible counter parts from reference like the current metal runtime but dispatches into the webgpu API
    • I am just picking metal that could be closer to webgpu api, the vulkan one can also be used as a ref.
  • Add a build option that optionally links in a webgpu native impl (can be from dawn or the one provided by Zig)

Then this will give libtvm_runtime the ability to load webgpu native modules. My guess is that it would take not that too much of an effort(mainly to translate the webgpu’s async api into sync version).

Once libtvm_runtime comes with webgpu native support, then it can be linked with other apps, and running the applications as normal.