Skip to content

[ExecuTorch][WebGPU] et_vk conv2d: route standard (groups==1) conv through an im2col tiled GEMM (1.1-2.4x)#20873

Open
JCNTH wants to merge 3 commits into
gh/JCNTH/48/basefrom
gh/JCNTH/48/head
Open

[ExecuTorch][WebGPU] et_vk conv2d: route standard (groups==1) conv through an im2col tiled GEMM (1.1-2.4x)#20873
JCNTH wants to merge 3 commits into
gh/JCNTH/48/basefrom
gh/JCNTH/48/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Problem: the direct conv2d kernel runs one thread per output element and re-reads the input receptive field from global memory for every output — zero cross-thread reuse. For the patch-embed stem (3-channel RGB) the vec4-over-IC path is inert (icpg=3 fails the %4 gate), so it runs the scalar direct path with no reuse at all.

Solution: route groups==1 non-transposed convs through an implicit-im2col tiled GEMM that reuses the linear tiled-GEMM skeleton — M=OC, N=BOHOW, K=ICKHKW; shared-memory 32x32 tiles + 4x4 register blocking; the input is im2col-sampled on the fly (out-of-range -> 0.0 implements padding). Grouped/depthwise/transpose stay on the direct/gather kernels.

Before: every conv -> direct kernel (scalar, or vec4-over-IC when icpg%4==0), no input reuse.
After: groups==1 -> conv2d_gemm (shared-mem tiling + register blocking, input-tile reuse across output positions); grouped/transpose -> unchanged.

Implementation:

  • New conv2d_gemm.wgsl (+ generated header): forks linear_fp32_tiled.wgslread_a loads the weight [OC, K], read_b im2col-samples the input (decodes n->(b,oh,ow), kk->(ic,kh,kw); ih=ohsH-pH+khdH; bounds-check->0), bias per-row (OC), output written NCHW. Reuses the existing ConvParams uniform.
  • Conv2d.cpp branches on groups==1: GEMM via compute_tile_grid_2d + add_dispatch_2d (mirrors LinearFp32.cpp); else the existing direct dispatch. The grouped path is byte-identical; both grids are computed before any buffer alloc (throw-before-leak). Mirrors Vulkan's own should_use_conv2d_im2col groups==1 routing.

Constraints: scalar GEMM (no vec4) — NCHW's channel stride isn't contiguous, so vec4-over-K would be a strided gather (no compute win on Apple's scalar ALU); ORT skips vec4 for NCHW too.

Co-authored-with: Claude Code.
@exported-using-ghexport

Differential Revision: D110995347

Differential Revision: D110995347

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20873

Note: Links to docs will display an error until the docs builds have been completed.

❌ 130 New Failures, 2 Unrelated Failures, 7 Unclassified Failures

As of commit 8ddeb0c with merge base c2b273e (image):

NEW FAILURES - The following jobs have failed:

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

  • pull / unittest / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?
  • pull / unittest-editable / windows / windows-job (gh) (matched win rule in flaky-rules.json)
    Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under 'C:\actions-runner\_work\executorch\executorch\test-infra\.github\actions\teardown-windows'. Did you forget to run actions/checkout before running your local action?

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

[ghstack-poisoned]
[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants