-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[ir] [transforms] Added assertion that indices won't cause overflow under debug mode #2199
Conversation
…rflow under debug mode. Fixed one typo in write_test docs.
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.
Thanks for the fix!
taichi/transforms/simplify.cpp
Outdated
auto zero = Stmt::make<ConstStmt>(LaneAttribute<TypedConstant>(0)); | ||
auto check_sum = Stmt::make<BinaryOpStmt>(BinaryOpType::cmp_ge, sum.get(), zero.get()); | ||
auto assert = Stmt::make<AssertStmt>(check_sum.get(), "The indices provided are too big!", std::vector<Stmt *>()); | ||
auto select = Stmt::make<TernaryOpStmt>(TernaryOpType::select, check_sum.get(), sum.get(), zero.get()); |
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.
Let's add this comment to explain why we need select
:
Because Taichi's assertion is checked only after the execution of the whole kernel, when the linear index overflows and goes negative, we have to replace that with 0 to make sure that the rest of the kernel can still complete. Otherwise, Taichi would crash due to the illegal memory address.
Co-authored-by: Ye Kuang <k-ye@users.noreply.github.com>
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.
LGTM
Related issue = #2146
With large indices such as variable[300][300][300][300], when performing IR transform and simplifying this to an integer, this integer will overflow to negative number, which would cause SegFault. I added assertion to IR under debug mode which would assert that the simplified index must NOT be less than 0. One test is provided named "test_indices_assert.py".
For modification in docs, there is one typo that added an 's' after 'exclude'. I simply deleted this 's'.
@k-ye
[Click here for the format server]