-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Implementation of Common Subexpression Elimination for TIR #9482
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 all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
1b1ab96
Initial implementation of Common Subexpression Elimination for TIR (#…
FranckQC b8f63b4
Merge branch 'apache:main' into FranckQC-CSE
FranckQC 08f4ae2
Merge branch 'main' of github.com:apache/tvm into FranckQC-CSE
FranckQC 0869a42
Added empty newline at the end of every new file
FranckQC c38de61
Rolled-back the pointer to the submodule vta-hw
FranckQC 114740a
Merge branch 'main' of github.com:apache/tvm into FranckQC-CSE
FranckQC 5de7f7d
Merge branch 'main' into FranckQC-CSE
FranckQC 08c3cb1
Merged upstream/main into branch
FranckQC 7afac3f
Improved the CSE by not commoning at the toplevel redundant computati…
FranckQC 2aa7ef9
Spelling and comment
FranckQC c4138d9
Improved the CSE by not commoning at the toplevel redundant computati…
FranckQC b5f4c97
Revert "Improved the CSE by not commoning at the toplevel redundant c…
FranckQC 2ae01d3
Fixed reference used for no reason instead of normal variable.
FranckQC 06f2303
Added comment explaning why we do not need the union/intersection ove…
FranckQC 58fb734
Merge branch 'main' of github.com:apache/tvm into FranckQC-CSE
FranckQC 0d28cc4
Did most of the changes suggested by upstream
FranckQC a2364bd
Continued to work on the remarks given on the public repo.
FranckQC bfe8d4b
Final remarks addressed, small formatting things, and fixing things r…
FranckQC 86c6020
Last linter fix.
FranckQC bb7d56c
Fixing newline
FranckQC 35100f1
Adding newline missing.
FranckQC ea7a042
Minor commit for style fo conform with clang-format
FranckQC 0073e8e
Removed trailing space at end of line
FranckQC 406868d
And more minor style changes
FranckQC 6f5fc37
Fixing style of the python test files
FranckQC cbb8d94
And one more for style in python tests!
FranckQC 0294739
This linter is very annoying to force the style of indentation in a c…
FranckQC 24a1f9c
Deactivate the CSE pass for the lowering tests as it would otherwise …
FranckQC 8e6b4ef
Fixing new lint offenses
FranckQC 34c13f2
Removing debug statement
FranckQC eac78dc
Restore other test file to its previous state
FranckQC 79451e2
One more for the linter...
FranckQC 7803bbb
Linter again, this time for the new test...
FranckQC 24ee891
again
FranckQC 542f963
again...
FranckQC c824f33
Deactivating the CSE pass for another lowering test as it does some c…
FranckQC d8a2c4c
Disabling the CSE for the a test for GPU too
FranckQC 3b6f725
Trying to fix a VTA test by disabling the CSE pass for it, as it prob…
FranckQC ab41b40
Complying with the linter
FranckQC a6409f9
Restarting the CI 1/2
FranckQC 8d62f32
Restarting the CI 2/2
FranckQC b8b33d2
Restarting CI 1/2
FranckQC 4b8c0dd
Restarting CI 2/2
FranckQC 2ea3215
Slightly reduce size of large pretty printer test, copied from https:…
FranckQC 780a00f
Merge branch 'main' of github.com:apache/tvm into FranckQC-CSE
FranckQC 51fff03
Trying to resolve the problems on the weird tests
FranckQC 29e83e4
Linter.
FranckQC 1dc15dc
Restarting CI which has skipped the MacOS build for no reason 1/2
FranckQC 220aa87
Restarting CI which has skipped the MacOS build for no reason 2/2
FranckQC e4c9832
Merge branch 'main' of github.com:apache/tvm into FranckQC-CSE
FranckQC accb0ce
Commented buggy tests
FranckQC 50f1707
Linter...
FranckQC 45fd7da
Restore the VTA tests, and use trick kindly given by Masa to disable…
FranckQC 8230999
New fix, which this time does not break the doc (VTA uses a set with …
FranckQC 4885ad4
More VTA fixes
FranckQC c8b2ff1
vta tutorial fix
masahi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| /*! | ||
| * \file check_contains.cc | ||
| * \brief Implementation of the analysis that tells if an expression contains | ||
| a node that satisfies a given predicate. | ||
| */ | ||
|
|
||
| #include "check_contains.h" | ||
|
|
||
| #include <tvm/tir/expr.h> | ||
|
|
||
| #include <vector> | ||
|
|
||
| namespace tvm { | ||
| namespace tir { | ||
|
|
||
| /*! | ||
| * \brief Toplevel (static) function that tells if an expression contains a subexpression that | ||
| satisfies a given predicate. | ||
| * \param expr The expression to check | ||
| * \param predicate The predicate that must be satisfied | ||
| * \return Whether `expr` contains a subexpression that satisfies `predicate` | ||
| */ | ||
| bool CheckContains::ExprContains(const PrimExpr& expr, | ||
| std::function<bool(const PrimExpr&)> predicate) { | ||
| CheckContains check_contains(predicate); | ||
| check_contains.VisitExpr(expr); | ||
| return check_contains.contains_it_; | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Toplevel (static) function that tells if a statement contains a subexpression that | ||
| satisfies a given predicate. | ||
| * \param stmt The statement to check | ||
| * \param predicate The predicate that must be satisfied | ||
| * \return Whether `stmt` contains a subexpression that satisfies `predicate` | ||
| */ | ||
| bool CheckContains::StmtContains(const Stmt& stmt, std::function<bool(const PrimExpr&)> predicate) { | ||
| CheckContains check_contains(predicate); | ||
| check_contains.VisitStmt(stmt); | ||
| return check_contains.contains_it_; | ||
| } | ||
|
|
||
| /*! | ||
| * \brief Protected constructor of CheckContains. | ||
| * \param predicate The predicate that must be satisfied | ||
| */ | ||
| CheckContains::CheckContains(std::function<bool(const PrimExpr&)> predicate) | ||
| : predicate_(predicate) {} | ||
|
|
||
| /*! | ||
| * \brief The method which overrides the generic dispatcher of StmtExprVisitor for expressions. | ||
| * \param expr The expression to visit | ||
| */ | ||
| void CheckContains::VisitExpr(const PrimExpr& expr) { | ||
| // If the predicate holds on `expr`, we know `expr` contains something which makes | ||
| // the predicate hold | ||
| if (predicate_(expr)) { | ||
| contains_it_ = true; | ||
| } else { | ||
| // Otherwise we continue to look for it recursively by calling the dispatcher | ||
| StmtExprVisitor::VisitExpr(expr); | ||
| } | ||
| } | ||
|
|
||
| /*! | ||
| * \brief The method which overrides the generic dispatcher of StmtExprVisitor for statements. | ||
| * \param stmt The statement to visit | ||
| */ | ||
| void CheckContains::VisitStmt(const Stmt& stmt) { | ||
| // We keep exploring only if `contains_it_` is false | ||
| if (!contains_it_) { | ||
| // and in order to do that we call the general dispatcher | ||
| StmtExprVisitor::VisitStmt(stmt); | ||
| } | ||
| // As otherwise we already have our answer | ||
| } | ||
|
|
||
| } // namespace tir | ||
| } // namespace tvm |
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,60 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| /*! | ||
| * \file check_contains.h | ||
| * \brief Interface of the analysis that tells if an expression contains | ||
| a node that satisfies a given predicate. | ||
| */ | ||
|
|
||
| #ifndef TVM_TIR_ANALYSIS_CHECK_CONTAINS_H_ | ||
| #define TVM_TIR_ANALYSIS_CHECK_CONTAINS_H_ | ||
|
|
||
| #include <tvm/tir/expr.h> | ||
| #include <tvm/tir/stmt_functor.h> // For the class StmtExprVisitor | ||
|
|
||
| namespace tvm { | ||
| namespace tir { | ||
|
|
||
| /*! | ||
| * \brief Visitor which tells if a given expression or statement contains a subexpression | ||
| that satisfies a given predicate | ||
| */ | ||
| class CheckContains : public StmtExprVisitor { | ||
| public: | ||
| // Toplevel (static) functions | ||
| static bool ExprContains(const PrimExpr& expr, std::function<bool(const PrimExpr&)> predicate); | ||
| static bool StmtContains(const Stmt& stmt, std::function<bool(const PrimExpr&)> predicate); | ||
|
|
||
| protected: | ||
| // Constructor | ||
| explicit CheckContains(std::function<bool(const PrimExpr&)> predicate); | ||
|
|
||
| void VisitExpr(const PrimExpr& expr) override; | ||
| void VisitStmt(const Stmt& stmt) override; | ||
|
|
||
| private: | ||
| std::function<bool(const PrimExpr&)> predicate_; | ||
| bool contains_it_ = false; | ||
| }; | ||
|
|
||
| } // namespace tir | ||
| } // namespace tvm | ||
|
|
||
| #endif // TVM_TIR_ANALYSIS_CHECK_CONTAINS_H_ | ||
Oops, something went wrong.
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.