Repository navigation
Fix dpnp.einsum memory-layout - #3058
Merged
antonwolfy merged 8 commits intoSep 9, 2026
Merged
Conversation
abagusetty
requested review from
antonwolfy,
ndgrigorian and
vlad-perevezentsev
as code owners
September 2, 2026 17:17
|
Can one of the admins verify this patch? |
Collaborator
antonwolfy
reviewed
Sep 3, 2026
antonwolfy
reviewed
Sep 5, 2026
| # a unary einsum without summation returns a view, as NumPy does for every | ||
| # `order` | ||
| if not returns_view: | ||
| if order == "K" and not all_f_contiguous: |
Contributor
There was a problem hiding this comment.
optimize=True now forces the result to C-contiguous, which
- changes behavior that previously matched NumPy on that path
- adds a copy for no functional benefit
Contributor
Author
There was a problem hiding this comment.
Shoot, now the order=K copy is gated with optimize is False so the matmul-based paths keep their layouts
Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com>
…agusetty/dpnp into fix-einsum-order-k-contiguity
antonwolfy
approved these changes
Sep 9, 2026
Contributor
There was a problem hiding this comment.
Thank you @abagusetty for improving the handling, LGTM
5 of 7 tasks
vlad-perevezentsev
added a commit
that referenced
this pull request
Sep 16, 2026
This PR improves `dpnp.einsum` performance by avoiding a copy into C-order. Commit 039b7f1 (#3058) remaps `order="K"` to `"C"` which turned the final `dpnp.asarray` from a no-op into a full device copy because dpnp contracts operands in reverse order so `"ij,jk"` computes `(a @ b).T` and the result is naturally `f-contiguous` This PR builds the result directly in the requested layout instead of fixing it afterwards. The last contraction determines the output axis order, so it can choose which operand is on the left side of the matmul and avoid an extra copy. This is only applied for `"C"` order, since for other layouts the default operand order already matches the expected `order="K" + optimize=True` behavior. The swap does not move any data. It only changes the operand order in the matmul
github-actions Bot
added a commit
that referenced
this pull request
Sep 16, 2026
This PR improves `dpnp.einsum` performance by avoiding a copy into C-order. Commit 039b7f1 (#3058) remaps `order="K"` to `"C"` which turned the final `dpnp.asarray` from a no-op into a full device copy because dpnp contracts operands in reverse order so `"ij,jk"` computes `(a @ b).T` and the result is naturally `f-contiguous` This PR builds the result directly in the requested layout instead of fixing it afterwards. The last contraction determines the output axis order, so it can choose which operand is on the left side of the matmul and avoid an extra copy. This is only applied for `"C"` order, since for other layouts the default operand order already matches the expected `order="K" + optimize=True` behavior. The swap does not move any data. It only changes the operand order in the matmul 53ac592
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.
One more minor layout issue detected during an app-testing in comparison to numpy behavior:
Fixes: #3056