Skip to content

[ExecuTorch][WebGPU] Port index_select#21171

Open
JCNTH wants to merge 2 commits into
gh/JCNTH/131/basefrom
gh/JCNTH/131/head
Open

[ExecuTorch][WebGPU] Port index_select#21171
JCNTH wants to merge 2 commits into
gh/JCNTH/131/basefrom
gh/JCNTH/131/head

Conversation

@JCNTH

@JCNTH JCNTH commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Ports aten.index_select.default as a gather along a dim, mirroring the landed flip/split index-transform (dual-TensorMeta, 2D-fold dispatch) + the landed index/Index.cpp int-index binding. index_select is pure data movement, so it remaps the dim coord through an int index and copies — no fp compute.

Key changes:

  • runtime/ops/index_select/{IndexSelect.cpp, index_select.wgsl} (+ generated index_select_wgsl.h) — per out flat idx: unravel via out_meta.strides, in_coord = out_coord with the dim coord remapped by index[out_coord[dim]], ravel via in_meta.strides, output[out] = input[in]; the index tensor is bound as array<i32> (the int32 downcast_64_bit of the int64 index, same as Index.cpp); Params { info: vec4<u32> } carries dim. Registered aten.index_select.default.
  • CMakeLists.txtruntime/ops/index_select/IndexSelect.cpp in WEBGPU_SRCS.

Buffer re-derivation of the gather (Vulkan IndexSelect.cpp is texture/channel-packed only — op_registry.py tags it CHANNELS_PACKED_TEXTURE; this backend is buffer-only, so the NCHW index math is derived and CPU-de-risked, cf. split.wgsl). Index-value bounds are trusted/unclamped, matching Vulkan index_select.glsl; a negative index is a memory-safe WGSL OOB read (no trap), same safety class as Vulkan's clamped texelFetch. No int dtype-guard on self/out (bit-preserving); nbytes guards reject non-fp32 self/out and a non-int32 index.
@exported-using-ghexport

Differential Revision: D112257660

Differential Revision: D112257660

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 5 New Failures, 11 Pending, 73 Unrelated Failures

As of commit 8d3afdd with merge base 4a26c64 (image):

NEW FAILURES - The following jobs have failed:

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

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.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 22, 2026
This was referenced Jul 22, 2026
This was referenced Jul 22, 2026
@JCNTH
JCNTH requested a review from psiddh July 23, 2026 02:08

@psiddh psiddh 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.

Approving full WebGPU stack

[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