Skip to content

feat(fuzzer): fold an aggregate into the trace by its leaves - #792

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
alejandro-soto-franco:feat/fuzzer-trace-aggregates
Aug 11, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
alejandro-soto-franco:feat/fuzzer-trace-aggregates

Conversation

@alejandro-soto-franco

Copy link
Copy Markdown
Contributor

Closes #791.

The trace API hashed 16 scalar types and nothing else, so a generated program whose dump site or return position held a tuple or an array was refused at the adapter with unsupported dumped type. That was 18 of the 60 seeds in the window the README quotes, and 320 of the 1000 seeds in the sweep that found #765 and #767.

Summary

Folds an aggregate into the trace as its leaves, in declaration order, so TraceValue covers arrays and tuples of anything it already covered, to any nesting depth.

Changes

  • crates/fuzzer/src/trace.rs: TraceValue for [T; N] over a const generic, for tuples up to arity 5, and for (). Each walks its leaves through the existing scalar writers.
  • crates/fuzzer/src/lib.rs: #![cfg_attr(not(test), no_std)], so a test build links std on the host while every real build, the device build included, stays no_std.
  • crates/fuzzer/tools/mir_generator.py: supported_trace_type becomes a recursive question over [T; N] and tuples rather than a set membership test. It governs both existing call sites, the dumped locals and the return type.
  • crates/fuzzer/README.md: refreshes the status transcripts and the supported-type list, which this change makes stale.

Rationale

The byte sequence an aggregate produces is exactly the one a scalar-by-scalar dump of the same leaves produces, so this widens what the trace accepts without introducing a second trace model. Nothing that hashed before hashes differently.

The fold reads leaves and never the aggregate's bytes. Padding is uninitialised, so folding raw bytes would be undefined behaviour in the CPU oracle, and any layout the two backends pad differently would report a MISMATCH on every seed that touched it. Padding is also where the silent miscompile behind #393 lived, so a byte fold would bury the signal this fuzzer exists to find. (u8, u32) is the discriminating case in the test: it holds only for an implementation that reads the two fields.

The array walk is an indexed while rather than a for over the array's IntoIterator. This crate is compiled for the device as well as the host, and #399 records that small local arrays consumed through iterator adapters stay in local memory. An index loop states the same thing without depending on how that resolves.

The tuple arity stops at 5 because TraceDump stops at 5, and the adapter refuses a wider one rather than emitting a program that fails to compile. Every assertion lives in one test function, because the trace is a single static mut and cargo runs test functions on parallel threads, so two folds at once would race on it.

Validation

RTX 5060 Laptop GPU, compute capability 12.0, CUDA 13.3, driver 610.43.03.

Seeds 300-359, the window the README quotes, changing only the trace API and the adapter:

before:  PASS=42  UNSUPPORTED=18
after:   PASS=60  UNSUPPORTED=0

Every refused seed became an executing differential run, and none of them mismatched. Seeds 0-99 are also 100 PASS with nothing refused.

Seeds 1000-1999, the window that produced #765 and #767:

PASS=999  UNSUPPORTED=1  COMPILE_FAIL=0  MISMATCH=0

The recorded figure for that window on 2026-08-09 was PASS=673 UNSUPPORTED=320 COMPILE_FAIL=7. The seven compile failures are gone because #769 landed, and that run predates this branch, so it is a recorded baseline rather than a paired arm.

No mismatch, so this widening surfaced no new silent miscompile in that window. What it did was put 319 more programs through the device where the harness previously refused to look at them.

The one remaining refusal is seed 1436, which returns a *const i8:

UNSUPPORTED [adapter] unsupported return type for return-value tracing: *const i8

That one is permanent rather than a gap to widen next. The CPU oracle and the device hold different addresses for the same object by construction, so folding a pointer into the trace would report a MISMATCH on every seed that dumped one.

The unit test discriminates. Reversing the array walk, so that it folds [1, 2, 3, 4] as 4, 3, 2, 1, fails the first assertion and leaves the rest of the file passing.

cargo test -p fuzzer                    1 passed, 0 failed
cargo clippy -p fuzzer --all-targets    clean
cargo fmt --check -p fuzzer             clean

The trace API hashed 16 scalar types and nothing else, so a generated program
whose dump site or return position held a tuple or an array was refused at the
adapter. That was 18 of the 60 seeds in the window the README quotes, and 320
of the 1000 seeds in the sweep that produced NVIDIA#765 and NVIDIA#767.

TraceValue now covers arrays and tuples of anything it already covered, to any
nesting depth, folding each leaf through the existing scalar writers. The byte
sequence an aggregate produces is the one a scalar-by-scalar dump of the same
leaves produces, so nothing that hashed before hashes differently.

The fold reads leaves and never the aggregate's bytes. Padding is
uninitialized, so folding raw bytes would be undefined behavior in the CPU
oracle and would report a MISMATCH on any layout the two backends pad
differently. Padding is also where the miscompile behind NVIDIA#393 lived.
@nihalpasham nihalpasham added enhancement New feature or request fuzzer Fuzzing infrastructure (rustlantis, difftest) labels Aug 11, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Reproduced on RTX 5090 (sm_120):

  • seeds 300-359: PASS=60 / UNSUPPORTED=0, against 42/18 on unpatched main;
  • seeds 1000-1099 spot check: PASS=100 / UNSUPPORTED=0; tests, clippy, and fmt all clean.

The leaf-walk impls and the recursive Python gate accept and refuse identical types on every edge case we threw at them (1-tuples, nested units, zero-length arrays, arity-6 tuples, slices, pointers).

Merging,

closes #791.

@nihalpasham
nihalpasham merged commit cd0407e into NVIDIA:main Aug 11, 2026
38 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-trace-aggregates 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

enhancement New feature or request fuzzer Fuzzing infrastructure (rustlantis, difftest)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fuzzer: the trace API hashes scalars only, so a third of every sweep is refused before it reaches the device

2 participants