-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[js/webgpu] Choose best wasm backend #18190
Conversation
WebGPU Android in Chrome is still behind flag "--enable-unsafe-apis". Even without this flag, navigator.gpu is available, but navigator.gpu.requestAdapter() would fail. This CL better checks the availability of WebGPU, especially for Android.
/azp run ONNX Runtime Web CI Pipeline |
Azure Pipelines successfully started running 1 pipeline(s). |
@qjia7 @guschmue @satyajandhyala @fs-eire Please review this change, thanks! |
Sorry, I just found even if we select the correct backend, WebGPU will get initialized later on unconditionally. I need more time to investigate this and please do not review now. |
Please check whether it's related with https://github.com/microsoft/onnxruntime/blob/main/js/web/lib/wasm/wasm-core-impl.ts#L55-L61C4. Maybe we should check whether the current backend is |
### Description This PR revises the backend registration. The following describes the expected behavior after this change: (**bolded are changed behavior**) - (ort.min.js - built without webgpu support) - loading: do not register 'webgpu' backend - creating session without EP list: use default EP list ['webnn', 'cpu', 'wasm'] - creating session with ['webgpu'] as EP list: should fail with backend not available - (ort.webgpu.min.js - built with webgpu support) - loading: **always register 'webgpu' backend** ( previous behavior: only register 'webgpu' backend when `navigator.gpu` is available) - creating session without EP list: use default EP list ['webgpu', 'webnn', 'cpu', 'wasm'] - when WebGPU is available (win): use WebGPU backend - when WebGPU is unavailable (android): **should fail backend init,** and try to use next backend in the list, 'webnn' (previous behavior: does not fail backend init, but fail in JSEP init, which was too late to switch to next backend) - creating session with ['webgpu'] as EP list - when WebGPU is available (win): use WebGPU backend - when WebGPU is unavailable (android): **should fail backend init, and because no more EP listed, fail. related PRs: #18190 #18144
close this as an alternative change (#18715) is merged |
### Description This PR revises the backend registration. The following describes the expected behavior after this change: (**bolded are changed behavior**) - (ort.min.js - built without webgpu support) - loading: do not register 'webgpu' backend - creating session without EP list: use default EP list ['webnn', 'cpu', 'wasm'] - creating session with ['webgpu'] as EP list: should fail with backend not available - (ort.webgpu.min.js - built with webgpu support) - loading: **always register 'webgpu' backend** ( previous behavior: only register 'webgpu' backend when `navigator.gpu` is available) - creating session without EP list: use default EP list ['webgpu', 'webnn', 'cpu', 'wasm'] - when WebGPU is available (win): use WebGPU backend - when WebGPU is unavailable (android): **should fail backend init,** and try to use next backend in the list, 'webnn' (previous behavior: does not fail backend init, but fail in JSEP init, which was too late to switch to next backend) - creating session with ['webgpu'] as EP list - when WebGPU is available (win): use WebGPU backend - when WebGPU is unavailable (android): **should fail backend init, and because no more EP listed, fail. related PRs: microsoft#18190 microsoft#18144
WebGPU Android in Chrome is still behind flag "--enable-unsafe-apis". Even without this flag, navigator.gpu is available, but navigator.gpu.requestAdapter() would fail. This PR checks the availability of WebGPU and choose the best wasm backend.