Skip to content
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

Merged
merged 3 commits into from
Oct 19, 2022

Conversation

vinx13
Copy link
Member

@vinx13 vinx13 commented Oct 14, 2022

@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 14, 2022

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

@vinx13 vinx13 force-pushed the feat/index_map_generic_dtype branch 2 times, most recently from a31ac49 to b585fb5 Compare October 14, 2022 23:36
Copy link
Contributor

@Lunderberg Lunderberg left a 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 Show resolved Hide resolved
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;
Copy link
Contributor

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 Show resolved Hide resolved
/*!
* \brief Evaluator to compute the mapped indices of a given index map.
*/
class IndexMapEvaluator : public DataTypeLegalizer {
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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.

@vinx13 vinx13 force-pushed the feat/index_map_generic_dtype branch from b585fb5 to da3dcdf Compare October 17, 2022 20:04
@vinx13 vinx13 force-pushed the feat/index_map_generic_dtype branch from da3dcdf to 5af29a6 Compare October 17, 2022 22:07
/*!
* \brief Evaluator to compute the mapped indices of a given index map.
*/
class IndexMapEvaluator : public DataTypeLegalizer {
Copy link
Contributor

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.

Copy link
Contributor

@Lunderberg Lunderberg left a 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!

@areusch areusch added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it and removed needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it labels Oct 19, 2022
@vinx13 vinx13 merged commit 458ca81 into apache:main Oct 19, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
…he#13085)

* [TIR] Allow IndexMap applied to arguments with different dtypes

* address comments

* Add SubstituteWithDataTypeLegalization
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
…he#13085)

* [TIR] Allow IndexMap applied to arguments with different dtypes

* address comments

* Add SubstituteWithDataTypeLegalization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants