-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[IR][SIBuilder] #14574
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
[IR][SIBuilder] #14574
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /* | ||
| * 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 tvm/ir/si_builder.h | ||
| * \brief build a source info during rewriting expressions. | ||
| */ | ||
| #ifndef TVM_IR_SI_BUILDER_H_ | ||
| #define TVM_IR_SI_BUILDER_H_ | ||
|
|
||
| #include <tvm/relay/expr.h> | ||
| #include <tvm/relay/expr_functor.h> | ||
| #include <tvm/tir/stmt.h> | ||
|
|
||
| #include <memory> | ||
| #include <unordered_set> | ||
|
|
||
| namespace tvm { | ||
|
|
||
| /*! | ||
| * \brief Source Information Builder, SIBuilder provides helper APIs for filling spans, | ||
| * particularly useful for one-to-many, many-to-one and many-to-many IR transformations. | ||
| */ | ||
| class SIBuilder { | ||
| public: | ||
| /*! | ||
| * \brief Create SIBuilder from a given span | ||
| */ | ||
| explicit SIBuilder(const Span& span = Span()); | ||
|
|
||
| /*! | ||
| * \brief Create SIBuilder from a given span sequence | ||
| */ | ||
| explicit SIBuilder(const Array<Span>& spans = Array<Span>()); | ||
| explicit SIBuilder(const std::initializer_list<Span>& init); | ||
|
|
||
| /*! | ||
| * \brief Create SIBuilder via a subgraph, | ||
| * Will construct span based on the exprs in the subgraph. Including the inputs exprs. | ||
| * | ||
| * \param entry Entry expr for subgraph | ||
| * \param inputs End exprs for subgraph | ||
| */ | ||
| template <typename T, typename = std::enable_if_t<std::is_base_of<BaseExpr, T>::value>> | ||
| explicit SIBuilder(const T& entry, const tvm::Array<T>& inputs = {}); | ||
| explicit SIBuilder(const tir::Stmt& entry, const tvm::Array<PrimExpr>& inputs = {}); | ||
| explicit SIBuilder(const tir::Stmt& entry, const tvm::Array<tir::Stmt>& inputs = {}); | ||
|
|
||
| ~SIBuilder(); | ||
|
|
||
| SIBuilder(const SIBuilder&) = delete; | ||
| SIBuilder& operator=(const SIBuilder&) = delete; | ||
|
|
||
| /*! | ||
| * \brief build a span of source information, which is based on the given span or subgraph. | ||
| * | ||
| * \return the built span | ||
| */ | ||
| Span Build() const; | ||
|
|
||
| /*! | ||
| * \brief Recursively fill all span of exprs in subgraph from entry until inputs. | ||
| * | ||
| * \param entry Entry expr for subgraph. | ||
| * \param inputs End exprs for subgraph, will not be filled with new span. | ||
| */ | ||
| template <typename T, typename = std::enable_if_t<std::is_base_of<BaseExpr, T>::value>> | ||
| void RecursivelyFillSpan( | ||
| const T& entry, const std::unordered_set<T, ObjectPtrHash, ObjectPtrEqual>& inputs) const; | ||
|
|
||
| void RecursivelyFillSpan( | ||
| const tir::Stmt& entry, | ||
| const std::unordered_set<PrimExpr, ObjectPtrHash, ObjectPtrEqual>& inputs) const; | ||
| void RecursivelyFillSpan( | ||
| const tir::Stmt& entry, | ||
| const std::unordered_set<tir::Stmt, ObjectPtrHash, ObjectPtrEqual>& inputs) const; | ||
|
|
||
| private: | ||
| struct Impl; | ||
| std::unique_ptr<Impl> impl_; | ||
|
|
||
| std::unique_ptr<Impl> CreateImpl(const Span& span); | ||
| }; | ||
|
|
||
| } // namespace tvm | ||
|
|
||
| #endif // TVM_IR_SI_BUILDER_H_ | ||
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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| Node, | ||
| SourceName, | ||
| Span, | ||
| SequentialSpan, | ||
| assert_structural_equal, | ||
| load_json, | ||
| save_json, | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ | |
|
|
||
| # Span | ||
| Span = base.Span | ||
| SequentialSpan = base.SequentialSpan | ||
| SourceName = base.SourceName | ||
|
|
||
| # Type | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document what "SI" stands for
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add to comments. It stands for source information builder.