Skip to content

docs(compiler): the shuffle dispatch these pages show does not exist - #816

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:docs/compiler-pages-real-names
Aug 12, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
vyncint:docs/compiler-pages-real-names

Conversation

@vyncint

@vyncint vyncint commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Continuation of #797, which corrected Stage 2 of the intrinsics guide for the
generated/hand-written split. Stage 3 has the same rot and #797 did not touch
it.

The defect

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 —
crates/mir-importer/src/translator/terminator/intrinsics/warp.rs, 118 lines —
but it defines only emit_warp_redux, and the string
"cuda_device::warp::shuffle_xor" appears in no hand-written match.

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

The fix, scoped like #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 — it is teaching the shape of a
    two-argument emitter, so it should not wear the name of a symbol that is not in
    the tree.

The op names these pages cite — ShflSyncBflyI32Op, convert_shuffle_i32 — I
checked and both are real, so they are untouched.

Also on mlir-dialects.md

"intrinsic functions like thread::index_x() or warp::shfl_sync_bfly()"

Neither exists. The real ones are thread::index_1d() and warp::shuffle_xor();
shfl_sync_bfly is the PTX instruction name, not the Rust entry point. Its
mangled-symbol example further down said thread_index_x and now agrees with the
corrected name.

Verification

  • Every name these pages now cite exists in the tree (emit_warp_redux,
    index_1d, shuffle_xor, ShflSyncBflyI32Op, convert_shuffle_i32).
  • No nonexistent name remains on any page.
  • sphinx-build -W --keep-going -b html succeeds.

(Found by diffing every API-shaped name the book cites against what the tree
exports — the same sweep that produced #815.)

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]>
@nihalpasham nihalpasham added documentation Improvements or additions to documentation intrinsics Device intrinsics and libdevice math mappings labels Aug 12, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: right to kill emit_warp_shuffle_i32, but several corrected passages were still wrong about how dispatch works: only the _sync variants are match strings (bare shuffle_xor is a source-level wrapper), emit_warp_redux is dead code and the redux family is catalog-generated, the barrier arm is thread::sync_threads, and index_1d never appears as a lone sreg read. Pushed 336a70b aligning all three pages with the generated dispatcher.

Verified here:

  • every corrected passage backed by dispatcher source: generated.rs match strings, the hand-written typed_swap arm now used as the hand-dispatch example, and the real 3-operand shuffle converter in Stage 4;
  • two provenance statements fixed alongside (NVVM ops are emitted by mir-importer, not mir-lower);
  • Sphinx build with CI's -W flags green.

Landing once CI is green.

@nihalpasham
nihalpasham merged commit dd26e18 into NVIDIA:main Aug 12, 2026
68 of 69 checks passed
nihalpasham added a commit that referenced this pull request Aug 12, 2026
* docs(compiler): the shuffle dispatch these pages show does not exist

Continuation of #797, which corrected Stage 2 of the intrinsics guide for
the generated/hand-written split. Stage 3 has the same rot and #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 #797 documented. A reader following either page looks for a dispatch
that was never there in this form.

Scoped like #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]>

* docs(api-ref): the shuffle i32 variants documented here do not exist

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]>

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

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 --
#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 #815 and #816, whose fixes this guard requires to be green --
review only the third commit.

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

* fix(ci): match mixed-case device-API names in the book guard

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

---------

Signed-off-by: Vyncint Ng <[email protected]>
Signed-off-by: nihalpasham <[email protected]>
Co-authored-by: nihalpasham <[email protected]>
nihalpasham pushed a commit that referenced this pull request Aug 12, 2026
…that hid (#833)

`pub mod translator` made every item under it reachable API, so `dead_code`
was off for the whole module tree. The only in-tree consumer reaches the
translator through `pipeline`, and the two predicates outsiders need are
already re-exported from the crate root, so the module is now `pub(crate)`.

That switches the lint back on and it finds six orphans, all removed:

- `intrinsics::warp::emit_warp_redux` -- the whole 118-line module. Called
  out as dead in the #816 merge note; the redux family is catalog-generated.
  Its doc claimed to be "shared by the whole integer reduction family",
  which is what sent the book's Stage 3 to the wrong place twice.
- `intrinsics::indexing::emit_index_2d` and its `generated_sreg_op` helper.
  Its own doc says the dispatcher routes index helpers as normal function
  calls instead; `try_dispatch_intrinsic` returns `Ok(None)` for all of them.
- `helpers::emit_nvvm_intrinsic` / `emit_nvvm_intrinsic_u64` -- the
  pre-catalog twins of `emit_generated_nvvm_intrinsic{,_u}`, differing only
  in not stamping the ABI marker.
- `translator::translate_function` -- the crate doc example's entry point.
  The example passed four arguments to a five-argument function, so it had
  not been compiled against reality in some time.
- `types::get_f32_type`.

`index_1d_sreg_ops_carry_their_exact_generated_markers` built its ops with
the dead `generated_sreg_op`, so it could not have caught a regression in
what the compiler actually emits. It now asserts the same three markers
against the target table the backend reads back at verification time, which
cross-checks the two generated artifacts against each other.

The seventh orphan is generated: `generated_intrinsic_marker`, a 2142-line
path-keyed table whose only callers are the generated tests in the same
file. Gated on `cfg(test)` in the renderer rather than deleted, since
whether the catalog should still render it is a generator decision. If you
want it gone, that is one more line in `render.rs` and -10k in output.

Book and crate docs updated where they named a removed symbol: the
quick-reference checklist pointed new contributors at `emit_nvvm_intrinsic`,
and both flow diagrams still started at `translate_function()`.

No behaviour change: nothing deleted had a caller.

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

documentation Improvements or additions to documentation intrinsics Device intrinsics and libdevice math mappings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants