Repository navigation
[WebGPU] Report copy_tensors misuse instead of terminating the process - #32315
Merged
Ananya Anand (4n4ny4) merged 1 commit intoSep 2, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Converts WebGPU copy failures into OrtStatus errors instead of allowing exceptions to terminate the process.
Changes:
- Adds exception handling around the
noexceptC ABI callback. - Extracts the potentially throwing copy implementation into a helper.
π‘ Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ananya Anand (4n4ny4)
force-pushed
the
webgpu-copy-tensors-misuse
branch
from
August 31, 2026 21:00
db87685 to
21a15f7
Compare
BufferManager::MemCpy reports misuse with ORT_ENFORCE, which throws: an aliased src/dst pair, an undersized destination and a still-mapped buffer all throw rather than returning a Status. The shared data transfer reaches it through WebGpuDataTransferImpl::CopyTensorsImpl, a noexcept C ABI callback that only handled a returned non-OK Status, so the exception escaped a noexcept frame and std::terminate ended the process with no message. Split the body into CopyTensorsOrThrow and wrap the callback in API_IMPL_BEGIN/API_IMPL_END, the conversion the rest of the C API already uses, so an ORT_ENFORCE failure is reported as ORT_FAIL rather than ending the process. Cover it with a self-copy of a device tensor in WebGpuPluginSharedAllocatorTest. That reaches the aliased-buffer enforce and asserts both that an error status comes back and that the tensor still round trips afterwards. Without the conversion the test fast-fails the process rather than failing.
Ananya Anand (4n4ny4)
force-pushed
the
webgpu-copy-tensors-misuse
branch
from
August 31, 2026 21:38
21a15f7 to
d552f04
Compare
Sushanth Rajasankar (sushraja-msft)
approved these changes
Aug 31, 2026
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.
Description
BufferManager::MemCpyreports misuse withORT_ENFORCE, which throws: an aliased src/dstpair, an undersized destination and a still-mapped buffer all throw rather than returning a
Status. The shared data transfer reaches it through
WebGpuDataTransferImpl::CopyTensorsImpl,which is a
noexceptC ABI callback and only handled a returned non-OK Status. The exceptionescaped a
noexceptframe, sostd::terminatetook the process down with no message and nostack.
This wraps the callback body so any throw becomes an
OrtStatus, which is what thesurrounding C API already expects.
The two sibling callbacks are deliberately left alone:
CanCopyImplonly calls C ABI functionpointers, and
ReleaseImplreturns void, so converting a throw there would mean swallowing itrather than reporting it, which is a separate decision from this one.
Motivation and Context
Not currently reachable from Python, because
copy_tensorsrejects every WebGPU OrtValueoutright. It becomes reachable as soon as the supported copies are allowed, which is what
#32074 does, so it is worth fixing at the boundary on its own rather than landing inside a
larger change.
The regression test for it uses the session-scoped allocation APIs under discussion in #32074
and is held there rather than duplicated here.