Repository navigation
feat(fuzzer): trace f32 and f64 values - #484
Merged
nihalpasham merged 2 commits intoJul 27, 2026
Merged
Conversation
The trace API had a writer for every integer type plus bool and char and
none for floats, so the adapter refused any seed whose dumped value or
return type was a float:
seed 221: UNSUPPORTED [adapter] unsupported return type for
return-value tracing: f32
That left float codegen outside the differential comparison, reachable
only where a float happened to pass through an as cast, a comparison
yielding bool, or transmute_place.
Fold floats as their to_bits() pattern, so the trace stays exact u64
hash equality. A tolerance in the trace would compare something other
than the value a backend produced, and would hide the differences the
fuzzer exists to find.
Pass --no-fmad when running a seed. Device codegen contracts an fmul
feeding an fadd into a single fma.rn by default, matching nvcc's
--fmad=true, while the CPU oracle rounds the multiply and the add
separately. Both are correct, so the resulting difference reports
nothing about a miscompile and would mask the differences that do.
Add f32 and f64 literals for generated function arguments, chosen to be
exactly representable so a seed starts from the value it was given.
Update the README's type list, which no longer excludes floats, and
record why contraction is disabled. The libdevice triage guidance stands
unchanged: transcendentals are still not required to be bit-identical to
the host's libm, and direct float dumps widen the exposure to that, so a
mismatch on a libdevice seed still needs checking in ULPs by hand.
Signed-off-by: Alejandro Soto Franco <[email protected]>
Rust does not pin down NaN payload bits, so a CPU and a GPU can legitimately produce different payloads for the same NaN-producing operation. Hashing raw float bits would then report a false MISMATCH while the writer's doc comment claimed bit-for-bit agreement always holds. Canonicalize every NaN to the quiet-NaN bit pattern (f32::NAN / f64::NAN to_bits) before folding it into the trace, matching Cranelift's fuzzgen practice. Non-NaN values still compare exactly, and a NaN against a non-NaN still hashes differently, so the real signal survives while payload divergence cannot fire. The CPU oracle and the GPU run link the same trace writers, so the canonicalization applies to both sides symmetrically. Update the writer doc comment and the README triage guidance accordingly. Signed-off-by: nihalpasham <[email protected]>
Collaborator
|
Thanks, Gist: FMA analysis is correct and routing it through the existing I pushed one commit -
Verified on an RTX 5090: seeds 200 through 299 pass, and seed 162 passes both with and without Merging. |
nihalpasham
approved these changes
Jul 27, 2026
nihalpasham
added a commit
that referenced
this pull request
Aug 20, 2026
…t accepts (#1069) * docs(book): the fuzzing chapter says the adapter rejects five types it accepts `fuzzing-and-differential-testing.md` documents the trace API's type support as nine scalars and then rules out five more: Today the trace supports: bool, i8, i16, i32, i64, u8, u16, u32, u64 It does not yet support `u128`, `i128`, `usize`, `isize`, or `char`. `SCALAR_TRACE_TYPES` in `crates/fuzzer/tools/mir_generator.py` holds sixteen, including all five of those plus `f32` and `f64`, and `supported_trace_type` gates the adapter on exactly that set. Executing the real predicate: u128 True i128 True usize True isize True char True f32 True f64 True [u128; 4] True (u32, char) True *const i8 False &i32 False (i8,i8,i8,i8,i8,i8) False So the paragraph is wrong about every type it names, and understates the rest: support is not set membership but a recursive question, because an array or tuple folds by its leaves up to arity 5 ([#792](#792)) -- and `f32`/`f64` have been in since [#484](#484). `crates/fuzzer/README.md` already states all of this correctly, listing the same sixteen scalars and the folding rule. The book page is the one outlier, so this brings it in line with the README and the code rather than inventing a third description. Two consequences follow: - The sample `UNSUPPORTED [adapter]` line used `u128` as its rejected type, which the adapter now accepts, so the example cannot be produced. It becomes `*const i8`, which the predicate does reject (measured above) and which the fuzzer README already uses as its own example of an adapter refusal. - The widening plan listed "Add trace support for more scalar types (`u128`, `i128`, `usize`, `isize`)" and "Add arrays, tuples, and eventually structs/enums" as future work. The first is done and the second is half done, so the plan now records what landed and keeps structs and enums as what remains. Left alone deliberately: the `RigidTy(Char)` backend classification in the same sample output. `char` behaviour is in flux -- translation maps it to `u32`, and whether `#[device]` extern signatures accept it is an open question ([#875](#875)) -- and I did not reproduce that line end to end, so it is not mine to rewrite here. Verified: the predicate results above come from importing `mir_generator.py` and calling `supported_trace_type`, not from reading it. Book builds clean under `sphinx-build -W`; `check-book-api-names.sh` passes. Signed-off-by: Vyncint Ng <[email protected]> * docs(book): fix the pointer refusal example and plain-language pass on the folding text --------- Signed-off-by: Vyncint Ng <[email protected]> Co-authored-by: nihalpasham <[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.
Summary
The trace API had a writer for every integer type plus
boolandchar, and none for floats, so the adapter refused any seed whose dumped value or return type was a float:Float codegen therefore sat outside the differential comparison. A float reached the hash only where it happened to pass through an
ascast, a comparison yieldingbool, ortransmute_place, which is a thin and accidental sample of a large part of the backend.Changes
f32andf64to the trace API, folded as theirto_bits()pattern.--no-fmadwhen running a seed.Rationale
Floats are hashed as bit patterns so the trace stays exact
u64equality. A tolerance inside the trace would compare something other than the value a backend produced, and would hide the differences the fuzzer exists to find. The consequence is that every NaN the two backends produce must agree bit for bit, payload included. That holds for the arithmetic rustlantis emits, and a disagreement in a NaN payload is a result worth reporting on its own.--no-fmadis the part worth arguing about. Device codegen setscontracton float arithmetic by default, so the NVPTX backend fuses anfmulfeeding anfaddinto onefma.rn, matching nvcc's--fmad=true. The CPU oracle rounds the multiply and the add separately. Both results are correct, so the difference reports nothing about a miscompile, and once it appears in the hash it would mask the differences that do. Disabling contraction for the fuzzer keeps the oracle and the device comparable. Contraction is worth fuzzing separately, against a contracted reference.This does widen exposure to the libdevice hazard the README already documents. Previously a float influenced the hash only indirectly; now it is hashed directly, so a seed calling a transcendental is more likely to produce a difference that is within the tolerance libdevice is permitted. That triage guidance is unchanged and still applies: check whether the differing value derives from a transcendental and compare in ULPs before treating a mismatch as a miscompile. The alternative, keeping floats out of the trace to avoid it, is what left this coverage gap.
Validation
Ran on an RTX 5060 Laptop GPU (sm_120a, CUDA 13.1,
nightly-2026-04-03).Seed 221, the case that motivated this:
Seeds 200 to 239 with this change:
The single failure is seed 212, a
SwitchIntvalue aboveu64::MAX, which is unrelated to this change and is fixed separately.A further 70 seeds, 230 to 299, ran green while checking the contraction question. No float seed in either range produced a mismatch.
The checked-in seed 162 regression case still passes:
cargo oxide run <example>passes (rustlantis-smoke)cargo test --workspacepassesNo example added:
rustlantis-smokeis the harness this changes, and it already carries the checked-in seed.Checklist
git commit -s)