Repository navigation
fix(cuda-oxide): lower core::intrinsics::float_to_int_unchecked - #1654
Open
veljjanoski wants to merge 1 commit into
Open
veljjanoski wants to merge 1 commit into
veljjanoski wants to merge 1 commit into
Conversation
Signed-off-by: Daniel Veljjanoski <danielveljanoski@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
f32::to_int_uncheckedandf64::to_int_uncheckedcallcore::intrinsics::float_to_int_unchecked. The importer had no handler for that intrinsic, so a kernel using either failed with "invalid input program" (#1595). This adds it the same way #473 addedexact_div, and lowers it to a plainfptosi/fptoui. The caller promises the value is finite and in range, so the clamping and NaN handling of the saturatingascast are not needed. rustc's LLVM backend emits the same instructions.Fixes #1595.
Changes
dialect-mir: newCALLEE_FLOAT_TO_INT_UNCHECKEDplaceholder, registered as a known placeholder that never needs libdevice.mir-importer: newintrinsics::float_to_intmodule and its terminator dispatch.mir-lower: the placeholder lowers tollvm.fptosiorllvm.fptoui. Signedness comes from the MIR result type, as in the saturating cast. Other sources (f16,f128) and destinations wider than 64 bits get a clear error, matching what the saturating cast supports on both intrinsic backends.fptosi/fptouiand no remaining call. A second test checks that ani128destination is rejected.float_to_int_uncheckedcovering f32→i32, f32→u32, f64→i64 and f64→u64. Each kernel gets inputs that only the right instruction converts correctly: negative values for the signed kernels, values above the signed maximum for the unsigned ones. ItsCargo.lockis copied fromexact_div_chunks, which has the same dependencies, so the example pins match.Testing
Run on an RTX 3090 (sm_86), CUDA 13.3, WSL2 Ubuntu 24.04, Rust 1.99.1.
Before the change, on
main(9df9e7c):After:
PTX for
f32_to_i32, withx[i] as i32compared tox[i].to_int_unchecked::<i32>():Across the four kernels, the
asversion adds 10 float compares and 10 selects. Theto_int_uncheckedversion has neither; its only selects are the 4 from the index checks, which both versions share.just -f cuda-oxide/Justfile checkpasses (the local mirror of CI: fmt, clippy, tests, guards, docs)cargo oxide run <example>passes, orcuda-oxide/scripts/smoketest.sh -o '^<example>$'Also run:
cargo clippy --locked --all-targets -- -D warningsin the example, andscripts/sync-example-locks.sh --check.Checklist
git commit -s)AI-usage disclosure: Claude (Anthropic) was used as assistant.