Skip to content

[Patch] allows new memory info name for WebGPU#27475

Merged
tianleiwu merged 1 commit intotlwu/rel-1.24.3from
fs-eire/webgpu-memory-info-name
Feb 27, 2026
Merged

[Patch] allows new memory info name for WebGPU#27475
tianleiwu merged 1 commit intotlwu/rel-1.24.3from
fs-eire/webgpu-memory-info-name

Conversation

@fs-eire
Copy link
Copy Markdown
Contributor

@fs-eire fs-eire commented Feb 27, 2026

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

@fs-eire fs-eire requested a review from Copilot February 27, 2026 04:28
@tianleiwu tianleiwu merged commit f408549 into tlwu/rel-1.24.3 Feb 27, 2026
12 checks passed
@tianleiwu tianleiwu deleted the fs-eire/webgpu-memory-info-name branch February 27, 2026 04:30
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" in CreateMemoryInfo.
  • Accept "WebNN_Ten" as an alias for "WebNN_Tensor" in CreateMemoryInfo.
  • 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 name1 verbatim into OrtMemoryInfo. In 1.24.x many call sites compare OrtMemoryInfo::name to the canonical constants (e.g., onnxruntime::WEBGPU_BUFFER/WEBNN_TENSOR), and OrtMemoryInfo equality/hashing includes name, so passing the short alias can lead to allocator lookup / device checks failing later. Consider normalizing these aliases to the existing canonical names when constructing OrtMemoryInfo, 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.

Comment on lines +240 to +252
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) {
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +241 to +252
// 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) {
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
fs-eire added a commit that referenced this pull request Mar 12, 2026
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>
fs-eire added a commit that referenced this pull request Mar 13, 2026
…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>
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.

3 participants