Repository navigation
Conversation
Use broadcast-aware indexing for complex div in optimized and portable CPU kernels to avoid reading past broadcast operands. Require matching input and output complex dtypes, consistent with the existing complex arithmetic kernels.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24409
Note: Links to docs will display an error until the docs builds have been completed.
|
Contributor
Author
|
@pytorchbot label "release notes: ops & kernels" |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The portable and optimized division helpers write broadcast results sequentially rather than using output strides, permuting results for channels-last tensors and requiring a stride-aware fix with regression coverage.
1 open issue
What changed in this PR
This PR addresses the complex division broadcasting bug from #24408 in ExecuTorch’s portable and optimized CPU kernels.
Changes:
- Replace direct input indexing with the shared binary elementwise broadcasting helper.
- Require matching complex input and output dtypes before typed data access.
- Add complex64/128 regression tests for scalar and multidimensional broadcasting, empty tensors, and dtype mismatches.
| File | Description |
|---|---|
kernels/test/op_div_test.cpp |
Adds complex broadcasting and dtype-rejection tests. |
kernels/portable/cpu/op_div.cpp |
Uses the broadcasting helper and validates complex dtypes. |
kernels/optimized/cpu/op_div.cpp |
Applies the same changes to optimized complex division. |
Review effort: Balanced
Comment on lines
+68
to
+72
| apply_binary_elementwise_fn<CTYPE, CTYPE, CTYPE>( | ||
| [](const CTYPE val_a, const CTYPE val_b) { return val_a / val_b; }, | ||
| a, | ||
| b, | ||
| out); |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Refs #24408
The optimized and portable complex div kernels index both inputs using the output index. When an operand is broadcast, this can read past its buffer and produce incorrect results.
Use
apply_binary_elementwise_fnto handle broadcasting, and require matching input/output dtypes before accessing typed data.Add regression tests for complex64/128 covering scalar operands on either side, multidimensional broadcasting, empty tensors, and mismatched dtypes.
Test plan
Run the div tests in both CPU configurations:
Result: 28 optimized CPU tests and 32 portable CPU tests passed.