Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebGPU execution provider #349

Closed
raphaelmenges opened this issue Feb 17, 2025 · 11 comments
Closed

Add WebGPU execution provider #349

raphaelmenges opened this issue Feb 17, 2025 · 11 comments

Comments

@raphaelmenges
Copy link

raphaelmenges commented Feb 17, 2025

Hello 👋,

The WebGPU execution provider (WebGPU ep) has been released exclusively for the JavaScript world a year ago. However, since then the WebGPU ep has become available to native platforms via Dawn and soon will be available to Emscripten as well.

To build the WebGPU ep for native platforms with Dawn, one needs to add the --use_webgpu flag in the build.py. The options for the WebGPU ep are defined here: https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/core/providers/webgpu/webgpu_provider_options.h

Since the onnxruntime maintainers are putting a lot of effort into the WebGPU execution provider and now it becoming available across all platforms, this might become default/fallback choice of hardware-accelerated inferencing with ort :)

@raphaelmenges
Copy link
Author

Image

@decahedron1: Do you also plan to make the WebGPU execution provider available in your static library binaries of onnxruntime?

@decahedron1
Copy link
Member

Yes, once ONNX Runtime 1.21 rolls around. (I already tried including it in the 1.20.2 binaries but had trouble building Dawn; seems to be fixed on trunk)

@raphaelmenges
Copy link
Author

Great, just great! Thank you @decahedron1.

@amitsheokand
Copy link

Thank you @decahedron1

@raphaelmenges
Copy link
Author

raphaelmenges commented Feb 18, 2025

I guess we should add the WebGPU ep in the docs as well?

Specifically here: https://github.com/pykeio/ort/blob/main/docs/pages/setup/cargo-features.mdx#execution-providers

@decahedron1
Copy link
Member

Nice catch =)

@raphaelmenges
Copy link
Author

WebGPU binaries are currently only available for wasm32-unknown-emscripten

Any reason to not include the WebGPU ep for the Windows, macOS, and Linux builds as well?

@decahedron1
Copy link
Member

Haven't gotten the chance to try compiling for those platforms. I also may not provide binaries for non-Emscripten depending on binary size (>150 MB)

@raphaelmenges
Copy link
Author

Let's see how fast the WebGPU ep will be. I really hope for it to become the default go-to for hardware acceleration across platforms! But no idea, yet.

@raphaelmenges
Copy link
Author

raphaelmenges commented Feb 20, 2025

FYI, I got the WebGPU ep compiled from microsoft/onnxruntime@ec3f871 for all (of my) targets but Windows: https://github.com/alfatraining/ort-artifacts-staging/actions/runs/13437315034

The error on Windows is ambiguous:

   onnxruntime_providers.vcxproj -> D:\a\ort-artifacts-staging\ort-artifacts-staging\onnxruntime\build\onnxruntime\Release\onnxruntime_providers.lib
error: Uncaught (in promise) Error: Exited with code: 1
            throw new Error(`Exited with code: ${code}`);
                  ^
    at CommandChild.pipedStdoutBuffer (https://jsr.io/@david/dax/0.41.0/src/command.ts:785:19)
    at eventLoopTick (ext:core/01_core.js:177:7)
Error: Process completed with exit code 1.

I know one should wait for onnxruntime v1.21.0+ to rely on WebGPU but I am just too curious 🙈

Update: I got the WebGPU ep running on macOS (arm64) with the above mentioned build of onnxruntime. I needed to link my executable additionally to the frameworks IOSurface, Metal, and QuartzCore. is_available() of the WebGPU ep returns always false, similar to the XNNPACK ep lately.

Update 2: I could trace down some specific error in the Windows build: https://github.com/alfatraining/ort-artifacts-staging/actions/runs/13437315034/job/37542669073#step:8:19525. Looks like something about DX12 is missing? Maybe just a GitHub runner issue? We might need to setup DirectX properly in the workflow? Use a newer Windows? I will investigate!

Update 3: When using the windows-2025 preview image, it compiles: https://github.com/alfatraining/ort-artifacts-staging/actions/runs/13440293785/job/37552758608 :)

@raphaelmenges
Copy link
Author

I also got the WebGPU ep run on Windows. However, one requires dxcompiler.dll and dxil.dll to be placed next to the executable for running it. Either we need to copy these .dll's into the archive with the precompiled onnxruntime during the artifact creation or the user must download them from here: https://github.com/microsoft/DirectXShaderCompiler/releases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants