-
Notifications
You must be signed in to change notification settings - Fork 917
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
[FEA] Consider disabling --expt-relaxed-constexpr
#7795
Comments
@karthikeyann please be aware of this with respect to #7713 |
No, we should prefer |
This was implied. The whole point of |
I want to be very explicit because it is not obvious to everyone (a fact that is evident in our code). |
This issue has been labeled |
Still valid |
This seems to be unblocked with the recent CCCL update. The changes in NVIDIA cuCollections PR #595 show that cuco can now build and run properly without relaxed constexprs. |
Previously, calling `narrow<>()` from CUDA device code should have resulted in a compile error but but did not due to a weird bug in NVCC pertaining to the experimental "--expt-relaxed-constexpr" flag: rapidsai/cudf#7795 This commit makes two changes to mitigate this problem: (1) `narrow<>()` no longer responds to `gsl_CONFIG_CONTRACT_VIOLATION_THROWS` because it does not do contract checking. Therefore, it plainly fails to compile for `gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION )` if exceptions are unavailable (e.g. in device code). (2) For `!gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION )`, `narrow<>()` now makes sure that the program is terminated by issuing a trap instruction if `std::terminate()` is not available.
* Do not call `std::terminate()` in CUDA device code Previously, calling `narrow<>()` from CUDA device code should have resulted in a compile error but but did not due to a weird bug in NVCC pertaining to the experimental "--expt-relaxed-constexpr" flag: rapidsai/cudf#7795 This commit makes two changes to mitigate this problem: (1) `narrow<>()` no longer responds to `gsl_CONFIG_CONTRACT_VIOLATION_THROWS` because it does not do contract checking. Therefore, it plainly fails to compile for `gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION )` if exceptions are unavailable (e.g. in device code). (2) For `!gsl_CONFIG( NARROW_THROWS_ON_TRUNCATION )`, `narrow<>()` now makes sure that the program is terminated by issuing a trap instruction if `std::terminate()` is not available. Some drive-by changes: * Update Xcode toolset versions [ci skip] * Update CI configuration, add newer compilers * Remove GCC 10 from macOS test suite Results in weird errors in libunwind ("_Unwind_GetTextRelBase - _Unwind_GetTextRelBase() not implemented") which I have no interest in tracking down.
NVIDIA/cuCollections#595 and rapidsai/cuspatial#1494 inspired me to look into this again. It's slow going (but low effort) to investigate, so I'll report back when I get compilation far enough to make a determination on whether removing this setting will be possible in cudf. I've run into one very odd case that seemed like a compiler bug, but other than that it seems largely like a lot of tedious but not difficult work. |
Contributes to #7795. Also contributes to rapidsai/build-planning#76. Authors: - Vyas Ramasubramani (https://github.com/vyasr) Approvers: - Nghia Truong (https://github.com/ttnghia) - Yunsong Wang (https://github.com/PointKernel) - Bradley Dice (https://github.com/bdice) - David Wendt (https://github.com/davidwendt) URL: #17545
Contributes to #7795 This PR updates `text` to build without depending on the relaxed constexpr build option. Authors: - Yunsong Wang (https://github.com/PointKernel) Approvers: - Basit Ayantunde (https://github.com/lamarrr) - Bradley Dice (https://github.com/bdice) - David Wendt (https://github.com/davidwendt) URL: #17647
Contributes to #7795 This PR updates `binaryop` to build without depending on the relaxed constexpr build option. Authors: - Yunsong Wang (https://github.com/PointKernel) Approvers: - David Wendt (https://github.com/davidwendt) - Vukasin Milovanovic (https://github.com/vuule) URL: #17598
Is your feature request related to a problem? Please describe.
--expt-relaxed-constexpr
is a convenient way to reuse existingconstexpr
host code, e.g., things likestd::max
.However, it can lead to some pretty surprising behavior. Consider:
https://godbolt.org/z/frb8c6cd7
One might expect this to fail to compile as
throw
is not valid in device code. However, not only does it happily compile, but it just stores the value 42.This example looks pretty harmless:
But this too results in an ill-formed program without a diagnostic.
https://godbolt.org/z/aTzGaMrGd
Describe the solution you'd like
We should think pretty hard about if we want to risk such egregious undefined behavior in libcudf.
As such, we may want to consider moving towards disabling
--expt-relaxed-constexpr
. At the very least, we should be preferringCUDA_HOST_DEVICE_CALLABLE
whenever possible (for functions that need be called from both host and device).Additional Context
The only place it is 100% safe to use a
constexpr
function in device code with--expt-relaxed-constexpr
is when used in a context that requires constant evaluation. Then it will fail to compile if theconstexpr
function contains things that would result in an ill-formed program: https://godbolt.org/z/47qfnPnc9The text was updated successfully, but these errors were encountered: