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 checks for unsafe implicit conversions in RangePolicy #6754
Add checks for unsafe implicit conversions in RangePolicy #6754
Conversation
I believe the logic isn't quite right for what it should check. I would suggest we just copy the stuff from mdspan (and backs-porting): Also the function for the representability check should only be called in debug mode maybe? |
DongHun and I met earlier today. I shared an alternative implementation https://godbolt.org/z/WEKM444n4 and we rediscovered that MDRange had kokkos/core/src/KokkosExp_MDRangePolicy.hpp Lines 74 to 87 in 4c94f08
We also discussed that C++20 has std::in_range that does pretty much what we want.
We decided to focus on making sure that we got the tests right and agreed we can refactor as needed later. |
…en deprecated code is used Modified the unit test to test warning outputs Changed implicit conversion check to be tested in debug mode only
67fcdb0
to
c8befbd
Compare
I think there may be some disparities between what the mdspan extent is requiring and what is currently accepted for indicies in For example of this case:
(in godbolt) But looking at the comment in the mdspan extent's representability check, the precondition is that an extent must be a positive integer:
So, there is an upfront check to disallow any negative extents, and because of this requirement, the rest of representability check would allow I think we would need to establish that |
DongHun is correct.
and we allow negative values in RangePolicy |
Sometimes it’s best to dismiss the reviewer’s suggestion:)
…On Thu, Feb 1, 2024 at 7:07 PM Dong Hun Lee ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In core/src/Kokkos_ExecPolicy.hpp
<#6754 (comment)>:
> : m_space(work_space),
m_begin(work_begin),
m_end(work_end),
m_granularity(0),
m_granularity_mask(0) {
+#ifdef KOKKOS_ENABLE_DEBUG
Removed this guard and in the unit test.
Also the function for the representability check should only be called in
debug mode maybe?
It was added in attempt to address this feedback.
—
Reply to this email directly, view it on GitHub
<#6754 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACIQEW2J6K7NWNWO54ZTIDYRQU3BAVCNFSM6AAAAABCNAFQS6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTQNJXHE3DSOBQGM>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
core/src/Kokkos_ExecPolicy.hpp
Outdated
#if !defined(KOKKOS_ENABLE_DEPRECATED_CODE_4) || \ | ||
defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS) |
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.
Whether or not we disable deprecation warnings shouldn't affect the interface exposed. Whether we warn or error out is determined in the implementation of check_conversion_safety
anyway and there the guards make sense.
#if !defined(KOKKOS_ENABLE_DEPRECATED_CODE_4) || \ | |
defined(KOKKOS_ENABLE_DEPRECATION_WARNINGS) | |
#ifndef KOKKOS_ENABLE_DEPRECATED_CODE_4 |
What happens if is_convertible
is false anyway? Wouldn't that already result in a compilation error? In that case, we can just enable the new interface unconditionally anyway, right?
edit: I meant always using the new interface instead of the old one.
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.
Whether or not we disable deprecation warnings shouldn't affect the interface exposed.
I agree with this statement in general. But the change you suggest would inhibit diagnosing narrowing conversions. (I am not saying we cannot come up with something else, just that the suggestion does not work.)
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.
Updated my comment.
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.
Whether we warn or error out is determined in the implementation of
check_conversion_safety
anyway and there the guards make sense.
What happens ifis_convertible
is false anyway? Wouldn't that already result in a compilation error? In that case, we can just enable the new interface unconditionally anyway, right?
Yes, since the old interface simply accepted arguments that are implicitly convertible to the member_type
, semantically it should be no different from enforcing the explicit is_convertible
check to the interface. I placed in those ifdef guards as a form of compatibility safety and mainly to follow our regular process for changing user facing interface.
But I am for using the new interface right away and leave the ifdef gurads only in check_conversion_safety
as well.
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.
Whether or not we disable deprecation warnings shouldn't affect the interface exposed.
I agree with this statement in general. But the change you suggest would inhibit diagnosing narrowing conversions. (I am not saying we cannot come up with something else, just that the suggestion does not work.)
@dalg24, any opinion on replacing the old interface with the new interface right away and leave the two ifdef guards only in check_conversion_saftey
?
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.
@dalg24, any opinion on replacing the old interface with the new interface right away and leave the two ifdef guards only in check_conversion_saftey?
OK with it.
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.
Switched to use the new interfaces and removed ifdef guards. 3065552.
Ignoring failure of one of the HIP build (machine issue) and
|
Resolves #6709
Added checks in RangePolicy to detect non value-preserving implicit conversions between input bounds and the policy's
IndexType
.Cases considered:
signed
arg type tounsigned
index typesunsigned
arg type tosigned
index types