Skip to content

[ET-VK] Reducing precision of some in members in conv2d pw to improved performance. #11192

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 12 commits into from
May 29, 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: #11139 by @trivedivivek
^ 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/trivedivivek/99/base
ghstack PR head: https://github.com/pytorch/executorch/tree/gh/trivedivivek/99/head
Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/trivedivivek/98/orig
Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/trivedivivek/99/orig
@diff-train-skip-merge

Pull Request resolved: #11108

This diff optimizes the performance of the `conv2d_pw` shader by de-vectorizing its implementation.

*   The original vectorized implementation of the `conv2d_pw` shader has been replaced with a de-vectorized approach to improve performance.
*   The `sum` array has been redefined to hold `float` values instead of `vec4` to accommodate the de-vectorized computation.

These changes seem to allow shader compiler to better optimize operations within the shader hence improving perf.
ghstack-source-id: 286652100
@exported-using-ghexport

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

This diff removes the use of shared memory in the conv2d pw (pointwise) operation to improve performance.
ghstack-source-id: 286652103

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

This diff tunes the tile size for the conv 2d pw op to improve performance. The changes include updating the `TILE_SIZE_X` and `TILE_SIZE_Y` values in the `conv2d_pw.yaml` files and modifying the `Convolution.cpp` files to adjust the image extents calculation. The `TILE_SIZE_X` value is changed from 2 to 1, and the `TILE_SIZE_Y` value is changed from 2 to 4.
ghstack-source-id: 286652109

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

The diff introduces minor tuning for the Conv2d pointwise (PW) operation in the Vulkan backend to improve performance.
Conv 2d pw now issues a 2D dispatch instead of 1D, where dispatch axis y is now sized based on output texture's batch size.
ghstack-source-id: 286652099

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

This improves the performance of the conv2d pw shader by de-vectorizing position storage.
The optimization involved replacing the `ivec3 pos` array with a plain `int pos` array to store the position values. The `x` and `y` coordinates are now stored in separate elements of the array instead of being stored together in an `ivec3`. This change allows for more efficient memory access and computation.
ghstack-source-id: 286652097
@exported-using-ghexport

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

This diff provides a minor unroll tuning to improve the performance of the conv2d pointwise (pw) operation in the Executorch Vulkan backend.
ghstack-source-id: 286652101
@exported-using-ghexport

Differential Revision: [D75420510](https://our.internmc.facebook.com/intern/diff/D75420510/)
…ove performance.

Pull Request resolved: #11135

This diff adjusts the local workgroup size (`local_wg_size`) based on batch count (stored in  `wg_size[1]`), to improve conv2d pw performance.

* If `wg_size[1]` is a multiple of 8, `local_wg_size_y` is set to 8.
* If `wg_size[1]` is a multiple of 4, `local_wg_size_y` is set to 4.
* If `wg_size[1]` is a multiple of 2, `local_wg_size_y` is set to 2.
* Otherwise, we default to `local_wg_size_y` = 1.

The dispatch size in 2 dimensions is then calculate based on `{64 / local_wg_size_y, local_wg_size_y, 1}`.
ghstack-source-id: 286652105
@exported-using-ghexport

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

This diff improves the performance of the conv2d pw shader by de-vectorizing all vectors.
ghstack-source-id: 286652098
@exported-using-ghexport

Differential Revision: [D75423245](https://our.internmc.facebook.com/intern/diff/D75423245/)
…stride = 1 and padding = 0.

Pull Request resolved: #11137

This diff creates a specialized version of the conv2d pw shader for X and Y stride equals 1 and padding equals 0.

* It adds a new file `conv2d_pw_s1p0.glsl`, which implements the conv2d pw shader for X and Y stride equals 1 and padding equals 0.
* It adds a new file `conv2d_pw_s1p0.yaml`, which defines the parameters and shader variants for the specialized conv2d pw shader.
* The file `Convolution.cpp` is modified to add a new parameter `stride_1_padding_0` to the `conv2d` function, which enables the use of the specialized shader.
ghstack-source-id: 286652107
@exported-using-ghexport

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

Pull Request resolved: #11138

This diff modifies the `conv2d_pw_s1p0.glsl` shader to store positions in `uint16` instead of `int`. The changes include adding the necessary extension for explicit arithmetic types, updating the type definitions for `TILE_SIZE_X` and `TILE_SIZE_Y`, and changing the type of the `pos` array.
ghstack-source-id: 286652102
@exported-using-ghexport

Differential Revision: [D75423935](https://our.internmc.facebook.com/intern/diff/D75423935/)
…d performance.

Pull Request resolved: #11139

Reducing precision of some in members in conv2d pw to improve performance.
ghstack-source-id: 286652106
@exported-using-ghexport

Differential Revision: [D75423958](https://our.internmc.facebook.com/intern/diff/D75423958/)
@pytorchbot pytorchbot requested a review from SS-JIA as a code owner May 28, 2025 15:54
Copy link

pytorch-bot bot commented May 28, 2025

🔗 Helpful Links

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

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

⏳ No Failures, 2 Pending

As of commit 9d95ea9 with merge base 5200778 (image):
💚 Looks good so far! There are no failures yet. 💚

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 May 28, 2025
@trivedivivek trivedivivek added the release notes: vulkan Changes to the Vulkan backend delegate label May 28, 2025
Base automatically changed from gh/trivedivivek/98/orig to main May 29, 2025 17:13
@trivedivivek trivedivivek merged commit 71025df into main May 29, 2025
96 checks passed
@trivedivivek trivedivivek deleted the gh/trivedivivek/99/orig branch May 29, 2025 18:36
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. release notes: vulkan Changes to the Vulkan backend delegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants