Skip to content

feat(fuzzer): trace f32 and f64 values - #484

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
alejandro-soto-franco:feat/fuzzer-float-tracing
Jul 27, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
alejandro-soto-franco:feat/fuzzer-float-tracing

Conversation

@alejandro-soto-franco

Copy link
Copy Markdown
Contributor

Summary

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

Float codegen therefore sat outside the differential comparison. A float reached the hash only where it happened to pass through an as cast, a comparison yielding bool, or transmute_place, which is a thin and accidental sample of a large part of the backend.

Changes

  • Add f32 and f64 to the trace API, folded as their to_bits() pattern.
  • Accept both in the adapter's supported-type set, and add literals for them so a generated function can take float arguments. The literals are exactly representable in binary floating point, so a seed starts from the value it was given.
  • Pass --no-fmad when running a seed.
  • Update the README's type list and record why contraction is disabled.

Rationale

Floats are hashed as bit patterns so the trace stays exact u64 equality. 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-fmad is the part worth arguing about. Device codegen sets contract on float arithmetic by default, so the NVPTX backend fuses an fmul feeding an fadd into one fma.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:

before: seed 221: UNSUPPORTED [adapter] unsupported return type for return-value tracing: f32
after:  seed 221: PASS [run] CPU/GPU traces matched

Seeds 200 to 239 with this change:

summary: COMPILE_FAIL=1, PASS=39

The single failure is seed 212, a SwitchInt value above u64::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 --no-fmad rustlantis-smoke
Stage 1b CPU hash: ...  Stage 1b GPU hash: ...
PASS: CPU/GPU traces match
$ cargo clippy --workspace -- -D warnings
$ cargo fmt --all -- --check
$ cargo check --workspace --all-targets
$ python3 -m py_compile crates/fuzzer/tools/mir_generator.py crates/fuzzer/tools/run_seed.py
(all clean)
  • cargo oxide run <example> passes (rustlantis-smoke)
  • cargo test --workspace passes
  • New example added (if applicable)

No example added: rustlantis-smoke is the harness this changes, and it already carries the checked-in seed.

Checklist

  • All commits signed off (git commit -s)
  • SPDX headers on new source files (no new files)

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]>
@nihalpasham nihalpasham added enhancement New feature or request codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Jul 27, 2026
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]>
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks,

Gist: FMA analysis is correct and routing it through the existing --no-fmad flag instead of a tolerance keeps the oracle bit-exact.

I pushed one commit -

  • canonicalizing NaN bits in the two writers before hashing (Cranelift-fuzzgen practice): raw payload bits could produce false MISMATCH verdicts that the doc comment promised could not happen, and
  • the README triage guidance now matches.

Verified on an RTX 5090: seeds 200 through 299 pass, and seed 162 passes both with and without --no-fmad.

Merging.

@nihalpasham
nihalpasham merged commit 5b98fc5 into NVIDIA:main Jul 27, 2026
33 checks passed
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]>
@alejandro-soto-franco
alejandro-soto-franco deleted the feat/fuzzer-float-tracing branch September 9, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants