Skip to content

Add vectorization in elementwise_util #9432

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

Open
wants to merge 96 commits into
base: gh/swolchok/439/head
Choose a base branch
from

Conversation

swolchok
Copy link
Contributor

@swolchok swolchok commented Mar 20, 2025

This is a first cut at #9241 . In this PR I've vectorized a small initial set of ops: atan2, clamp, fmod_Scalar, maximum, minimum, mul, pow, and sigmoid. In addition, the following ops should have gotten vectorized automatically because they already used generic lambdas: add, div, rsub, sub. I've left covering ops that use the unary_ufunc_* utilities in pattern.h for a follow-up push, because pattern.h and elementwise_util need some work before we can migrate pattern.h's utilities to be backed by elementwise_util.

This PR adds an interesting testing problem: in theory, all operators might need test cases long enough to tickle vectorization, because we might accidentally vectorize ops unexpectedly and break their lambdas due to anticipated differences in semantics. I address this issue by using Vectorized for the scalar prologue/epilogue in debug mode (we run tests in both debug and release) so that we can detect broken lambdas. I additionally intentionally introduced a bug in the vectorized path in elementwise_util and manually verified that we saw test failures for each vectorized op called out above.

swolchok added 18 commits March 18, 2025 17:32
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Copy link

pytorch-bot bot commented Mar 20, 2025

🔗 Helpful Links

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

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

❌ 1 New Failure, 1 Unrelated Failure

As of commit 84170e4 with merge base 71025df (image):

NEW FAILURE - The following job has failed:

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.

swolchok added a commit that referenced this pull request Mar 20, 2025
this works with op_mul, which is vectorized-friendly, but doesn't work
when we roll out to pattern.h because those ops will not work with
Vectorized yet. See TODO in elementwise_util.h

ghstack-source-id: 30d2311
ghstack-comment-id: 2738665976
Pull Request resolved: #9432
@swolchok swolchok added the release notes: ops & kernels Changes to the opset and any new / changed kernel implementations label May 27, 2025
@swolchok swolchok marked this pull request as ready for review May 27, 2025 23:57
swolchok added a commit that referenced this pull request May 28, 2025
this works with op_mul, which is vectorized-friendly, but doesn't work
when we roll out to pattern.h because those ops will not work with
Vectorized yet. See TODO in elementwise_util.h

ghstack-source-id: 4ed038f
ghstack-comment-id: 2738665976
Pull Request resolved: #9432
@swolchok swolchok requested a review from kimishpatel May 28, 2025 18:02
@swolchok swolchok marked this pull request as draft May 28, 2025 20:07
swolchok added a commit that referenced this pull request May 28, 2025
this works with op_mul, which is vectorized-friendly, but doesn't work
when we roll out to pattern.h because those ops will not work with
Vectorized yet. See TODO in elementwise_util.h

ghstack-source-id: 66f9d9d
ghstack-comment-id: 2738665976
Pull Request resolved: #9432
[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 28, 2025
this works with op_mul, which is vectorized-friendly, but doesn't work
when we roll out to pattern.h because those ops will not work with
Vectorized yet. See TODO in elementwise_util.h

ghstack-source-id: 66f9d9d
ghstack-comment-id: 2738665976
Pull Request resolved: #9432
@swolchok swolchok changed the base branch from main to gh/swolchok/439/head May 28, 2025 22:09
[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 28, 2025
this works with op_mul, which is vectorized-friendly, but doesn't work
when we roll out to pattern.h because those ops will not work with
Vectorized yet. See TODO in elementwise_util.h

ghstack-source-id: 66f9d9d
ghstack-comment-id: 2738665976
Pull Request resolved: #9432
[ghstack-poisoned]
@kimishpatel
Copy link
Contributor

This is still in draft state. Are you planning to push more changes?

@swolchok
Copy link
Contributor Author

This is still in draft state. Are you planning to push more changes?

I was waiting for CI to be green before bothering reviewers. Will publish shortly

[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 29, 2025
[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 29, 2025
[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 29, 2025
[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 29, 2025
[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 29, 2025
[ghstack-poisoned]
swolchok added a commit that referenced this pull request May 29, 2025
[ghstack-poisoned]
@swolchok swolchok marked this pull request as ready for review May 29, 2025 19:27
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: ops & kernels Changes to the opset and any new / changed kernel implementations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants