Skip to content

[ET-VK] Add 2D Reduction to Vulkan Backend #12860

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 8 commits into from
Aug 6, 2025
Merged

Conversation

alexdean08
Copy link
Collaborator

@alexdean08 alexdean08 commented Jul 25, 2025

Summary: This change adds 2D reduction to the Vulkan delegate. Prior to this change, only 1D reduction was implemented. Models like MobileNetV3 and ResNet do 2D reduction, and their performance was being negatively impacted by the lack of a 2D reduction Vulkan implementation.

cc @SS-JIA @manuelcandales @cbilgin

@alexdean08 alexdean08 requested a review from SS-JIA as a code owner July 25, 2025 17:54
@pytorch-bot pytorch-bot bot added the module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ label Jul 25, 2025
Copy link

pytorch-bot bot commented Jul 25, 2025

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 New Failures, 1 Unrelated Failure

As of commit 3ca809f with merge base 9d86cbe (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 Jul 25, 2025
@alexdean08
Copy link
Collaborator Author

@pytorchbot label "release notes: vulkan"

@pytorch-bot pytorch-bot bot added the release notes: vulkan Changes to the Vulkan backend delegate label Jul 25, 2025
Copy link
Contributor

@SS-JIA SS-JIA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some small comments. Thanks for working on this!

// with the accumulator.
#define POSTPROCESS(accum) ${POSTPROCESS}

void reduce_2d(const ivec2 tid, ivec3 scan_pos) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand it, this implementation doesn't currently support reduction among the elements of a texel,.

So for example for a tensor of size (channels = 4, height = 16, width = 16) where reading one texel returns 4 channels, this function would only be able to handle reduction along the height and width dims, but not if channels is one of the dims being reduced - is that correct?

If so, we can leave the more generalized implementation for later, but we should add some checks to make sure we don't lower unsupported cases to Vulkan 😛

Would also recommend renaming this function to reduce_2d_non_texel_dim or reduce_2d_non_packed_dim.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup you're right, this doesn't support reduction among the elements of a texel. Just changed to reduce_2d_non_packed_dim. Let me know if you're aligned

reduce_dim1 = nchw_dim_to_whcn_dim(reduce_dim1, ndim);
reduce_dim2 = nchw_dim_to_whcn_dim(reduce_dim2, ndim);

// Check that the concat dim is not one of the reduction dims
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should also add a check that graph.packed_dim_of(in) and graph.packed_dim_of(out) is not one of the reduction dims.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added above this comment. Let me know if you're aligned

@alexdean08 alexdean08 merged commit 112a09f into pytorch:main Aug 6, 2025
99 of 102 checks passed
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. module: vulkan Issues related to the Vulkan delegate and code under backends/vulkan/ release notes: vulkan Changes to the Vulkan backend delegate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants