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

[js/webgpu] Choose best wasm backend #18190

Closed
wants to merge 6 commits into from
Closed

[js/webgpu] Choose best wasm backend #18190

wants to merge 6 commits into from

Conversation

gyagp
Copy link

@gyagp gyagp commented Oct 31, 2023

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.

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.
@guschmue
Copy link
Contributor

/azp run ONNX Runtime Web CI Pipeline

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gyagp
Copy link
Author

gyagp commented Nov 1, 2023

@qjia7 @guschmue @satyajandhyala @fs-eire Please review this change, thanks!

@gyagp gyagp marked this pull request as ready for review November 1, 2023 07:55
@gyagp
Copy link
Author

gyagp commented Nov 1, 2023

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.

@gyagp gyagp marked this pull request as draft November 1, 2023 09:46
@qjia7
Copy link
Contributor

qjia7 commented Nov 2, 2023

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 webgpu instead of checking BUILD_DEFS.DISABLE_WEBGPU.

@gyagp gyagp changed the title [js/webgpu] Check the availability of WebGPU during resolveBackend [js/webgpu] Choose best wasm backend Nov 6, 2023
fs-eire added a commit that referenced this pull request Dec 20, 2023
### 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
@fs-eire
Copy link
Contributor

fs-eire commented Jan 23, 2024

close this as an alternative change (#18715) is merged

@fs-eire fs-eire closed this Jan 23, 2024
siweic0 pushed a commit to siweic0/onnxruntime-web that referenced this pull request May 9, 2024
### 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
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

Successfully merging this pull request may close these issues.

4 participants