Skip to content

Conversation

FractalFir
Copy link
Collaborator

Currently, we replace unsupported fptoui_sat with fptoui. 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.)

@FractalFir FractalFir requested a review from LegNeato October 3, 2025 22:10
Copy link
Contributor

@LegNeato LegNeato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🍻

@FractalFir FractalFir merged commit e6e046d into Rust-GPU:main Oct 5, 2025
12 checks passed
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

Successfully merging this pull request may close these issues.

2 participants