-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir][tensor] Loosen restrictions on folding dynamic reshapes #137963
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
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2ae4480
[mlir][tensor] Loosen restrictions on folding dynamic reshapes
AGindinson 4f7c389
Merge branch 'main' into artem/upstream/reassoc-expand-of-collapse
AGindinson 18da6fe
Merge branch 'main' into artem/upstream/reassoc-expand-of-collapse
AGindinson 52ff4e0
[fixup] Algorithm rewrite
AGindinson 1c85a68
[fixup] Add/expand unit tests
AGindinson 0fe986e
[fixup] variable renaming
AGindinson e3aa239
[fixup] Additional edge-case
AGindinson 16a932c
[WIP] Current tests pass
AGindinson dd36c47
[WIP] New tests
AGindinson 114af4b
Merge branch 'main' into artem/upstream/reassoc-expand-of-collapse
AGindinson 07ed33d
[fixup] Add scalar target tests & fix em
AGindinson 6e61a52
[fixup] for self-induced unit dims problem
AGindinson b0e5c93
Merge branch 'main' into artem/upstream/reassoc-expand-of-collapse
AGindinson a6a18d6
[fixup] apply non-functional comments
AGindinson ce007de
[fixup] apply greedy logic suggestions
AGindinson 66adf99
Merge branch 'main' into artem/upstream/reassoc-expand-of-collapse
AGindinson 15caa29
[fixup] improve `getNonOverlappingIndicesWith(&rhs)`
AGindinson 6b5d5cd
Merge branch 'main' into artem/upstream/reassoc-expand-of-collapse
AGindinson 35cb397
Merge branch 'main' into reassoc-expand-of-collapse
AGindinson 20e9a9f
Merge branch 'main' into reassoc-expand-of-collapse
AGindinson 880b394
[fixup] Reduce auto usage, drop obsolete variable
AGindinson cc6df04
[fixup] Move a comment to the right place
AGindinson ea9161d
[fixup] Clarify some early-return cases
AGindinson 54abd87
[fixup] Improve auto usage further
AGindinson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| //===- ReshapeOpsUtilsTest.cpp - ReshapeOpsUtils unit tests ---------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "mlir/Dialect/Utils/ReshapeOpsUtils.h" | ||
| #include "llvm/ADT/STLExtras.h" | ||
| #include "gtest/gtest.h" | ||
| #include <optional> | ||
|
|
||
| using namespace mlir; | ||
|
|
||
| /// Helper to make constructing | ||
| /// `std::optional<SmallVector<ReassociationIndices>>` more readable. | ||
| static std::optional<SmallVector<ReassociationIndices>> | ||
| makeOptionalIndices(std::initializer_list<ReassociationIndices> list) { | ||
| return std::optional<SmallVector<ReassociationIndices>>(list); | ||
| } | ||
|
|
||
| TEST(ReassociationIndicesForCollapse, StaticTest) { | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 20}, {200}), | ||
AGindinson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| makeOptionalIndices({{0, 1}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 20, 30}, {10, 600}), | ||
| makeOptionalIndices({{0}, {1, 2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 20, 30}, {200, 30}), | ||
| makeOptionalIndices({{0, 1}, {2}})); | ||
| } | ||
|
|
||
| TEST(ReassociationIndicesForCollapse, StaticTestFailure) { | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 20}, {10}), std::nullopt); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 20}, {10, 20}), | ||
AGindinson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::nullopt); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 20, 30}, {200, 300}), | ||
| std::nullopt); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 20, 30}, {1, 10, 20, 30}), | ||
| std::nullopt); | ||
| } | ||
|
|
||
| TEST(ReassociationIndicesForCollapse, StaticTestUnitDims) { | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, 1}, {10}), | ||
| makeOptionalIndices({{0, 1}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({1, 20, 30}, {600}), | ||
| makeOptionalIndices({{0, 1, 2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({1, 1, 1}, {1}), | ||
| makeOptionalIndices({{0, 1, 2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({1, 1, 1}, {1, 1}), | ||
| makeOptionalIndices({{0}, {1, 2}})); | ||
| } | ||
|
|
||
| TEST(ReassociationIndicesForCollapse, DynamicTest) { | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({ShapedType::kDynamic, 1}, | ||
| {ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({ShapedType::kDynamic, 1, 1}, | ||
| {ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1, 2}})); | ||
| EXPECT_EQ( | ||
| getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}, {ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {1, ShapedType::kDynamic, ShapedType::kDynamic}, | ||
| {1, ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0}, {1, 2}})); | ||
|
|
||
| EXPECT_EQ(getReassociationIndicesForCollapse({ShapedType::kDynamic, 10}, | ||
| {ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {1, ShapedType::kDynamic, ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1, 2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({ShapedType::kDynamic, 10, 20}, | ||
| {ShapedType::kDynamic, 20}), | ||
| makeOptionalIndices({{0, 1}, {2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({10, ShapedType::kDynamic, 20}, | ||
| {ShapedType::kDynamic, 20}), | ||
| makeOptionalIndices({{0, 1}, {2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, 3, 2, 5, 2}, {ShapedType::kDynamic, 20}), | ||
| makeOptionalIndices({{0, 1}, {2, 3, 4}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {10, ShapedType::kDynamic, 20, ShapedType::kDynamic, 1}, | ||
| {ShapedType::kDynamic, 20, ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1}, {2}, {3, 4}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({1, ShapedType::kDynamic, 1}, | ||
| {ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1, 2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, ShapedType::kDynamic, 1}, | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0}, {1, 2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {1, ShapedType::kDynamic, ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0, 1}, {2}})); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, 1, ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}), | ||
| makeOptionalIndices({{0}, {1, 2}})); | ||
| } | ||
|
|
||
| TEST(ReassociationIndicesForCollapse, DynamicTestFailure) { | ||
| EXPECT_EQ(getReassociationIndicesForCollapse({ShapedType::kDynamic, 10, 20}, | ||
| {ShapedType::kDynamic, 10}), | ||
| std::nullopt); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, 10, ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}), | ||
| std::nullopt); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {20, ShapedType::kDynamic, 10, ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}), | ||
| std::nullopt); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, 5, 3, 2, 2}, {ShapedType::kDynamic, 20}), | ||
| std::nullopt); | ||
| EXPECT_EQ( | ||
| getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, ShapedType::kDynamic, ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}), | ||
| std::nullopt); | ||
| EXPECT_EQ(getReassociationIndicesForCollapse( | ||
| {ShapedType::kDynamic, ShapedType::kDynamic, 10, 1, | ||
| ShapedType::kDynamic}, | ||
| {ShapedType::kDynamic, ShapedType::kDynamic}), | ||
| std::nullopt); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.