[Plugin WebGPU EP] Fix API initialization error handling#28211
[Plugin WebGPU EP] Fix API initialization error handling#28211
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens initialization-time error handling for the WebGPU Plugin EP entrypoint (CreateEpFactories) so failures during onnxruntime::ep::ApiInit() return a usable OrtStatus instead of crashing/hiding the underlying error.
Changes:
- Adds a pre-init
try/catcharoundonnxruntime::ep::ApiInit()with a conservativeOrtStatusconstruction path. - Falls back to printing an error and aborting if
OrtStatuscannot be created. - Adds
<cstdio>/<cstdlib>includes to support the fallback path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // We assume that `CreateStatus` has the same offset in the `OrtApi` struct in v1 and the current version. | ||
| // `OrtApiBase::GetApi()` could theoretically return `OrtApi` structs with different layouts for different | ||
| // versions, but `CreateStatus` has maintained the same offset across all versions so far. |
There was a problem hiding this comment.
The ORT API is meant to always remain backwards compatible so I don't think this is an 'assumption' as it should be a guarantee.
There was a problem hiding this comment.
this comment does allow for the possibility of the API struct changing in a non-backwards compatible way. it hasn't, yet.
onnxruntime/onnxruntime/core/session/onnxruntime_c_api.cc
Lines 4221 to 4258 in c7c99ce
There was a problem hiding this comment.
added a static_assert to enforce this
Description
This pull request improves error handling in the
CreateEpFactoriesfunction inonnxruntime/core/providers/webgpu/ep/api.cc.The main enhancement is the addition of a more conservative mechanism for creating
OrtStatusobjects when exceptions occur during API initialization.The existing code was attempting to create a C++ API
Ort::Statusinstance even if the API was not initialized successfully.Motivation and Context
Fix crash that was hiding underlying error message.