Skip to content

fix(fuzzer): run seeds whose device code calls libdevice - #395

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
alejandro-soto-franco:fix/fuzzer-libdevice-seeds
Jul 22, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
alejandro-soto-franco:fix/fuzzer-libdevice-seeds

Conversation

@alejandro-soto-franco

@alejandro-soto-franco alejandro-soto-franco commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #414

Summary

A generated seed whose device code calls libdevice never reached the comparison. The harness loaded the kernel with load_module_from_file("rustlantis_smoke.ptx"), and once libdevice is involved the backend does not emit a bare PTX file, so the run died with DriverError(301, "file not found") and the seed was scored COMPILE_FAIL. The compiler was right and the harness could not keep up with it.

Changes

  • Load through kernels::load(&ctx), so cuda-host's load_embedded_module dispatches over cubin, PTX, NVVM IR and LTOIR and links whichever the backend produced. This is the entry point examples/libdevice_math already uses for kernels calling libdevice math.
  • Check in seed 162 as generated_case.rs, replacing the integer-only seed 19.
  • Document the float and libdevice precision caveat in crates/fuzzer/README.md.
  • Correct the README's stale type-support notes.

Rationale

Seed 162 calls fmaf64 and is now the checked-in case, so the fix is captured in the tree rather than asserted in prose. Measured on an RTX 5060, driver 610.43.03:

harness result
main COMPILE_FAIL, Failed to load PTX module: DriverError(301, "file not found")
this change PASS [run] CPU/GPU traces matched

The trace comparison is exact u64 hash equality, which assumes the CPU and the GPU agree bit for bit. That is safe for fma, which IEEE-754 specifies as a single correctly-rounded operation. It does not hold across libdevice as a whole: the transcendentals are not required to match the host's libm, and this repository already compares them within 2 ULP in examples/math_atan and through ulp_distance in examples/libdevice_math.

Floats never enter the hash directly, since the trace API has no f32 or f64 arm and the adapter refuses a bare float dump, but a float still reaches it through an as cast, through a comparison yielding a bool, or through rustlantis' transmute_place. Unlocking these seeds therefore admits mismatches that are precision artefacts rather than backend bugs. The README now says so and asks that a float-influenced MISMATCH be compared in ULPs before it is filed. Making the comparison itself tolerant is a change to the trace model and is left alone here.

The same README had drifted elsewhere: it listed the trace API as hashing nine types when trace.rs has hashed fifteen since May, including the u128 its worked example still cites as unsupported.

Validation

  • cargo check --workspace --all-targets
  • cargo clippy --workspace -- -D warnings
  • cargo fmt --all -- --check
  • (cd crates/rustc-codegen-cuda && cargo fmt --all -- --check)
  • (cd crates/rustc-codegen-cuda/examples/rustlantis-smoke && cargo fmt --all -- --check)
  • python3 crates/fuzzer/tools/run_seed.py --seed 162 against main, giving COMPILE_FAIL
  • python3 crates/fuzzer/tools/run_seed.py --seed 162 against this branch, giving PASS

crates/fuzzer has no unit tests and no CI job runs it, so both fuzzer results above are manual, on the hardware named.

A generated seed whose device code calls libdevice never reached the comparison.
The harness loaded the kernel with `load_module_from_file("rustlantis_smoke.ptx")`,
and once libdevice is involved the backend does not emit a bare PTX file, so the
run died with `DriverError(301, "file not found")` and the seed was scored
COMPILE_FAIL. The compiler was right and the harness could not keep up with it.

Load through `kernels::load(&ctx)` instead. `cuda-host`'s `load_embedded_module`
dispatches over cubin, PTX, NVVM IR and LTOIR payloads and links whichever the
backend produced, which is the same entry point `examples/libdevice_math` already
uses for kernels that call libdevice math.

Seed 162 is such a case (`fmaf64`) and is now the checked in `generated_case.rs`,
so the fix is captured in the tree rather than only in this message. On an
RTX 5060, driver 610.43.03:

- against the harness on main: `COMPILE_FAIL`, with
  `Failed to load PTX module: DriverError(301, "file not found")`
- against this change: `PASS [run] CPU/GPU traces matched`

