[Patch] allows new memory info name for WebGPU#27475
[Patch] allows new memory info name for WebGPU#27475tianleiwu merged 1 commit intotlwu/rel-1.24.3from
Conversation
There was a problem hiding this comment.
Pull request overview
Extends the C API OrtApis::CreateMemoryInfo handling in ORT 1.24.x to accept the newer shortened WebGPU (and WebNN) memory info names used by newer (1.25.x) plugin EP builds, improving cross-version plugin compatibility.
Changes:
- Accept
"WebGPU_Buf"as an alias for"WebGPU_Buffer"inCreateMemoryInfo. - Accept
"WebNN_Ten"as an alias for"WebNN_Tensor"inCreateMemoryInfo. - Add inline comments explaining the origin of the shortened names (SSO on wasm32) and the compatibility intent.
Comments suppressed due to low confidence (1)
onnxruntime/core/framework/allocator.cc:256
- CreateMemoryInfo now accepts the short aliases ("WebGPU_Buf"/"WebNN_Ten"), but it also stores
name1verbatim into OrtMemoryInfo. In 1.24.x many call sites compareOrtMemoryInfo::nameto the canonical constants (e.g.,onnxruntime::WEBGPU_BUFFER/WEBNN_TENSOR), andOrtMemoryInfoequality/hashing includesname, so passing the short alias can lead to allocator lookup / device checks failing later. Consider normalizing these aliases to the existing canonical names when constructingOrtMemoryInfo, or otherwise ensure all downstream comparisons treat both names as equivalent.
} else if (strcmp(name1, onnxruntime::WEBGPU_BUFFER) == 0 ||
strcmp(name1, onnxruntime::WEBNN_TENSOR) == 0 ||
// PR #27207 (merged to main/1.25.x, not in 1.24.x) shortened the WebGPU/WebNN
// memory info names from "WebGPU_Buffer"/"WebNN_Tensor" to "WebGPU_Buf"/"WebNN_Ten"
// to enable Small String Optimization (SSO) on wasm32 (emscripten), where strings
// must be <= 10 chars for SSO.
//
// A WebGPU/WebNN plugin EP built against 1.25.x will use the new short names.
// Accept both old and new names here so that plugin EPs targeting either 1.24.x
// or 1.25.x can work with this 1.24.x runtime.
//
// See: https://github.com/microsoft/onnxruntime/pull/27207
strcmp(name1, "WebGPU_Buf") == 0 ||
strcmp(name1, "WebNN_Ten") == 0) {
*out = new OrtMemoryInfo(
name1, type,
OrtDevice(OrtDevice::GPU, OrtDevice::MemType::DEFAULT, OrtDevice::VendorIds::NONE, device_id),
mem_type1);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| strcmp(name1, onnxruntime::WEBNN_TENSOR) == 0 || | ||
| // PR #27207 (merged to main/1.25.x, not in 1.24.x) shortened the WebGPU/WebNN | ||
| // memory info names from "WebGPU_Buffer"/"WebNN_Tensor" to "WebGPU_Buf"/"WebNN_Ten" | ||
| // to enable Small String Optimization (SSO) on wasm32 (emscripten), where strings | ||
| // must be <= 10 chars for SSO. | ||
| // | ||
| // A WebGPU/WebNN plugin EP built against 1.25.x will use the new short names. | ||
| // Accept both old and new names here so that plugin EPs targeting either 1.24.x | ||
| // or 1.25.x can work with this 1.24.x runtime. | ||
| // | ||
| // See: https://github.com/microsoft/onnxruntime/pull/27207 | ||
| strcmp(name1, "WebGPU_Buf") == 0 || | ||
| strcmp(name1, "WebNN_Ten") == 0) { |
There was a problem hiding this comment.
This change also adds support for the WebNN short name ("WebNN_Ten"), but the PR title/description only mention WebGPU. Please update the PR description (or remove the WebNN part) so the change scope matches what’s being shipped.
| // PR #27207 (merged to main/1.25.x, not in 1.24.x) shortened the WebGPU/WebNN | ||
| // memory info names from "WebGPU_Buffer"/"WebNN_Tensor" to "WebGPU_Buf"/"WebNN_Ten" | ||
| // to enable Small String Optimization (SSO) on wasm32 (emscripten), where strings | ||
| // must be <= 10 chars for SSO. | ||
| // | ||
| // A WebGPU/WebNN plugin EP built against 1.25.x will use the new short names. | ||
| // Accept both old and new names here so that plugin EPs targeting either 1.24.x | ||
| // or 1.25.x can work with this 1.24.x runtime. | ||
| // | ||
| // See: https://github.com/microsoft/onnxruntime/pull/27207 | ||
| strcmp(name1, "WebGPU_Buf") == 0 || | ||
| strcmp(name1, "WebNN_Ten") == 0) { |
There was a problem hiding this comment.
There’s no regression test ensuring CreateMemoryInfo accepts the new short aliases and produces a usable memory info for subsequent allocator/device matching. Adding a small shared_lib test that calls the public C/C++ API with "WebGPU_Buf" (and optionally "WebNN_Ten") would help prevent future breakage of this compatibility behavior.
Accept pre-1.25 names "WebGPU_Buffer"/"WebNN_Tensor" as aliases in CreateMemoryInfo and normalize them to the current short names "WebGPU_Buf"/"WebNN_Ten". This allows released onnxruntime-genai (which still uses the old long names) to work with main branch ORT. The normalization is critical because downstream code (external data loader, WebGPU context) compares memory info names against the current constants. Without normalization, those comparisons would fail. See: #27207 See: #27475 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ty (#27637) ### Description Accept pre-1.25 names `"WebGPU_Buffer"`/`"WebNN_Tensor"` as aliases in `CreateMemoryInfo` and normalize them to the current short names `"WebGPU_Buf"`/`"WebNN_Ten"`. This is the **reverse** of #27475 (which added forward compatibility in the 1.24.x patch branch). ### Motivation and Context Released onnxruntime-genai still uses the old (pre-1.25) long names when calling `CreateMemoryInfo`. Without this change, those calls fail with `ORT_INVALID_ARGUMENT` on main branch. ### Key Design Decision When an old name is detected, it is **normalized** to the current short constant (e.g., `"WebGPU_Buffer"` -> `"WebGPU_Buf"`). This is critical because downstream code (e.g., `external_data_loader.cc`, `webgpu_context.cc`) compares `OrtMemoryInfo.name` against the current constants. Simply passing through the old name would cause those comparisons to fail. ### Changes - `onnxruntime/core/framework/allocator.cc`: Accept and normalize legacy names in `CreateMemoryInfo` - `onnxruntime/test/shared_lib/test_allocator.cc`: Add test verifying legacy names are accepted and normalized ### See Also - #27207 (original rename) - #27475 (forward compat in 1.24.x) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
allows new memory info name for WebGPU.
Motivation and Context
This allows at least 1.24.3 works with future (1.25.x) WebGPU plugin DLL