[webgpu] support arbitrary input_channel size for im2col - #27038
Conversation
|
@daijh, PTAL, thanks! |
|
Many comments in shader does not reflect the |
|
LGTM, please invite more reviewers to check. |
|
Hi @qjia7 , This PR is ready for review, PTLA, thanks! |
There was a problem hiding this comment.
Pull request overview
Extends the WebGPU Conv im2col+matmul path to support non-multiple-of-4 input channel counts by selecting an appropriate vectorization width (vec4/vec2/vec1), enabling broader use of the optimized kernel.
Changes:
- Add
vec_sizetemplate parameter and logic to support vec1/vec2 loads inim2col_matmul.wgsl.template. - Select
vec_sizeat runtime based onchannel_inputand plumb it through shader generation/caching inim2col_matmul.{h,cc}. - Add two new Conv2D unit tests covering cases with asymmetric padding and
C=4/C=6.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/test/providers/cpu/nn/conv_op_test.cc | Adds Conv2D test cases that include a non-multiple-of-4 input channel scenario (C=6). |
| onnxruntime/core/providers/webgpu/nn/im2col_matmul.wgsl.template | Generalizes im2col indexing/tiling and accumulation to support vec_size 1/2/4. |
| onnxruntime/core/providers/webgpu/nn/im2col_matmul.h | Extends program interface to carry vec_size. |
| onnxruntime/core/providers/webgpu/nn/im2col_matmul.cc | Computes vec_size, updates program inputs/cache hint, and removes the prior %4 restriction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
As a last-minute change, the commit message needs to be updated to reflect both vec1 and vec2. |
Head branch was pushed to by a user without write access
|
/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
|
A soft ping... PTAL, thank you! |
Description
This PR supports
vec1/vec2for arbitraryinput_channelinim2colkernel, which could bring performance gain to more models.Like for
yolov8n_posemodel, there is about ~7% gain for whole model, and ~50% for thoseconv2dop whichinput_sizeare not multiple of 4.Motivation and Context