-
Notifications
You must be signed in to change notification settings - Fork 406
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
Checked narrowing conversion in MDRangePolicy construction #3527
Conversation
@@ -162,7 +179,7 @@ struct MDRangePolicy : public Kokkos::Impl::PolicyTraits<Properties...> { | |||
enum { rank = static_cast<int>(iteration_pattern::rank) }; | |||
|
|||
using index_type = typename traits::index_type; | |||
using array_index_type = long; | |||
using array_index_type = std::int64_t; | |||
using point_type = Kokkos::Array<array_index_type, rank>; // was index_type |
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.
You may ask why didn't I change this to
using point_type = Kokkos::Array<array_index_type, rank>; // was index_type | |
using point_type = Kokkos::Array<index_type, rank>; // was index_type |
The answer is because it would potentially break user code :/
@@ -162,7 +179,7 @@ struct MDRangePolicy : public Kokkos::Impl::PolicyTraits<Properties...> { | |||
enum { rank = static_cast<int>(iteration_pattern::rank) }; | |||
|
|||
using index_type = typename traits::index_type; | |||
using array_index_type = long; | |||
using array_index_type = std::int64_t; |
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.
This change was suggested by @crtrott
It does not absolutely have to be part of this PR.
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.
Cabana was building MDRangePolicy
with arrays of long
without setting the index type on the policy.
Although this was invalid use we must recognize this change may break code downstream.
Any idea about the OpenMPTarget failure? I want to dig in on that before approving, though this looks good, I'm not sure what the bug is |
Because the error message is not detected. I wonder if it has anything to do with it being printed to the standard error. kokkos/core/src/OpenMPTarget/Kokkos_OpenMPTarget_Abort.hpp Lines 54 to 57 in 3243f20
|
Well kokkos/core/src/impl/Kokkos_Error.hpp Lines 192 to 202 in 3243f20
|
e7ec914
to
569d93a
Compare
(std::is_signed<To>::value != std::is_signed<From>::value); | ||
auto const ret = static_cast<To>(arg); | ||
if (static_cast<From>(ret) != arg || | ||
(is_different_signedness && (arg < From{}) != (ret < To{}))) { |
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.
It should be enough to check that both of them are positive, shouldn't it? If one of the types is unsigned, values of that type cannot be negative anyway.
// NOTE prefer C array U[M] to std::initalizer_list<U> so that the number of | ||
// elements can be deduced (https://stackoverflow.com/q/40241370) | ||
template <class Array, class U, std::size_t M> | ||
// NOTE for some unfortunate reason the policy bounds are stored as signed |
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.
This note needs to be expanded upon. The problem isn't just signed vs. unsigned numbers, it is really because there are possibly three separate element types involved, one of which may have a different sign than the others: IndexType
, Array::value_type
and U
.
Even after reading the note, it was not obvious why IndexType
is here at all, or why we cannot convert to an array of IndexType
here.
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.
Done
Because it turns out that Array uses long...
569d93a
to
b212d46
Compare
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.
The conversion works (assuming the size of the resulting array is large enough, which should be checked), but it is hard to follow because of the non-local nature of the IndexType
check.
…entially_narrowing
Retest this please |
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.
Putting a hold on it: wasn't there some convention regarding death test naming we tried to follow? I thought we had some issues with death tests on various platforms and want an easy way to exclude death tests.
Good catch. Fixed. |
Fix #3524