Fix WebGPU instance creation for caller-supplied GPUDevice - #1
Open
4n4ny4 wants to merge 1 commit into
Open
Conversation
Sessions that import an external GPUDevice hung inside WebGpuContext::Wait(). post-webgpu.js created the WGPUInstance with a null descriptor, so the instance lacked the TimedWaitAny feature, while WebGpuContext::Wait() calls instance_.WaitAny(f, UINT64_MAX). emdawnwebgpu returned wait status 3 and the run never completed. This only reproduces when the caller supplies their own GPUDevice, which is why the default path was unaffected. Factor the native instance descriptor into WebGpuContext::CreateWebGpuInstance(), export it to WASM as OrtCreateWebGpuInstance, and use it from post-webgpu.js so the JS-created instance matches what the native waiter requires. Creation failure is now rejected explicitly, and custom-device registration is reset in a finally block so a failed session creation no longer poisons subsequent attempts. Adds a browser unit test covering the custom and default device paths, repeated session lifecycle, and cleanup after a creation failure. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Sessions that import a caller-supplied
GPUDevicehang insideWebGpuContext::Wait().onnxruntime/wasm/post-webgpu.jscreated theWGPUInstancewith a null descriptor, so the instance lacked theTimedWaitAnyfeature.WebGpuContext::Wait()callsinstance_.WaitAny(f, UINT64_MAX), and emdawnwebgpu returns wait status 3 because timed waits were never enabled. The run never completes.This only reproduces when the caller supplies their own
GPUDevice, which is why the default path is unaffected and the issue went unnoticed.Change
WebGpuContext::CreateWebGpuInstance()so there is a single definition of what the native waiter requires.OrtCreateWebGpuInstanceand use it frompost-webgpu.js, so the JS-created instance matches.finallyblock, so a failed session creation no longer poisons subsequent attempts.Validation
New browser unit test
js/web/test/unittests/backends/wasm/test-webgpu-device.tscovers the custom-device path, the default path, repeated session lifecycle, and cleanup after a forced creation failure. Full browser unit suite passes.Notes
Pure correctness fix — no performance claims. This is a prerequisite for any benchmark that shares a single
GPUDevicebetween runtimes.