Skip to content

[WebGPU EP] Support uint8 for Reshape - #29897

Merged
hariharans29 merged 3 commits into
microsoft:mainfrom
miaobin:webgpu-reshape-uint8
Jul 28, 2026
Merged

[WebGPU EP] Support uint8 for Reshape#29897
hariharans29 merged 3 commits into
microsoft:mainfrom
miaobin:webgpu-reshape-uint8

Conversation

@miaobin

@miaobin miaobin commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Description

Adds uint8 data type support to the Reshape operator in the WebGPU execution provider. The op is used by detr-resnet-50 and other models that reshape uint8 tensors.

Motivation and Context

Adds uint8 to the WebGPU Reshape type constraint so uint8 Reshape nodes stop falling back to the CPU EP. Reshape is a pure copy/view op (it aliases the input buffer, or does a raw byte copy when not in-place) and never interprets element values in a shader, so uint8 is enabled unconditionally in both the versioned and latest-opset kernel factories -- no shader changes are needed.

This PR also adds a WebGPU uint8 Reshape test. It runs on a WebGPU-only session with CPU-EP fallback disabled (kOrtSessionOptionsDisableCPUEPFallback), so the node must be placed on the WebGPU kernel.

Adds uint8 to the WebGPU `Reshape` type constraint so uint8 Reshape nodes stop
falling back to the CPU EP. Reshape is a pure copy/view op (it aliases the input
buffer, or does a raw byte copy when not in-place) and never interprets element
values in a shader, so uint8 is enabled unconditionally in both the versioned
and latest-opset kernel factories -- no shader changes are needed.

Also adds a WebGPU uint8 Reshape test. It runs on a WebGPU-only session with
CPU-EP fallback disabled (kOrtSessionOptionsDisableCPUEPFallback), so the node
must be placed on the WebGPU kernel.
@azure-pipelines

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

@miaobin

miaobin commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@hariharans29, PTAL, thanks!
cc/ @huningxin @ibelem @adrastogi

@miaobin miaobin changed the title WebGPU: Support uint8 for Reshape [WebGPU EP] Support uint8 for Reshape Jul 27, 2026
@adrastogi
adrastogi requested a review from Copilot July 27, 2026 14:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the WebGPU Execution Provider’s Reshape kernel registration to accept uint8 tensors so Reshape nodes on uint8 data don’t fall back to CPU, and adds a regression test to ensure the WebGPU kernel is actually selected when CPU fallback is disabled.

Changes:

  • Add uint8 to the WebGPU Reshape type constraints (both versioned and latest kernel factories).
  • Add a WebGPU uint8 Reshape test that disables CPU-EP fallback to ensure proper EP placement.
Show a summary per file
File Description
onnxruntime/test/providers/cpu/tensor/tensor_op_test.cc Adds a uint8 Reshape test intended to force WebGPU execution by disabling CPU fallback.
onnxruntime/core/providers/webgpu/tensor/reshape.cc Adds uint8 to the registered WebGPU Reshape type constraints.

Review details

  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Low

Comment thread onnxruntime/test/providers/cpu/tensor/tensor_op_test.cc
@hariharans29

Copy link
Copy Markdown
Member

Please take a look at copilot's comment

@miaobin

miaobin commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Please take a look at copilot's comment

Resolved the comment and please take another look, thanks a lot!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

onnxruntime/core/providers/webgpu/tensor/reshape.cc:45

  • Same issue here: type_constraints can be moved into TypeConstraint to avoid copying the vector again during kernel registration.
  std::vector<MLDataType> type_constraints = GetOpTypeConstraints(enable_int64, true);
  type_constraints.push_back(DataTypeImpl::GetTensorType<uint8_t>());

  KernelCreatePtrFn kernel_create_fn = [](FuncManager&, const OpKernelInfo& info, std::unique_ptr<OpKernel>& out) -> Status {
    out = std::make_unique<Reshape>(info);

Comment thread onnxruntime/core/providers/webgpu/tensor/reshape.cc
std::move the type-constraints vector into KernelDefBuilder::TypeConstraint.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@hariharans29
hariharans29 merged commit 65abd89 into microsoft:main Jul 28, 2026
86 checks passed
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