Skip to content

feat: add schedule perturbation campaign - #1065

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
drbh:ptx-schedule-campaign
Aug 20, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
drbh:ptx-schedule-campaign

Conversation

@drbh

@drbh drbh commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

this pr adds a schedule perturbation campaign for existing cuda-oxide examples.

the campaign builds an example once, inserts deterministic nanosleep.u32 delays at structural synchronization sites in the generated PTX (atomics, mbarriers, fences, ordered loads/stores, warp collectives, loop back-edges), patches a copy of the executable's embedded artifact, and runs each variant behind a watchdog. the code and inputs never change; only warp timing does, and every mutation is a pure function of the seed so a finding replays exactly.

GEMM_SOL_PHASE=4b-correctness cargo oxide fuzz-schedule gemm_sol \
  --arch sm_100a --seeds 56..57 --focus mbarrier --confirm-runs 3 --timeout-secs 20

outputs

schedule-fuzz: baseline Pass
schedule-fuzz: FINDING seed=56 - SCHEDULE-SENSITIVE CORRECTNESS FAILURE
  confirmation: 3/3 reproductions (CONFIRMED)
RESULT: FOUND 1 CANDIDATE(S)

that finding is a real race: on 1x B200 (sm_100a), sweeping seeds 0..140 with --focus mbarrier surfaced a TILE_INFO mailbox race in the gemm_sol phase 4B kernel: the producer warp can republish tile coordinates before all five reader warps have copied them, leaving 264 of 1024 output tiles unwritten. seeds 56 and 135 each reproduce it 3/3 against a passing pristine baseline. the fix (and full failure output) is in #1066

findings are reported as schedule-sensitive outcomes rather than proof of a data race or deadlock: CORRECTNESS FAILURE, OUTPUT CHANGE (with --compare-output), TIMEOUT, CRASH, or GPU WEDGE candidates. a finding is rerun up to --confirm-runs times, and a timeout is rechecked with pristine PTX so a wedged device is not misreported. mutated PTX, decisions, logs, replay.sh, sites.json, and summary.json land under crates/fuzzer/artifacts/schedule/<example>/; the standalone ptx-schedule binary can also --list-sites or rewrite a PTX file directly. details are in crates/fuzzer/README.md.

cargo test -p ptx-schedule passes (7 tests) and cargo fmt --all -- --check is clean.

please let me know if I should make any changes or adjust the approach. Thanks!

@drbh drbh mentioned this pull request Aug 20, 2026
@nihalpasham nihalpasham added enhancement New feature or request cargo-oxide The `cargo oxide` subcommand and build automation build-related Build scripts, toolchain discovery, or compilation setup labels Aug 20, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator
  • Ran the campaign end to end on an RTX 5090: vecadd and cuda_module_in_lib baselines pass with zero findings, barrier gets real injections (7 then 11 of its 14 sites) and passes, per-seed artifacts plus sites.json and summary.json all written, and the objcopy-patched executables load and run.
  • One commit layered on: wires the four repo gates the branch missed (SPDX header on campaign.rs, both crate inventories, the CLI doc table, the unit-tests matrix plus Justfile parity); rejects --materialize-cubin for fuzz-schedule since it was accepted but never forwarded, and a cubin-materialized bundle has no PTX payload to patch; drains child stdout/stderr concurrently in run_binary (output past the pipe buffer wedged the child into a false Hang); records per-seed perturb/patch errors without killing the campaign or summary.json; and makes find_executable search all packages' bin targets, since packages.first() picked the kernel lib in every lib+bin example workspace and cuda_module_in_lib errored before running. Tests grow 7 to 9; clippy, fmt, gate scripts, and the book build are all clean.
  • One question: the lib.rs test comment references a "recovered Python classifier" that exists nowhere in the repo. Out-of-tree prototype? A reword or a pointer would help the next reader.
  • Noted for follow-up, not blocking: two classified sites inside one inline-asm block would map to the same insertion offset, and EditScript treats same-offset inserts as conflicts (latent today; no checked-in PTX trips it); replay.sh hardcodes the GEMM_SOL_PHASE env capture.

