Skip to content

[ET-VK] Introduce generalized shaders for transfer ops and use it for select and slice #11304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 3, 2025

Conversation

pytorchbot
Copy link
Collaborator

This PR was created by the merge bot to help merge the original PR into the main branch.
ghstack PR number: #11255 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/231/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/231/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/SS-JIA/230/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/SS-JIA/231/orig
@diff-train-skip-merge

SS-JIA added 3 commits June 2, 2025 15:30
Pull Request resolved: #11253

## Changes

* Call `encode_execute()` upon resize in `propagate_resize()`
* Minor update to `DispatchNode` to store push constant data array as a persistent member of the class

## Motivation

Passing in tensor metadata (i.e. sizes, strides) via push constants is typically more performant than passing them via a UBO (uniform buffer object). However, currently dynamic shapes do not work when push constants are used as I realized that the tensor metadata contained in the push constants do not get updated.

It appears that that `vkCmdPushConstants` sets the push constants when encoding the command buffer, however the push constants will not be updated if the command buffer is submitted for execution multiple times. Therefore, to update push constant values **the command buffer needs to be re-encoded**.

## Performance Impact

This may add a small performance overhead (i.e. re-encoding the command buffer) when executing models with dynamic shapes. Models that do not trigger tensor resizing will not be impacted.

However, I measured the impact on a llama 3.2 1B model and the impact of re-encoding a command buffer appears to be negligible.

In any case, re-encoding the command buffer is a "necessary evil" when working with dynamic shapes, otherwise the tensor metadata seen by shaders may never get updated. Furthermore, re-encoding the command buffer can allow an opportunity to adjust global work group sizing to match current tensor sizes, which may have a huge performance impact when maximum tensor sizes far exceeds what tensor sizes will realistically be during inference (one instance of this is for transformer models when the max sequence length is very long).
ghstack-source-id: 287711101
@exported-using-ghexport

Differential Revision: [D75686051](https://our.internmc.facebook.com/intern/diff/D75686051/)
Pull Request resolved: #11254

## Changes

For `DynamicDispatchNode`:
* Pass in global work group size to the local work group size determination function
* Add additional constructor for which the shader is not dynamic
* During `encode`, check that pick functions are not `nullptr`

## Motivation

Oftentimes it is useful to know what the global work group size is when determining what the local group group size should be.

## Performance Impact

None.
ghstack-source-id: 287711100
@exported-using-ghexport

Differential Revision: [D75686047](https://our.internmc.facebook.com/intern/diff/D75686047/)
… select and slice

Pull Request resolved: #11255

## Changes

* Introduce `transfer_buffer.glsl` and `transfer_texture.glsl`, and `Transfer.cpp` which generalizes shaders where each element of the output is copied from a unique element of the input.
* Update `Slice.cpp` and `Select.cpp` to use `Transfer.cpp`
* Remove old implementations of slice and select

## Motivation

With this new implementation, the op can now support both buffers and textures of any packing. There are also benefits of code consolidation.
ghstack-source-id: 287711104
@exported-using-ghexport

Differential Revision: [D75686050](https://our.internmc.facebook.com/intern/diff/D75686050/)
@pytorchbot pytorchbot requested a review from SS-JIA as a code owner June 3, 2025 00:00
Copy link

pytorch-bot bot commented Jun 3, 2025

🔗 Helpful Links

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

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

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

@facebook-github-bot facebook-github-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 Jun 3, 2025
Base automatically changed from gh/SS-JIA/230/orig to main June 3, 2025 00:22
@SS-JIA SS-JIA merged commit 1a11267 into main Jun 3, 2025
93 checks passed
@SS-JIA SS-JIA deleted the gh/SS-JIA/231/orig branch June 3, 2025 00:23
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.

3 participants