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][Fix] IndexDataTypeNormalizer not unwrapping float casting #13789

Merged

Conversation

MasterJH5574
Copy link
Contributor

This PR fixes a bug of IndexDataTypeNormalizer that is used by CreatePrimFunc.

#13449 enhanced the normalizer by unwrapping unnecessary casts, by the rule that “if the value to be casted already has the target index dtype`, the cast will be omitted. However, there are cases where a cast here is for other purpose. Like in image resize operators, there are sometimes rounding operation for indices, like

 T.Cast("int64", T.round(T.float32(128) / T.Cast("float32", oh) * T.Cast("float32", v_i2), dtype="float32"))

is used as a final index. Note that this PrimExpr contains casts that directly operated on indices, such as T.Cast("float32", oh). This cast is for division purpose, in order to have floating point division result. As a result, it is not expected to unwrap such casts, while the previous implementation did remove the casts.

Therefore, this PR patches this issue by only unwrapping the casts whose target dtype is integer dtype.

cc @vinx13 @tqchen

@tvm-bot
Copy link
Collaborator

tvm-bot commented Jan 15, 2023

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

@MasterJH5574
Copy link
Contributor Author

Depends on #13788

@github-actions github-actions bot requested review from tqchen and vinx13 January 15, 2023 20:20
@MasterJH5574 MasterJH5574 force-pushed the tvm-dev/2023-01-15-datatype-normalizer branch from b45d704 to bf9ddb3 Compare January 15, 2023 20:27
Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Same here that you might want to revert the change to 3rdparty/cutlass

@MasterJH5574 MasterJH5574 force-pushed the tvm-dev/2023-01-15-datatype-normalizer branch from bf9ddb3 to 54b0fba Compare January 16, 2023 01:15
@junrushao junrushao changed the title [Fix] IndexDataTypeNormalizer not unwrapping float casting [TIR][Fix] IndexDataTypeNormalizer not unwrapping float casting Jan 16, 2023
@tqchen tqchen merged commit a530df8 into apache:main Jan 16, 2023
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.

4 participants