Replace incorrect, UB-prone fptoui_sat with a corret implementation. #287
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, we replace unsupported
fptoui_sat
withfptoui
. This is incorrect(fptoui
is wrapping, not saturating in CUDA) and UB-prone(casting values out of range is UB).fptoui_sat
can be correctly emulated at the cost of 2 additional PTX instructions(max & min).This PR implements such emulation, removing another source of UB in Rust-CUDA.
(Equivalent, but slightly more complex approach can be applied to
fptosi_sat
. I will implement that in a separate PR. After we fix that too, we can disable-Z saturating_float_casts=false
, and remove that kind of UB fully.)