Halide icon indicating copy to clipboard operation
Halide copied to clipboard

[WebGPU] Unify Emscripten and dawn-native paths in the runtime

Open jrprice opened this issue 2 years ago • 11 comments

There are a few differences in the native APIs implemented by Emscripten and Dawn that mean Halide's WebGPU backend currently requires a build-time switch to select between the two. Once these differences are resolved, we should be able to remove this conditional logic and the build-time switch.

The differences are:

  1. Emscripten missing wgpuCreateInstance and wgpuReleaseInstance
  2. Emscripten missing wgpuAdapterGetLimits
  3. Waiting for async device init callbacks: emscripten_sleep() vs usleep() (e.g. wgpuInstanceProcessEvents())
  4. Waiting on other async callbacks: emscripten_sleep() vs wgpuDeviceTick() (e.g. wgpuInstanceProcessEvents())

jrprice avatar Dec 20 '22 18:12 jrprice

Is there any plan as to when/if this will get resolved?

steven-johnson avatar Feb 22 '23 20:02 steven-johnson

One comment in https://github.com/halide/Halide/pull/6492 suggests that the lack of support for wgpuInstanceProcessEvents() is also tied to this issue, but I don't see it mentioned above

steven-johnson avatar Feb 22 '23 20:02 steven-johnson

lack of support for wgpuInstanceProcessEvents() is also tied to this issue

Yeah, this is the expected name for the solution for the emscripten_sleep() vs wgpuDeviceTick() discrepancy. I've added it to the original comment to make that clearer.

Is there any plan as to when/if this will get resolved?

We're focusing on getting V1 of WebGPU shipped in Chrome really soon [1], and then we expect to have a renewed focus on making the native vs web story better. So yes, these things will get resolved, but I can't give an exact timeframe right now.

[1]: Intent to ship: WebGPU (Chromium)

jrprice avatar Feb 23 '23 19:02 jrprice

Ah, gotcha, thanks. FYI, googling for wgpuInstanceProcessEvents() shows that it is in Emscripten's current version of webgpu.h: https://github.com/emscripten-core/emscripten/blob/main/system/include/webgpu/webgpu.h -- is it already implemented there?

steven-johnson avatar Feb 23 '23 19:02 steven-johnson

is it already implemented there?

It's in the header (which I think is just a copy of Dawn's header), but the implementation is still absent: https://github.com/emscripten-core/emscripten/blob/7de3bc93f0f7b65549215772255779ad8305ce78/src/library_webgpu.js#L2426

jrprice avatar Feb 23 '23 20:02 jrprice

As of Aug 2023, Emscripten/Dawn now support (and require) wgpuCreateInstance() and wgpuInstanceRelease() in non-native code, so I updated those in #7804. (wgpuInstanceProcessEvents() and wgpuAdapterGetLimits() are still unimplemented.)

steven-johnson avatar Aug 24 '23 19:08 steven-johnson

As of now, wgpuInstanceProcessEvents() and wgpuAdapterGetLimits() are both present in webgpu.h -- are they still nonfunctional?

steven-johnson avatar Nov 27 '23 20:11 steven-johnson

wgpuInstanceProcessEvents() and wgpuAdapterGetLimits() are still both unimplemented by Emscripten.

For future reference the Emscripten implementation is here, and it's usually easy to search for these functions since they are present but both just abort().

jrprice avatar Nov 27 '23 20:11 jrprice

...sigh. Is there any path or plan for them to implement them?

steven-johnson avatar Nov 27 '23 20:11 steven-johnson

Since WebGPU API issues have come up again, I see these are still unimplemented; is there any likely path to them getting there, or should we assume this is just a long-term API divergence?

steven-johnson avatar Feb 08 '24 19:02 steven-johnson

I've asked the folks closer to this, and the response is still that we should eventually get to a world where you can target both native and Emscripten without any #ifdefs. I'm afraid we can't give a specific timeframe for when this will happen though. The latest header update PR did remove one such #ifdef however, so that's something!

jrprice avatar Feb 08 '24 22:02 jrprice