[WebGPU EP] Support uint8 for Reshape - #29897
Merged
Merged
Conversation
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: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Author
|
@hariharans29, PTAL, thanks! |
Contributor
There was a problem hiding this comment.
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
uint8to the WebGPUReshapetype constraints (both versioned and latest kernel factories). - Add a WebGPU
uint8Reshapetest 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
Member
|
Please take a look at copilot's comment |
Contributor
Author
Resolved the comment and please take another look, thanks a lot! |
Contributor
There was a problem hiding this comment.
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_constraintscan be moved intoTypeConstraintto 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);
std::move the type-constraints vector into KernelDefBuilder::TypeConstraint.
hariharans29
approved these changes
Jul 28, 2026
40 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Reshapetype 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.