[TIR][Utility] More flexible tir::Substitute arguments#14251
Merged
kparzysz-quic merged 3 commits intoapache:mainfrom Mar 23, 2023
Merged
[TIR][Utility] More flexible tir::Substitute arguments#14251kparzysz-quic merged 3 commits intoapache:mainfrom
kparzysz-quic merged 3 commits intoapache:mainfrom
Conversation
Previously, the `tir::Substitute` method had overloads that supported a few ways of providing the variable map (e.g. `const Map<Var,PrimExpr>&`, `std::unordered_map<const VarNode*, PrimExpr>&`, etc.), delegating out to the overload that uses `std::function<Optional<PrimExpr>(const Var&)>`. However, the types supported for the variable map depended on the type being substituted (e.g. only supporting `const Map<Var,PrimExpr>&` with substituting into a `Array<Range>`), which would be unexpected to new developers. This PR makes the `tir::Substitute` utility more uniform in the arguments that it accepts. * For any type that is supported by `tir::Substitute`, `Array<T>` is also supported. * Any variable mapping type can be used with any substitution type. All variable mapping types are normalized to `std::function<Optional<PrimExpr>(const Var&)>`. * For `Map` and `std::unordered_map` arguments, the value type may be any subclass of `PrimExpr` (e.g. `Map<Var, Var>` instead of `Map<Var, PrimExpr>`). Previously, the calling scope needed to either construct a temporary map that returned `PrimExpr`, or to use a broader value type in the map than otherwise required. The initial and primary goal was to allow a `Map<Var, Var>` to be used as an argument to `tir::Substitute`, rather than a `Map<Var, PrimExpr>`, and making the utility more general was more straightforward than adding multiple overloads specificall for `Map<Var, Var>`.
Collaborator
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
kparzysz-quic
approved these changes
Mar 22, 2023
Contributor
kparzysz-quic
left a comment
There was a problem hiding this comment.
LGTM, pending some comment fixes.
Contributor
Author
|
Thank you, and corrected the copy/paste errors in the docstring. |
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.
Previously, the
tir::Substitutemethod had overloads that supported a few ways of providing the variable map (e.g.const Map<Var,PrimExpr>&,std::unordered_map<const VarNode*, PrimExpr>&, etc.), delegating out to the overload that usesstd::function<Optional<PrimExpr>(const Var&)>. However, the types supported for the variable map depended on the type being substituted (e.g. only supportingconst Map<Var,PrimExpr>&with substituting into aArray<Range>), which would be unexpected to new developers.This PR makes the
tir::Substituteutility more uniform in the arguments that it accepts.For any type that is supported by
tir::Substitute,Array<T>is also supported.Any variable mapping type can be used with any substitution type. All variable mapping types are normalized to
std::function<Optional<PrimExpr>(const Var&)>.For
Mapandstd::unordered_maparguments, the value type may be any subclass ofPrimExpr(e.g.Map<Var, Var>instead ofMap<Var, PrimExpr>). Previously, the calling scope needed to either construct a temporary map that returnedPrimExpr, or to use a broader value type in the map than otherwise required.The initial and primary goal was to allow a
Map<Var, Var>to be used as an argument totir::Substitute, rather than aMap<Var, PrimExpr>, and making the utility more general was more straightforward than adding multiple overloads specificall forMap<Var, Var>.