Skip to content
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

clamp(v, lo, hi) changed slightly in C++20. Should we change as well? #6966

Open
nliber opened this issue Apr 25, 2024 · 3 comments
Open

clamp(v, lo, hi) changed slightly in C++20. Should we change as well? #6966

nliber opened this issue Apr 25, 2024 · 3 comments
Assignees

Comments

@nliber
Copy link
Contributor

nliber commented Apr 25, 2024

In C++17, clamp(v, lo, hi) uses operator< to do the comparison.

In C++20 and beyond, clamp(v, lo, hi) uses std::less{} to do the comparison. I'm not sure why it changed (I cannot find the LWG issue), but I suspect this has something to do with clamping pointers.

Should we change, and if so, should that change be dependent on the C++ version?

My answer to the above is yes and no.

@nliber nliber self-assigned this Apr 25, 2024
@masterleinad
Copy link
Contributor

masterleinad commented Apr 26, 2024

I agree. We should use std::less then if we can use it in device kernels.

@crtrott
Copy link
Member

crtrott commented Apr 26, 2024

std::less won't work on the device so we would need a Kokkos::less ...

@nliber
Copy link
Contributor Author

nliber commented May 29, 2024

std::less<void> from clang does return std::forward<_T1>(__t) < std::forward<_T2>(__u);.
std::less<void> from gcc does return _S_cmp(std::forward<_Tp>(__t), std::forward<_Up>(__u), __ptr_cmp<_Tp, _Up>{});, which basically checks to see if it is a pointer comparison, and if so, uses less<const volatile void*> to do the work, which in non constant evaluated contexts is return (__UINTPTR_TYPE__)__x < (__UINTPTR_TYPE__)__y;.

And to be consistent, we'd add all six comparator functors, both as a primary template as well as void and pointer specializations.

clang is functionally equivalent to what we do now. gcc does more work because of unusual architectures it supports, but I'm not sure that is applicable for us.

I guess I'm asking: is this worth doing (presumably following the gcc model)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants