-
Notifications
You must be signed in to change notification settings - Fork 445
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
Check for overflow during backend initialization (Cuda, HIP, SYCL) #6159
Conversation
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.
Please also fix the other backends that have the same code.
please make the description more descriptive |
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.
Looks OK to me.
425f765
to
9267043
Compare
Please update the title and description to describe the full scope of this pull request. |
Done 👌 |
Looks like HIP failures are unrelated. |
Retest this please |
- use correct namespace - only used overflow detection when necessary
Co-authored-by: Daniel Arndt <[email protected]>
std::size_t alloc_size; | ||
if (multiply_overflow(m_scratchFlagsCount, sizeScratchGrain, alloc_size)) { | ||
Kokkos::abort("Arithmetic overflow detected."); | ||
} |
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 don't find this code intuitive. What about we do sth like
std::size_t alloc_size = multiply_overflow(m_scratchFlagsCount, sizeScratchGrain);
and we put the Kokkos::abort
inside multiply_overflow
. The code is easier to read and we don't need to repeat the Kokkos::abort
everywhere.
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.
See ffe1120.
} else { | ||
return true; | ||
} | ||
} |
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.
Small follow up for someone: there are builtins we could use here: https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html
fixes #3805
Kokkos::abort
when an overflow is detected (which should be fine in this case since we cannot allocate that much memory anyways)