@nihalpasham
nihalpasham merged commit 7c21400 into NVIDIA:main Aug 20, 2026
50 checks passed
nihalpasham pushed a commit that referenced this pull request Aug 21, 2026
…a pass (#1112)

`has_skip_marker` accepts `skipping:` and nothing else. The convention it is
implementing has two spellings, and `scripts/smoketest.sh` -- which owns it --
accepts both:

    if grep -qiE '^[[:space:]]*(skipping:|pass \(skipped\))' "${log}"; then

Its own comment names the second form in so many words: "`PASS (skipped): ...`
form below sm_75". `generated_ldmatrix` prints exactly that:

    println!(
        "PASS (skipped): ldmatrix.m8n8.x4.b16 requires sm_75+; device is sm_{major}{minor}"
    );

An example declining that way exits 0 and prints no mismatch marker, so
`run_binary` classifies the run `RunKind::Pass`. That matters because the
campaign gates on it:

    if !matches!(baseline.kind, RunKind::Pass) {
        ... println!("schedule-fuzz: BASELINE FAILURE: {:?}; no schedule
        variants were run", ...)

With the right kind the campaign stops there and says so. With `Pass` it
proceeds: it patches the PTX, sweeps every seed, and each variant declines
identically -- same exit code, same output, so not even `OutputChanged` fires.
The campaign reports a clean sweep of a kernel that never launched.

This is #665's bug in the second consumer of the same convention. That fix
put it as "a skip the function fails to recognise is not merely missing its
`(skipped)` annotation -- it is promoted to a full execution PASS", and taught
`verdict_standard` the second spelling. `ptx-schedule`'s campaign arrived later
(#1065) with only the first. A silent all-clear is the worst outcome available
to a bug-finding tool, and it is the one this produces on any device below an
example's floor.

Hoist both spellings into a `SKIP_MARKERS` constant and check the line against
each, with the coupling to the smoketest's pattern recorded next to it.
Case-insensitivity is unchanged and already correct: `run_binary` lowercases
before classifying, which is what makes this match the smoketest's `grep -i`.

Two tests: both spellings are recognised with and without leading whitespace,
and the near-misses are not -- a bare `pass`, `pass: 1024 elements verified`,
`success`, and a mid-line `no skipping: here`, since the marker is anchored to
the start of the line in the smoketest too. Both fail with the second marker
removed.

Verified: 11 tests pass, fmt clean, `clippy --all-targets -- -D warnings`
clean, and `cargo doc --document-private-items` clean.

Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham pushed a commit that referenced this pull request Aug 21, 2026
…#1116)

`ptx-schedule` landed in #1065 and depends on both PTX crates. Neither one's
README says so, and one of them is now wrong rather than merely short.

**`ptx-parse`** lists its consumers in a table: `cuda-oxide-codegen`,
`cuda-host`, `cuda-intrinsics-gen`, `cargo-oxide`, `dialect-ptx`. Six crates
declare `ptx-parse` as a dependency; that is five of them. `ptx-schedule`
takes `Document`, `EditScript`, `Instruction` and `ParseError`, which is as
central a use as any row already there. Every other row checks out, including
the file-level detail -- `export.rs` and `ptx.rs` in `cuda-oxide-codegen`, and
`embedded.rs` in `cuda-host`, all three exist and all three reference
`ptx_parse`.

**`dialect-ptx`** has a section headed "First consumers" that reads:

> The first in-tree consumers of the native CFG are IKET PTX instrumentation
> (`dialect-iket`), which needs verified block boundaries and successor edges
> to place probes, and the Tile-to-SIMT interop epic (#96) ...

Neither is a consumer. `dialect-iket` does not depend on `dialect-ptx` and
contains no reference to it; #96 is still an open tracking issue. Meanwhile the
one crate that does depend on `dialect-ptx` -- `ptx-schedule`, and it depends
on nothing else from it but `cfg::ControlFlow` -- goes unmentioned. So the
section states a plan in the present tense, and the reader looking for who
actually exercises the native CFG is pointed at two crates that do not.

Rename it to "Consumers", name `ptx-schedule` and what it uses the CFG for
(back-edge discovery, which is what makes a spin loop perturbable whatever its
label, predicate or branch spelling), and keep the other two where they belong,
as planned work that does not depend on the crate yet.

Verified: `check-book-api-names.sh` reports OK across 159 READMEs; no relative
links were added, so crates.io rendering is unaffected (the correction from
#981's review).

Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham added a commit that referenced this pull request Aug 21, 2026
* docs(ptx-schedule): the one published crate with no README

`ptx-schedule` arrived with #1065 and is the only publishable crate in the
workspace with neither a `readme` key nor a README.md on disk. Checked across
`cargo metadata`: every other publishable member has both. crates.io renders
that file as the package page, so this one would publish with an empty body.

This is the same gap #981 closed for `ptx-parse`, and the README follows that
one's shape.

Content is taken from the crate rather than from the commit that added it:

- The purpose and the "owns neither CUDA execution nor an input generator"
  boundary come from `lib.rs`'s module header.
- The seven `SiteKind` variants and the eight campaign `RunKind` verdicts are
  each enumerated in full, since a partial list of a closed enum is the thing
  that rots (#978, #1045, #1056).
- `InjectionOptions`' four fields, `DEFAULT_MAX_SLEEP_NS` (64 µs), the
  `nanosleep.u32` insertion, and the `confirm_runs` re-run before a finding is
  reported are all as implemented.
- `cargo oxide fuzz-schedule` is named as the user-facing entry point, with the
  crate's own binary shown for single-file work; the flags in the example come
  from `main.rs`'s usage string.

One detail carried over from #981's review: the License link is absolute rather
than `../../LICENSE`, because crates.io rewrites relative README links against
the repository root and the relative form 404s there.

Verified: `cargo metadata` now reports `readme: README.md` for the crate and
the file resolves; all seven `SiteKind` and eight `RunKind` names appear;
`check-crate-inventory.sh`, `check-spdx-headers.sh` and
`check-book-api-names.sh` pass; no relative `../` links remain.

Signed-off-by: Vyncint Ng <[email protected]>

* docs(ptx-schedule): align the README with the code it describes

Six statements did not match the crate as it stands:

- the execution disclaimer claimed the whole crate owns no CUDA
  execution while campaign.rs two sections down builds, launches,
  watchdogs and assigns verdicts; the section now scopes the claim to
  analyze_ptx/perturb_ptx and points at the campaign layer;
- intensity is a probability dial (0.75 x intensity per site, and it
  scales the drawn sleep lengths), not a fraction of sites touched;
- focus re-weights selection by substring over each site's opcode and
  instruction text (0.95x hits, 0.15x misses); it never restricts the
  sweep to one callable;
- Skipped is assigned only when the example prints a skip marker; a
  zero-injection seed still runs and reports like the baseline;
- findings are reported with their confirmation counts attached, not
  gated on confirmation;
- a seed pins the rewrite, not the schedule the GPU then picks.

Smaller table fixes from the same read of classify_instruction: the
Barrier row now names mbarrier.*, OrderedMemory names the ordering
qualifiers it actually matches (a scope alone never classifies), the
Backedge row describes the conservative same-or-earlier-block test
(no dominance is computed), and the block-index field is called out as
back-edge-only. The injection knobs move into a bulleted list so each
one can state its own semantics.

---------

Signed-off-by: Vyncint Ng <[email protected]>
Co-authored-by: nihalpasham <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build-related Build scripts, toolchain discovery, or compilation setup cargo-oxide The `cargo oxide` subcommand and build automation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants