Repository navigation
fix(intrinsics): lower fast float ops - #187
Merged
nihalpasham merged 2 commits intoJun 16, 2026
Merged
Conversation
Signed-off-by: nik <[email protected]>
The fast-float intrinsic lowering set FastmathFlags::FAST on the llvm
float binops, but the textual exporter never read the attribute, so the
flags were dropped at .ll emission and the fast-math contract was inert
end to end. Read the fast-math attribute in export_binop and print the
matching LLVM keywords (the all-bits set as the 'fast' shorthand, any
subset as individual keywords) between the opcode and the type.
This is a no-op for integer binops (no attribute) and for float ops
lowered from ordinary Rust arithmetic (empty flags), so existing IR is
unchanged; it only fires for the f*_fast intrinsics. Verified end to end:
a kernel calling core::intrinsics::f{add,sub,mul,div,rem}_fast on f32 and
f64 now exports 'f.. fast float'/'f.. fast double', while vecadd's plain
'fadd float' is unchanged. Adds a focused export regression test.
nihalpasham
force-pushed
the
prepare-fast-float-intrinsics
branch
from
June 16, 2026 06:20
563f12a to
71680ac
Compare
Collaborator
|
Lowers the One gap: the textual exporter was dropping the fast-math flags, so they never reached the PTX (the optimization was inert).
|
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
Transitive dependency (rayon via candle/criterion/gemm). Affected versions dereference the underlying pointer in the fmt::Pointer impl for Atomic and Shared even when it is invalid (e.g. Atomic::null). Lockfile-only change; cargo deny check advisories passes. Signed-off-by: Melih Elibol <[email protected]>
meefs
pushed a commit
to meefs/cuda-oxide
that referenced
this pull request
Sep 30, 2026
…NVIDIA#225, NVIDIA#185) (NVIDIA#256) Three squash merges landed from branches that had resolved a merge against main by keeping pre-merge copies of files, so each one quietly reverted an earlier, unrelated merge: - NVIDIA#239 (2482cb9) reverted NVIDIA#240 (1216aef): the const raw-pointer surface (as_ptr, program_id/num_programs, the cast_* and get_tensor_base helpers, unsafe on load_ptr_tko/store_ptr_tko), the compiler's const-pointer typing, the two GPU test files and the matching book and tutorial text. - NVIDIA#247 (5f5f4c5) reverted NVIDIA#225 (a2843e7): integer division and remainder serialization (rounding<zero> and inferred signedness on divi/remi) and its test. - NVIDIA#187 (35a9cc2) reverted NVIDIA#185 (cbf52c0): the flake.nix toolkit-assembly hardening and host-arch driver directory derivation. This re-applies all three verbatim as cherry-picks. The only overlapping file, cutile-book/guide/performance.md, merges cleanly with NVIDIA#239's own edits. A per-file scan of the last 60 merges finds no other reversal still missing at HEAD: NVIDIA#249's removal of the About page was deliberate, and the two setup-python flips in .github/workflows/pages.yml were re-applied by the later dependabot bump. Verified: cargo fmt, cargo build, and the restored GPU tests (const_pointers, program_id) plus integer_ops, memory_and_atomic_ops and optimization_hints pass on an RTX 5090 with CUDA 13.3. Signed-off-by: Melih Elibol <[email protected]> Co-authored-by: Gabriel Wu <[email protected]>
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.
Closes #186.
Related: #62, #142, #148, #161.
Problem
core::intrinsics::{fadd_fast,fsub_fast,fmul_fast,fdiv_fast,frem_fast}are generic compiler intrinsics with no MIR body. When the importer leaves them as ordinary calls, unresolved cuda-oxide placeholder callees can survive into LLVM lowering and fail verification or symbol resolution.The initial lowering used
FastmathFlagsAttr::default()while claiming to emit fast-math binops. In pliron-llvm,FastmathFlagsAttr::default()isFastmathFlags::empty(), so that did not express Rust's finite/non-NaNf*_fastcontract.Fix
The importer recognizes the
core::intrinsicsandstd::intrinsicsspellings for all fivef*_fastoperations and emits the same centralized Rust-intrinsic placeholder calls as the other target-specific Rust intrinsics.mir-lowernow routes those placeholders before the libdevice path and replaces them with the matching LLVM float binop:llvm.fadd,llvm.fsub,llvm.fmul,llvm.fdiv, orllvm.frem. The fast-intrinsic path usesFastmathFlags::FAST.into()explicitly instead of the empty default.Diligence
Sibling float intrinsic paths checked:
core::intrinsicsmath such assqrtf32,powif64,fmaf32,round_ties_even_f64,maximum_number_nsz_f32, andcbrtf32;std::intrinsicsaliases for the same fixed-width math intrinsics;libmpath matching, including re-exported names such aslibm::sqrtfand nested names such aslibm::math::sqrt::sqrtf;std::sys::cmathnames foratan,atan2, andcbrt;f*_fastintrinsics;fcmplowering, whose regression coverage depends on empty fast-math flags so NaN checks do not become poison.The generic
f*_fastoperations are the only sibling path with no type suffix and no libdevice entry point, so they are routed to LLVM binops rather than the libdevice declaration/call path.Tests
Added a focused
mir-lowerregression that constructs placeholder calls for all fivef*_fastintrinsics for bothf32andf64. The test asserts:FastmathFlagsAttr::default()is distinct from explicitFastmathFlags::FAST;f32andf64monomorphizations are covered for every operation;fastflags;mir.callor placeholder-named LLVM call survives.Validation
Targeted local validation:
cargo test -p mir-lower test_fast_float_intrinsics_lower_to_explicit_fast_binops