The trace comparison is exact `u64` hash equality, which assumes the CPU and the
GPU agree bit for bit. That assumption is safe for `fma`, which IEEE-754 specifies
as a single correctly-rounded operation. It does not hold across libdevice as a
whole: the transcendentals are not required to match the host's libm, and this
repository already compares them within 2 ULP in `examples/math_atan` and through
`ulp_distance` in `examples/libdevice_math`. Floats never enter the hash directly,
since the trace API has no `f32` or `f64` arm and the adapter refuses a bare float
dump, but a float still reaches it through an `as` cast, through a comparison
yielding a `bool`, or through rustlantis' `transmute_place`.

Unlocking these seeds therefore admits mismatches that are precision artefacts
rather than backend bugs. `crates/fuzzer/README.md` gains a section saying so and
asking that a float-influenced `MISMATCH` be compared in ULPs before it is filed.
Making the comparison itself tolerant is a change to the trace model and is left
alone here.

The same README had drifted elsewhere: it listed the trace API as hashing nine
types when `trace.rs` has hashed fifteen since May, including the `u128` its
worked example still cites as unsupported.

Signed-off-by: Alejandro Soto Franco <[email protected]>
@alejandro-soto-franco
alejandro-soto-franco force-pushed the fix/fuzzer-libdevice-seeds branch from 6163814 to 45c8798 Compare July 20, 2026 17:11
The worked example still showed seed 0 classified UNSUPPORTED for a u128
dump, two lines above the corrected type list that names u128 as hashed,
and the terminal-summary example still showed seed 1 failing on
RigidTy(Char), which the type translator has handled for a while. Both
examples predate the adapter/trace-API widening and contradict the rest
of the document.

Re-ran both seeds on this branch (RTX 5090, driver-backed run through
run_seed.py): seed 0 and seed 1 both report
PASS [run] CPU/GPU traces matched. The examples now quote that observed
output, and the UNSUPPORTED explanation stands on its own instead of
leaning on a classification that no longer occurs.

Signed-off-by: nihalp <[email protected]>
@nihalpasham nihalpasham added bug Something isn't working documentation Improvements or additions to documentation build-related Build scripts, toolchain discovery, or compilation setup host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) labels Jul 22, 2026
Checked-in seeds now sit inside the example's per-directory
'cargo clippy --all-targets -- -D warnings' CI gate, and machine
generated MIR-shaped code is lint-hostile by design (seed 162's
'394723964_u32 as f64' trips unnecessary_cast). The generator already
emits rustc lint allows for the same reason; extend the emitted header
with clippy::all and regenerate seed 162, keeping the checked-in case
byte-identical to generator output.

Signed-off-by: nihalp <[email protected]>
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR. LGTM.

  • The rustlantis-smoke harness no longer hardcodes a bare PTX file: it loads through #[cuda_module] + kernels::load(&ctx), so the embedded-module dispatch handles cubin, PTX, NVVM IR, and LTOIR — whichever the backend legitimately produces. Libdevice-calling seeds stop dying at module load and stop being misattributed as COMPILE_FAIL.
  • Seed 162 (fmaf64 -> __nv_fma, the NVVM-IR route) is checked in as a standing regression case; the checked-in case is byte-identical to regenerated generator output.
  • The fuzzer README's stale type-support claims were corrected. I pushed maintainer follow-ups: the two remaining stale examples (seed 0's u128 UNSUPPORTED message and seed 1's RigidTy(Char) failure) now quote genuine observed output — both seeds PASS on current main — and the case generator emits #![allow(clippy::all)] in its header, since checked-in seeds now sit inside CI's per-example clippy gate and machine-generated MIR-shaped code trips lints by design (seed 162's integer-cast line failed that gate). Seed 162 was regenerated, staying byte-identical to generator output.

For example:

seed 162 before: COMPILE_FAIL [backend]  (harness could not load NVVM IR)
seed 162 after:  PASS [run] CPU/GPU traces matched

Reviewer note: Seeds 0, 1, and 162 all PASS on an RTX 5090; scripts/smoketest.sh rustlantis-smoke passes in full and compile-only modes with the .ll + .target sidecar confirmed on the NVVM-IR route. Note the example now requires libNVVM/nvJitLink at runtime (same class as libdevice_math). All hosted CI checks passed on the final head.

This closes #414.

@nihalpasham
nihalpasham merged commit d6a051b into NVIDIA:main Jul 22, 2026
33 checks passed
@alejandro-soto-franco
alejandro-soto-franco deleted the fix/fuzzer-libdevice-seeds 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

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup documentation Improvements or additions to documentation host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fuzzer: seeds whose device code calls libdevice are scored COMPILE_FAIL

2 participants