Skip to content

[ET-VK][runtime] Write one vec4 texel per thread in buffer permute and view - #25326

Merged
SS-JIA merged 1 commit into
mainfrom
gh/SS-JIA/739/orig
Nov 20, 2026
Merged

SS-JIA merged 1 commit into
mainfrom
gh/SS-JIA/739/orig

Conversation

@pytorchbot

Copy link
Copy Markdown
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #25305 by @SS-JIA
^ Please use this as the source of truth for the PR details, comments, and reviews
ghstack PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/739/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/739/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/main
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/739/orig
Differential Revision: D133233612
@diff-train-skip-merge

…d view

Pull Request resolved: #25305

## Ulterior Motive

Buffer tensors pad the packed dim to a multiple of four. This commit recovers the latency that padding costs a model with decomposed pixel shuffles, while keeping the padding.

## Rationale

**What**: `permute` and `view_copy` get vec4 shader variants for buffer outputs whose packed dim has stride 1. Each thread writes one texel of four packed-dim elements.

**Why**: Exporting with decompositions turns `pixel_shuffle` into `view -> permute -> view`. The permute output's packed dim has size 2, so padding doubles the buffer and half of its elements are padding. The scalar shaders spend one thread on each of those elements, and the following view loses its same-physical-order fast path.

## Details

- Dispatch
  - **Before**: `permute_buffer` and `view_buffer` launch one thread per padded output element and do scalar writes.
  - **After**: if `is_packed_dim_vec4_contiguous(out)` holds, `permute_vec4_buffer` / `view_vec4_buffer` launch one thread per texel (`default_pick_vec4_gwg`) and write a vec4. All other outputs keep the scalar shaders.
- `is_packed_dim_vec4_contiguous` (`TensorUtils`) returns true for a buffer tensor that meets all of these:
  - elements of at most 4 bytes;
  - packed block size 1;
  - packed dim aligned to 4;
  - packed dim innermost in the dim order.
- Both shaders select the vec4 path with a `VEC4_OUTPUT` macro and `#ifdef` inside `main()`. Only the output binding declaration differs per variant.
- `permute_vec4_buffer`:
  - It computes the tensor index once per texel.
  - Lane `i` reads `inp_bufi + i * stride`, where `stride` is the input stride of the permuted packed dim.
  - Padding lanes are written as zero.
- `view_vec4_buffer`:
  - If input and output have the same physical element order, it copies four consecutive elements.
  - Otherwise, lane 0 maps through the contiguous index. Later lanes either advance the input index by one contiguous step, when every dim below the packed dim has size 1, or recompute it.
- `cases.py` changes:
  - New pixel-shuffle-shaped 6D cases for buffer `permute` (float and int32, all layouts, zero-padding checks) and for `view_copy`.
  - The `view_copy` highdim suite now also runs int32 and checks zero padding.

Authored with Claude Code.

Differential Revision: [D133233612](https://our.internmc.facebook.com/intern/diff/D133233612/)

**NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D133233612/)!
ghstack-source-id: 478906400
@pytorchbot
pytorchbot requested a review from SS-JIA as a code owner November 20, 2026 02:31
@pytorch-bot

pytorch-bot Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ 73 Pending, 1 Unrelated Failure

As of commit 7ee6c46 with merge base c29858d (image):

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@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 Nov 20, 2026
@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.

@SS-JIA
SS-JIA added this pull request to stack #25329 November 20, 2026 02:47
@SS-JIA
SS-JIA merged commit 7b9752e into main Nov 20, 2026
217 of 222 checks passed
@SS-JIA
SS-JIA deleted the gh/SS-JIA/739/orig branch November 20, 2026 02:48

This branch was previously deployed

1 inactive deployment
cadence — 7ee6c466 Deployed Nov 20, 2026 by pytorchbot via hifi5s-op-test / hifi5s #39577
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants