Skip to content

[WebGPU] Fix plugin tensor conversion for CPU memory descriptors - #33634

Open
Yang Gu (gyagp) wants to merge 1 commit into
microsoft:mainfrom
gyagp:fix/webgpu-tensor-memory-type
Open

Yang Gu (gyagp) wants to merge 1 commit into
microsoft:mainfrom
gyagp:fix/webgpu-tensor-memory-type

Conversation

@gyagp

Copy link
Copy Markdown
Contributor

Description

CPU tensors created with C#'s default OrtMemType.Cpu descriptor can terminate the process when a WebGPU plugin kernel converts them through the EP API adapter. The adapter passes the OrtMemType value (-1) into OrtDevice::MemoryType, whose valid values are 0 and 5. Validation then throws through a noexcept delegating constructor.

Use GetDeviceMemoryType() when reconstructing OrtDevice, while preserving the separate OrtMemType field. Valid CPU and host-accessible descriptors then pass the existing constructor validation.

Add regression coverage for WebGPU inference with default, CPU-input, CPU-output, and host-accessible memory descriptors. The inference graph consumes one input on both CPU and GPU, and profiling must confirm execution of MemcpyFromHost. The C# package smoke test now selects the registered plugin by library path, preventing built-in WebGPU from satisfying the test accidentally.

Motivation and Context

Addresses microsoft/onnxruntime#33557 by fixing the erroneous memory-type conversion before constructor validation.

Validation

  • Focused conversion checks pass for five combinations of the two memory-type fields using the initializer extracted from the modified source, with the original constructor exception specification retained.
  • C++ formatting and git diff --check pass.
  • macOS arm64 RelWithDebInfo rebuild of the plugin and onnxruntime_provider_test passed with the original OrtDevice header retained.
  • WebGpuPluginSharedAllocatorTest.InferenceWithCpuTensorMemoryTypes passed on macOS arm64 with the original noexcept declaration retained. It covers four memory descriptors and verifies four actual WebGPU MemcpyFromHost executions through profiling.
  • C# NuGet smoke test: not run; .NET SDK is not installed.

Use the device memory type when reconstructing OrtDevice from an API
tensor, preserving the separate OrtMemType field so valid CPU descriptors
pass the existing constructor validation.

Add a plugin inference regression, including profiling that confirms
MemcpyFromHost executes for CPU input descriptors. Select
the registered plugin by library path in the C# package smoke test.

Fixes microsoft#33557.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@gyagp

Copy link
Copy Markdown
Contributor Author

/run bots

@qjia7

Copy link
Copy Markdown
Contributor

The request was received. Approve workflow runs. Thanks.

This branch has not been deployed

No deployments
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.

2 participants