-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[TIR] Allow IndexMap applied to arguments with different dtypes #13085
Conversation
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 |
a31ac49
to
b585fb5
Compare
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.
I like it overall! I have a couple of nitpicks, and a question on whether the IndexMapEvaluator
should be instead an optional feature of tvm::tir::Substitute
, but overall I like it!
src/tir/ir/index_map.cc
Outdated
for (int i = 0; i < static_cast<int>(arguments.size()); ++i) { | ||
var_map_.Set(index_map_->initial_indices[i], arguments[i]); | ||
} | ||
Array<PrimExpr> result = index_map_->final_indices; |
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.
Can use Array::Map
instead of making a copy that is then mutated.
return index_map_->final_indices.Map(...);
src/tir/ir/index_map.cc
Outdated
/*! | ||
* \brief Evaluator to compute the mapped indices of a given index map. | ||
*/ | ||
class IndexMapEvaluator : public DataTypeLegalizer { |
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.
Should this be part of a more general utility overall? It looks like this is effectively a variation of tvm::tir::Substitute
that allows the substituted values to have a different datatype than the replaced var's type. Rather than having a utility that is specific to IndexMap
, should this functionality be an option when calling Substitute
?
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.
It inherits from DataTypeLegalizer
that contains extra logic than StmtMutator
, I think it's better to be separated from IRSubstitute
. Perhaps we can introduce another utility function SubstituteWithDataTypePromotion
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.
Hmm, good point. I had been thinking that the DataTypeLegalizer
would have the necessary follow-up steps that should be performed after every substitution in order to have valid TIR, rather having extra logic as well. Since there is extra logic, that would make sense to me to have the separate SubstituteWithDataTypeLegalization
.
b585fb5
to
da3dcdf
Compare
da3dcdf
to
5af29a6
Compare
src/tir/ir/index_map.cc
Outdated
/*! | ||
* \brief Evaluator to compute the mapped indices of a given index map. | ||
*/ | ||
class IndexMapEvaluator : public DataTypeLegalizer { |
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.
Hmm, good point. I had been thinking that the DataTypeLegalizer
would have the necessary follow-up steps that should be performed after every substitution in order to have valid TIR, rather having extra logic as well. Since there is extra logic, that would make sense to me to have the separate SubstituteWithDataTypeLegalization
.
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.
Thank you for splitting out the utility function, and LGTM!
…he#13085) * [TIR] Allow IndexMap applied to arguments with different dtypes * address comments * Add SubstituteWithDataTypeLegalization
…he#13085) * [TIR] Allow IndexMap applied to arguments with different dtypes * address comments * Add SubstituteWithDataTypeLegalization
cc @Lunderberg @Hzfengsy