Halide
Halide copied to clipboard
[WebGPU] Unify Emscripten and dawn-native paths in the runtime
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:
- Emscripten missing
wgpuCreateInstance
andwgpuReleaseInstance
- Emscripten missing
wgpuAdapterGetLimits
- Waiting for async device init callbacks:
emscripten_sleep()
vsusleep()
(e.g.wgpuInstanceProcessEvents()
) - Waiting on other async callbacks:
emscripten_sleep()
vswgpuDeviceTick()
(e.g.wgpuInstanceProcessEvents()
)
Is there any plan as to when/if this will get resolved?
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
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.
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?
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
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.)
As of now, wgpuInstanceProcessEvents() and wgpuAdapterGetLimits() are both present in webgpu.h -- are they still nonfunctional?
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()
.
...sigh. Is there any path or plan for them to implement them?
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?
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 #ifdef
s. 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!