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
Add overflow check for stride calculation #94900
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/94900
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit dca992e: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
c10/core/TensorImpl.h
Outdated
overflowed |= c10::mul_overflows(sizes_and_strides_.stride_at_unchecked(i + 1), std::max<int64_t>( | ||
sizes_and_strides_.size_at_unchecked(i + 1), 1), std::addressof(sizes_and_strides_.stride_at_unchecked(i))); | ||
TORCH_CHECK(!overflowed, | ||
"Stride calculation overflowed with stride of dim", i); |
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.
Is it better to test this only once outside of the loop?
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.
Yes. Moved it outside the loop.
f52b910
to
93b6092
Compare
waiting for you to un-draft this |
#if C10_HAS_BUILTIN_OVERFLOW() | ||
return __builtin_mul_overflow(a, b, out); | ||
#else | ||
volatile int64_t tmp = a * b; |
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.
May I know why you make it volatile
?
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.
Because compiler might optimize/omit it.
@pytorchbot merge |
Merge failedReason: This PR needs a label If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Fixes pytorch#94120 and pytorch#94128. Pull Request resolved: pytorch#94900 Approved by: https://github.com/ezyang, https://github.com/jgong5
Fixes #94120 and #94128. Pull Request resolved: #94900 Approved by: https://github.com/ezyang, https://github.com/jgong5
Fixes #94120 and #94128.