You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I had a bug which looked like Kokkos failed to allocate an otherwise reasonable amount of space. But turned out I had actually overflowed an int variable that I was using as an extent to instantiate a kokkos view. Like the n variable below:
I wonder if you would consider adding a check for this sort of degenrate cases? Currently the size_t argument type for the extents masks this type of error. So maybe something along the line of:
// original function
void realloc(size_t n){
}
// an overload for signed types
void realloc(int n){
if(n>0) realloc(n)
}
The text was updated successfully, but these errors were encountered:
turned out I had actually overflowed an int variable
Overflow of signed integers yields undefined behavior (UB) so you would need to handle it on your side regardless of whether Kokkos::realloc can detect that a negative integer was provided as argument.
That said, I do agree that it is somewhat unfortunate that realloc takes the extents in each dimension as std::size_t and that it silently wraps around when a negative integer is passed.
The issue is well beyond realloc or resize, you get the same behavior when you construct a View with an extent passed a negative integer.
I had a bug which looked like Kokkos failed to allocate an otherwise reasonable amount of space. But turned out I had actually overflowed an
int
variable that I was using as an extent to instantiate a kokkos view. Like then
variable below:Kokkos::realloc(Kokkos::view_alloc(space, Kokkos::WithoutInitializing), v, n)
I wonder if you would consider adding a check for this sort of degenrate cases? Currently the
size_t
argument type for the extents masks this type of error. So maybe something along the line of:The text was updated successfully, but these errors were encountered: