Skip to content

ci: guard the device-API names the book shows in Rust blocks - #819

Merged
nihalpasham merged 6 commits into
NVIDIA:mainfrom
vyncint:ci/book-api-name-guard
Aug 12, 2026
Merged

nihalpasham merged 6 commits into
NVIDIA:mainfrom
vyncint:ci/book-api-name-guard

Conversation

@vyncint

@vyncint vyncint commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Stacked on #815 and #816 — this guard needs both of their fixes to be
green, so the branch carries them. Review only the third commit
(f89c1944). If those land first this rebases to one commit.

A Rust code block in the book is something a reader pastes. When a device
function is renamed, or never existed, nothing fails: the book renders, CI is
green, and the reader finds out. That has now bitten three times —

All three were found by hand, months apart.

What it checks

scripts/check-book-api-names.sh resolves every warp::, thread::, grid::
and cluster:: call the book shows against the functions cuda-device exports.
On the current tree: 26 calls across 271 Rust blocks against 1,148 exports.

Scope is what makes it precise rather than merely broad:

  • Only ```rust fenced blocks. In prose a name may legitimately be a PTX
    instruction (shfl.sync.bfly), a module path, or another project's API; inside
    a Rust block it is a call and has to exist. This restriction is what takes the
    check from dozens of false positives to none.
  • Only the four device modules. Host APIs are already covered by rustdoc,
    which builds under -D warnings.
  • Existence only — never arity or types. Those change for good reasons and
    the compiler catches them; a name that is simply absent is the silent case.

The lookbehind is load-bearing

I only found this by running the guard against my own branch: warp and
thread are also module names inside the compiler, so the intrinsics guide's
intrinsics::warp::emit_two_operand_intrinsic(...) — a mir-importer path with no
business resolving against cuda-device — was flagged until the pattern learned
to reject a qualified prefix. An explicit cuda_device:: prefix stays accepted.

Verification

case result
current tree passes, 26/26 resolve
book reverted to pre-fix state reports warp::shuffle_xor_i32 — the defect it exists for
synthetic rename (shuffle_xor → shuffle_rotate) caught
compiler-internal intrinsics::warp::… correctly ignored
cuda-device/src missing exits non-zero rather than passing vacuously
cuda-device/src truncated reports the now-missing names

just check-guards green end to end; every scripts/check-*.sh is referenced by
both the Justfile and a workflow.

(Minor: #806 also edits the check-guards recipe, on a different line. They
should merge cleanly; happy to rebase if not.)

vyncint and others added 4 commits August 12, 2026 07:26
Continuation of NVIDIA#797, which corrected Stage 2 of the intrinsics guide for
the generated/hand-written split. Stage 3 has the same rot and NVIDIA#797 did
not touch it.

`adding-new-intrinsics.md` and `mir-importer.md` both show
`"cuda_device::warp::shuffle_xor"` dispatching to
`intrinsics::warp::emit_warp_shuffle_i32`. That function does not exist.
The file they cite does -- `intrinsics/warp.rs`, 118 lines -- but it
defines only `emit_warp_redux`, and the string `"cuda_device::warp::
shuffle_xor"` appears nowhere in a hand-written match.

The shuffles are catalog intrinsics. `shuffle_xor` is in
`intrinsics/catalog.json`, so its arm is generated into
`intrinsics/generated.rs` (line 1660 and around) beside the generated ops
that NVIDIA#797 documented. A reader following either page looks for a dispatch
that was never there in this form.

Scoped like NVIDIA#797: the guide is told what is generated rather than
rewritten. mir-importer.md's match keeps its two genuinely hand-written
arms and gains a paragraph on where the rest come from; the guide's Stage 3
gains the same note, and its illustrative emitter is renamed
`emit_two_operand_intrinsic` so nobody greps the tree for a symbol that is
not in it. The op names those pages cite -- `ShflSyncBflyI32Op`,
`convert_shuffle_i32` -- are real and untouched.

Also on mlir-dialects.md: "intrinsic functions like `thread::index_x()` or
`warp::shfl_sync_bfly()`" named two functions that do not exist either.
The real ones are `thread::index_1d()` and `warp::shuffle_xor()`;
`shfl_sync_bfly` is the PTX instruction, not the Rust entry point. Its
mangled-symbol example further down said `thread_index_x` and now agrees.

Verified: every name these pages now cite exists in the tree, no
nonexistent one remains on any page, and `sphinx-build -W --keep-going`
succeeds.

Signed-off-by: Vyncint Ng <[email protected]>
The quick reference's warp section advertises an `i32` form for all four
shuffles -- a `// i32 variants` code line calling
`warp::shuffle_xor_i32`, and a table whose four rows are written
`shuffle_xor_{f32,i32}` and so on. No `_i32` function exists in
`cuda_device::warp`, so the code line does not compile and the table
sends a reader looking for three more that are not there.

The real widths are the unsuffixed name for `u32`, plus `_f32`, `_f64`
and `_u64`, each with a `_sync` form taking an explicit member mask.

Worth more than deleting the wrong line: the page showed only the `_f32`
forms, so it never mentioned the `u32` ones at all -- a reader shuffling
integers had nothing correct to copy. The example now uses the
unsuffixed form and the table lists the widths that exist, with a note
that an `i32` should be reinterpreted and passed through the `u32` form,
since a shuffle moves bits without interpreting them.

Verified: every function the page now names exists in
crates/cuda-device/src/warp.rs, no `_i32` shuffle claim remains in any
user-facing page, and `sphinx-build -W --keep-going` succeeds.

Signed-off-by: Vyncint Ng <[email protected]>
A Rust code block in the book is something a reader pastes. When a device
function is renamed or never existed, nothing fails: the book renders, CI
is green, and the reader finds out. That has now bitten three times --
NVIDIA#797 (op files that no longer existed), the `warp::shuffle_xor_i32` entry
in the API quick reference, and a dispatch helper in the compiler pages
replaced by generated code. All three were found by hand, months apart.

`scripts/check-book-api-names.sh` resolves every `warp::`, `thread::`,
`grid::` and `cluster::` call the book shows against the functions
`cuda-device` exports. On the current tree that is 26 calls across 271
Rust blocks against 1,148 exports.

Scope is what makes it precise rather than merely broad:

  * Only ```rust fenced blocks. In prose a name may legitimately be a PTX
    instruction (`shfl.sync.bfly`), a module path, or another project's
    API; inside a Rust block it is a call and has to exist. Restricting to
    code blocks is what takes this from dozens of false positives to none.
  * Only the four device modules. Host APIs are already covered by
    rustdoc, which builds under `-D warnings`.
  * Existence only, never arity or types -- those change for good reasons
    and the compiler catches them. A name that is simply absent is the
    silent case.

The lookbehind rejecting a qualified prefix is load-bearing and I only
found it by running the guard against this branch: `warp` and `thread` are
also module names inside the compiler, so the intrinsics guide's
`intrinsics::warp::emit_two_operand_intrinsic(...)` -- a mir-importer path
with no business resolving against cuda-device -- was flagged until the
pattern learned to skip it.

Verified: passes here; reverting the two book pages to their pre-fix state
reports `warp::shuffle_xor_i32`, the defect it exists for; a synthetic
rename is caught; the compiler-internal path is ignored; and a missing or
truncated cuda-device tree fails rather than passing vacuously.

Stacked on NVIDIA#815 and NVIDIA#816, whose fixes this guard requires to be green --
review only the third commit.

Signed-off-by: Vyncint Ng <[email protected]>
@nihalpasham nihalpasham added build-related Build scripts, toolchain discovery, or compilation setup documentation Improvements or additions to documentation QoL-improvement Quality-of-life improvement; not a correctness fix labels Aug 12, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: right guard at the right tier: the book's Rust blocks are statement excerpts with free variables, so name resolution against cuda-device's export surface is what's checkable without compiling 271 fragments. One hole: both regexes were lowercase-only, leaving the threadIdx_x family invisible. Pushed 4960d37 widening the identifier classes; coverage goes from 26 to 33 unique calls with the mixed-case family now guarded.

Verified here:

  • guard red on main's stale warp::shuffle_xor_i32, green on the PR's book content;
  • two fabricated-API probes both caught post-fix, then reverted;
  • job and Justfile wiring matches the existing guard family (checkout@v4, 5-minute bound).

Landing after #815 and #816: this branch stacks both and will need a rebase once they merge.

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

# Conflicts:
#	cuda-oxide-book/compiler/adding-new-intrinsics.md
#	cuda-oxide-book/compiler/mir-importer.md
#	cuda-oxide-book/compiler/mlir-dialects.md
nihalpasham
nihalpasham previously approved these changes Aug 12, 2026
Signed-off-by: nihalpasham <[email protected]>

# Conflicts:
#	Justfile
@nihalpasham
nihalpasham merged commit cefa105 into NVIDIA:main Aug 12, 2026
42 checks passed
nihalpasham pushed a commit that referenced this pull request Aug 13, 2026
#819 reads only ```rust fenced blocks, and said so: a call is something a reader
pastes, while a name in running text might be a PTX mnemonic or another
project's function. That scoping left half of the very bug it was written for
uncovered.

#815 removed two things from the API quick reference. One code-block line,
`warp::shuffle_xor_i32(val, mask)`, which #819 now catches. And four *table*
rows, written `shuffle_xor_{f32,i32}(val, mask)` -- which it does not, because
they are not in a code block and not literal names. Reinstating that row today
passes the guard.

Adds a second pass over everything outside a fenced block, restricted to
backticked, module-qualified names. Backticks are what make it precise: a
backticked `warp::foo` is a claim about this API wherever it appears, so the
false positives that motivated the code-block-only scope do not arise.
Unqualified table entries stay out of scope -- deciding which module a bare
`shuffle_xor` belongs to is guesswork, and that is the one thing this cannot do
without inventing a mapping.

`_{a,b,c}` families are expanded, so a family with one bad member fails on that
member instead of passing as an unrecognised literal. That notation is live
today in `thread::threadIdx_{x,y,z}()`, and it is what carried #815's rows.

Both passes now self-test for a non-empty result, since the new regex is the
likelier of the two to break quietly.

Verified: passes clean (34 calls in 271 blocks, 31 names in prose and tables,
against 1161 exported fns) and exits 1 under four mutations -- #815's exact
table row reinstated (reports `warp::shuffle_xor_i32`), a bad axis in the live
shorthand (reports `thread::threadIdx_q`), a broken call in a code block
(the pre-existing pass, unchanged), and a rotted prose regex (self-test).

Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham added a commit that referenced this pull request Aug 13, 2026
…s in CI (#853)

The open-source review of commit 15fa9d9 confirmed everything from #812
fixed and left two items, both addressed here:

1. Source headers: scripts/check-book-api-names.sh and
   scripts/check-reserved-prefixes.sh landed after #812 merged (#819,
   #835) without the standard SPDX header. Both now carry it.

2. Third-party notices: the rangemap sub-crate under
   crates/fuzzer/rustlantis/ carries its own LICENSE-APACHE and
   LICENSE-MIT copies, which THIRD_PARTY_NOTICES did not mention. The
   Rustlantis entry now names that path; both texts are byte-identical
   to the rustlantis top-level ones.

The review also suggested a CI guard, since headers have now drifted
twice. scripts/check-spdx-headers.sh requires the two-line header on
every tracked *.rs *.sh *.py *.cu *.c *.h *.ll file outside the
vendored rustlantis subtree, with a checked exemption for the two
CUTLASS-derived BSD-3-Clause helpers the review accepted as-is. It runs
as a fourth job of the cargo-deny workflow and from 'just check-guards',
and CONTRIBUTING's License Headers section points at it.

Signed-off-by: nihalpasham <[email protected]>
nihalpasham pushed a commit that referenced this pull request Aug 17, 2026
`check-spdx-headers.sh` globs `*.rs *.sh *.py *.cu *.c *.h *.ll`. Eight
tracked first-party files fall outside that list and are therefore unchecked:

  cuda-oxide-book/_static/css/custom.css
  cuda-oxide-book/_static/css/lightbox.css
  cuda-oxide-book/_static/css/nvidia-sphinx-theme.css
  cuda-oxide-book/_static/js/lightbox.js
  cuda-oxide-book/_static/js/spa-nav.js
  cuda-oxide-book/_templates/footer.html
  cuda-oxide-book/_templates/globaltoc.html
  flake.nix

All eight already carry the standard two-line header, so this changes no
file and fails nothing today. That is exactly the hazard the guard's own
header describes: the OSRB review fixed 32 files in #812, and the next two
scripts to land (#819, #835) arrived without headers because nothing was
watching that extension. The same is true here one file type over -- a new
book stylesheet or template can land bare and CI stays green.

CONTRIBUTING already names HTML's comment form in the header policy, so
these files are in policy scope; only the guard's glob was short.

Verified: the guard passes unchanged over the extended scope (1803 files,
up from 1795), and stripping the header from `flake.nix` or from
`_static/js/spa-nav.js` now fails the run, where before it passed.

Signed-off-by: Vyncint Ng <[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 documentation Improvements or additions to documentation QoL-improvement Quality-of-life improvement; not a correctness fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants