Repository navigation
feat(ptx): add ptx-parse and the PTX dialect with verified native CFG (stack #914-#917) - #917
Merged
Merged
Conversation
This was referenced Aug 15, 2026
Rename the crate directory, package name, workspace entries, and all dependent imports. Mark the crate publishable since cuda-host (published) depends on it; the ptx-parse name is free on crates.io.
…ueries Extracted from PR NVIDIA#915: ten examples' textual PTX assertions move onto ptx-parse Document queries (callables, directives), with each example Cargo.lock refreshed for the new path dependency. The dialect half of that PR is not included.
…ing nothing instructions_with_matching_head mapped Document::parse errors to an empty match list, so unparseable PTX read as "no match" and could slip through the probe validators with a misleading zero-count message. Return the ParseError instead and propagate it through matching_instructions, contains_matching_instruction, InstructionPattern::matches, and selection_matches_policy, matching how the other migrated call sites surface parse errors.
… dependency cuda-host now depends on ptx-parse, and every example workspace resolves cuda-host through its path dependency, so each committed example Cargo.lock (and the isolated rustc-codegen-cuda lock) gains the two additive ptx-parse entries. Purely additive, matching the re-lock pattern from NVIDIA#893.
Collaborator
|
Head of the stack and the landing vehicle: merging this merges #914 through #917, and those three close as already-fixed. Rebuilt on the hardened #916 with the final review items plus the whole-stack verification on our hardware. Changes:
The verification that matters, all on our hardware:
Known boundary, stated plainly: raising is not universal yet. Callables with nested call-frame scopes refuse to raise rather than guess. That is the intended fail-closed posture; widening it is future work with its own tests. |
Extracted from PR NVIDIA#915: crates/dialect-ptx only (the example-migration half already landed with the ptx-parse foundation). Imports adapted from the renamed ptx-syntax crate to ptx-parse.
…attrs ptx.callable carried the same facts twice: typed attrs (callable_name, callable_kind, callable_external) for queries and the header string for printing. The emitter prints only the string, so mutating a typed attr silently desynced the emitted PTX from the queryable truth. The header stays the print carrier (it holds parameter lists and performance directives the dialect does not model yet), but Verify now re-parses it with ptx-parse and rejects any disagreement with the typed attrs, naming both values in the error. ptx.scope's header gets the matching check: a non-empty header must not carry its own terminator and must not spell a callable, which would bypass ptx.callable's typed attrs. The contract is documented on both ops.
…cate attr PTX defines exactly one instruction prefix, the guard predicate, so ptx.instruction no longer carries a free-form instruction_prefix string. It now carries an optional typed PredicateAttr (register + negation), populated by the projection from ptx-parse's parsed predicate. The emitter derives the textual "@%p1" / "@!%p1" guard from the attribute, and attribute verification rejects registers that are not %-prefixed. PtxBuilder grows predicated_instruction(); plain instruction() drops the prefix parameter. Repo-wide grep confirms nothing but predicate text ever rode in the prefix string.
…it, reparse Builds a kernel with a counting loop through PtxBuilder, prints the typed IR (the loop back-edge carries the typed ptx.predicate attribute), emits canonical PTX, and checks the guard survives a lossless ptx-parse round trip.
The license-inventory, crate-overview, and SPDX CI guards require every workspace member to be listed. Adds dependency-licenses.csv rows and README Crate Overview rows for both new crates, and the standard SPDX header on ptx-parse's audit example.
… plan time '.' is a word byte, so a vector-element use such as v.x lexes as a single token and never resolves to the binding v. Renaming a nested binding would leave v.x behind, silently rebinding it to any same-named outer register and assembling with wrong semantics. RegisterAlphaPlan now scans the callable body for tokens of the form R.suffix whenever R is scheduled for renaming and fails closed with a typed error naming the token and its byte span.
…le names The occupied-token check only avoids names spelled inside the callable body. A module callable never referenced in the body, or a label equal to a bank base name (which the bank availability check skips), can still end up as a rename target; the rewritten register then captures branch or call targets and the PTX fails ptxas or assembles with wrong semantics. RegisterAlphaPlan now cross-checks every chosen target against the callable's labels and the module's callable names and fails closed with a typed error naming both symbols.
…eiling The UnsupportedPtxVersion ceiling previously gated only the read-only CFG recovery. Rewrites are higher risk than reads: an unaudited ISA could bind or spell registers in ways the resolver does not model. The .version validation moves to a shared version module with a typed PtxVersionError, and RegisterAlphaPlan and ScopeFlattenPlan now fail closed on missing, invalid, or newer-than-9.3 versions exactly like ControlFlow::analyze.
Pragma strings are tool-defined with placement-dependent meanings, so deleting the braces around a block-scoped pragma such as .pragma "nounroll"; can widen its effect to the whole callable. Scope flattening now fails closed on nested scopes containing .pragma; only .loc, whose debug-location effect follows lexical order regardless of braces, remains scope-neutral.
The example now re-analyzes its own canonical emission with NativeCfgPlan, prints the raised module and the guarded loop back-edge ptx.terminator (typed predicate plus real successor edges), and checks that canonical emission from the raised CFG is byte-identical to the surface emission.
nihalpasham
force-pushed
the
pr/ptx-v2-native-cfg
branch
from
August 17, 2026 07:01
f0d6a5b to
35c8073
Compare
nihalpasham
approved these changes
Aug 17, 2026
This was referenced Aug 17, 2026
nihalpasham
added a commit
that referenced
this pull request
Aug 18, 2026
* docs(ptx-parse): the one published crate with no README
Every workspace member except `ptx-parse` ships a `README.md` and declares
`readme = "README.md"` -- 26 of 27 with both, and `ptx-parse` with neither.
It is the wrong crate to have missed. `ptx-parse` is the only member that sets
`publish = true`:
# Published because cuda-host depends on it (name verified free on crates.io).
publish = true
description = "Lossless structural views over PTX source text"
so it is the one crate here whose page on crates.io renders from a README, and
that page would render with the one-line description and nothing else. Its
sibling `dialect-ptx` -- from the same #914-#917 stack -- has both, and its
README sends readers here: "`ptx-parse::Document` owns exact external source,
trivia, unknown syntax, and byte-preserving edits." Following that pointer
currently lands on nothing.
The README is written from the crate's own sources, not from an impression of
them:
* the framing and the deliberate no-ISA-type-checking rule come from the
`lib.rs` crate doc,
* the six `StatementKind` variants, the `Document` accessors, `diagnostics`,
`coverage` and `ParseError` from `lib.rs` and `syntax.rs`,
* the `EditScript` surface, including `apply_with_map`/`AppliedEdits` and the
`MapBias` at edit boundaries, from `edit.rs`,
* the `ptx-parse` / `dialect-ptx` split restated in the same terms
`dialect-ptx`'s README already uses, so the two agree rather than drift,
* and the consumer table from the actual `ptx_parse::` call sites in
`cuda-oxide-codegen`, `cuda-host`, `cuda-intrinsics-gen`, `cargo-oxide` and
`dialect-ptx`.
`readme = "README.md"` is added alongside, matching the other 26 manifests, so
the packaged crate carries it too.
Verified: every backticked API name in the new README resolves in
`crates/ptx-parse/src/`; all 27 members now have both the file and the
manifest field; `cargo metadata --locked` still parses; check-crate-inventory,
check-dependency-licenses and check-spdx-headers pass.
Signed-off-by: Vyncint Ng <[email protected]>
* docs(ptx-parse): use absolute LICENSE link so crates.io does not 404
crates.io rewrites relative README links against the repository root,
so ../../LICENSE escapes the root on the published page.
---------
Signed-off-by: Vyncint Ng <[email protected]>
Co-authored-by: nihalpasham <[email protected]>
nihalpasham
pushed a commit
that referenced
this pull request
Aug 18, 2026
## The Crate Map `architecture-overview.md`'s Crate Map opens "cuda-oxide is split into focused crates. Here is every one and its role" and then lists 15. The workspace has 27 members plus `rustc-codegen-cuda`, so 13 are absent: cuda-intrinsics cuda-intrinsics-gen cuda-artifact-finalizer cuda-oxide-codegen oxide-artifacts reserved-oxide-symbols dialect-iket iket-lower dialect-ptx ptx-parse libnvvm-sys nvjitlink-sys fuzzer This is the same gap `scripts/check-crate-inventory.sh` exists to prevent, one document over. That guard was written because `dialect-iket` and `iket-lower` were missing from README.md's Crate Overview -- "1,700 lines of compiler across two crates, with no row between them". Both are missing here too, and the guard cannot see this table because it only reads README.md. Roles are copied verbatim from README.md's Crate Overview rather than written fresh, so the two inventories agree word for word and the guarded one stays the single source of truth. The table is now 28/28 against the member list. ## The dialect count Two pages state how many pliron dialects cuda-oxide defines, and both predate `dialect-iket` and `dialect-ptx` (#917): architecture-overview.md:188 "cuda-oxide defines two dialects on top of pliron" pliron.md:352 "cuda-oxide works with three dialects" Neither is a count of everything; both are counts of the lowering path, which is what the surrounding prose goes on to describe. Rather than fold two off-path dialects into a "levels of abstraction" narrative where they do not belong, each claim is now scoped to the lowering path and names the other two so a reader knows they exist. `dialect-iket` carries 7 ops and 2 types; `dialect-ptx` is the structured terminal PTX dialect from #917. `mlir-dialects.md` carries the same claim in its opening and is fixed in a separate change; this one does not touch that file, so the two do not overlap. Verified: the Crate Map matches the member list exactly (28 listed, 28 actual, no missing and no extra, checked by script); `just book` (`sphinx-build -W --keep-going`) succeeds; check-crate-inventory and check-book-api-names pass. Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham
pushed a commit
that referenced
this pull request
Aug 18, 2026
…alidates (#969) The obligation #964's merge comment attached to #946 landing. #946 has landed (d485edb), and it was not the only batch member to move these numbers. The page carries a self-invalidating stamp: "If the header stamp no longer starts with `df42ef97`, the counts on this page predate the catalog you are reading." Every `ops/generated/` header now prints `20440c06...`, so it does. Recomputed from the tree at d485edb, with each delta attributed by `git ls-tree` + `git show` per module rather than from a PR diff: generated/integer_minmax.rs 0 -> 8 new module (#967, DPX min/max) generated/packed_alu.rs 22 -> 30 f32x2 arithmetic (#946) ops/wgmma.rs 6 -> 7 counted-K pipeline op (#935) which moves five figures and adds a row: stamp df42ef97 -> 20440c06 total 543 across 41 modules -> 560 across 42 hand-written 18 ops -> 19 (`wgmma` 6 -> 7) generated 34 modules / 525 ops / 986 catalog entries -> 35 modules / 541 ops / 1002 catalog entries Packed (SIMD-in-reg) 43 -> 51 Integer min/max (DPX) new row, 8 -- `integer_minmax` `integer_minmax` gets its own row rather than joining Scalar math beside `extended_minmax`: six of its eight ops are `16x2` packed forms (`max_s16x2`, `min_relu_s16x2`, ...) and two are scalar `s32`, so it is a feature area rather than a scalar-math addition. Checked and unchanged in the same pass: dialect-mir is still 62 ops across 12 modules with 9 types, and the `pliron` pin is still 8447aa42, so the LLVM dialect's 69 stands. **A correction to my own #964 while I am here.** That PR asserted #946 added no ops, on the strength of `gh pr diff 946 | grep -c pliron_op` returning 0. As the merge comment noted, `gh pr diff` returns empty on a diff that large, so the grep was counting nothing rather than finding nothing -- an unfalsifiable check that reads as a clean result. Every count in this commit is derived from git objects in the tree instead. Separately, the chapter's opening said cuda-oxide "works across three pliron dialects ... two defined locally". Two more local pliron dialects exist and the book never mentions either: `dialect-iket` (7 ops, 2 types) and `dialect-ptx` (#917). The claim is now scoped to the lowering path, which is what this chapter actually covers, with a pointer to the two crates' READMEs. The same count appears in `pliron.md` and `architecture-overview.md`; those are a separate change, and this one does not touch either file. Verified: every figure on the page recomputed by script against the tree; `just book` (`sphinx-build -W --keep-going`) succeeds; check-book-api-names passes. Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham
pushed a commit
that referenced
this pull request
Aug 18, 2026
`unit-tests.yml`'s matrix covers 21 of the 27 workspace members. Its own
comment block names the intended exclusions:
# Crates intentionally not in this matrix:
# * `cuda-bindings` — generated sys bindings covered transitively.
# * `fuzzer` — differential-testing infra with no unit tests.
# * `rustc-codegen-cuda` — its own [workspace] ...
Four members are in neither list. They are not declared out; they were left
out, and between them they hold 107 `#[test]` functions that nothing executes:
dialect-ptx 43 structured terminal PTX dialect (#917)
ptx-parse 35 lossless CST over PTX source (#917)
iket-lower 22 dialect-iket -> runtime compatibility profile
dialect-iket 7 in-kernel event tracing dialect
`dialect-iket` and `iket-lower` have been uncovered for a long time -- they are
the same two crates whose absence from README.md motivated
`check-crate-inventory.sh` ("1,700 lines of compiler across two crates, with no
row between them"). `dialect-ptx` and `ptx-parse` arrived with #914-#917 last
batch. The PTX pair is the one that stings: `dialect-ptx` verifies native CFG
invariants, which is precisely the sort of property a unit test is the only
cheap way to hold, and 43 of them have never gated a merge.
None of the four touches `cuda-bindings`, so none needs the toolkit: their
dependency sets are `pliron`, `pliron-derive`, `thiserror`, `combine`,
`dyn-clone`, `linkme`, and `ptx-parse` has no dependencies at all. They go in
the plain matrix with the default `--all-targets` and no `needs_cuda`, and add
about a second of runtime between them.
The exclusion comment now also says what the list is *for* -- that a member
absent from both the matrix and the list is an omission rather than a decision
-- since the list reading as complete is what made this invisible.
`just test` gets the same four, because its own comment is the contract:
"Mirrors .github/workflows/unit-tests.yml; keep the two in step." `test-cuda`
is unchanged; nothing here links the driver.
Verified locally with the pinned toolchain:
dialect-iket 7 passed; 0 failed
iket-lower 22 passed; 0 failed
ptx-parse 35 passed; 0 failed
dialect-ptx 43 passed; 0 failed
so this turns CI green-on-nothing into green-on-107 without changing a test.
Also checked by script: the CI matrix and the Justfile's package lists are now
identical, and every workspace member is either in the matrix or named in the
exclusion comment -- no member is silently uncovered. `unit-tests.yml` still
parses, with 25 matrix entries.
Signed-off-by: Vyncint Ng <[email protected]>
2 of 3 tasks
nihalpasham
pushed a commit
that referenced
this pull request
Aug 19, 2026
…aims (#1019) `check-dependency-licenses.sh` justifies a pipeline stage like this: # The file uses CRLF, hence the `tr -d '\r'`. recorded="$(tail -n +2 "${CSV}" | cut -d, -f1 | tr -d '\r' | ...)" Both halves are wrong. **The file is not CRLF.** `dependency-licenses.csv` has zero CR bytes. It was CRLF when the guard was written -- 111 of them at 642eacf -- and 8eb0dcf (#917) normalized it to LF while touching it for something unrelated, so the sentence has been stale since that landed. **And the `tr` would not be needed even if it were.** A CR sits immediately before the newline, which puts it in the CSV's *last* field. `cut -d, -f1` reads the first. The strip has never had anything to remove on this path. Verified rather than reasoned: converting the committed CSV to CRLF (117 CR bytes) and running the guard with the strip removed passes exactly as it does today. I first wrote this commit claiming the opposite -- that dropping the strip would report every crate as missing -- and the mutation refused to reproduce it, which is how the second error came to light. Both directions, both line endings, all four combinations agree. So the stage goes, and the comment now records why no CR handling belongs there. The same reasoning applies to the `.strip("\r")` in the example-workspace half further down, which reads `line.split(",")[0]`; that one is left alone as one concern per change. Happy to keep the `tr` as belt-and-braces instead and only fix the comment -- it costs nothing at runtime. I removed it because a line whose stated purpose is false and whose effect is nil teaches the next reader something untrue about the file format, which is how it survived this long. Verified: guard passes on the tree as committed (57 declared crates, plus the example-workspace half), and passes identically with the CSV converted to CRLF. Signed-off-by: Vyncint Ng <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Raises analyzed PTX into native pliron basic blocks with verified structure, and canonically re-emits it. Head of the #914 -> #915 -> #916 -> #917 stack: merging this lands all four.
Motivation
This makes control flow first-class IR instead of substrings, which is the foundation both near-term consumers (IKET PTX instrumentation, Tile-to-SIMT epic #96) and the long-term direct-emission path build on:
The raised form, from a real loop kernel:
Successors are real pliron block references; the back-edge is IR, not a string.
What changed (including the review fixes)
NativeCfgPlan::analyzedoes all fallible work (flatten, rename, CFG) touching nothing;materializeonly allocates the proven graphVerify: fallthrough must name the next emitted block, branch successors need a same-callable source label,brx.idxtables defined once, before use, all users agreeing.pragmais scope-sensitive now (fail-closed): pragma strings have placement-dependent meaning (a block-scopednounrollwidened to the callable is a behavior change), so nested scopes containing one refuse to flatten. Only.locstays scope-neutral, with the documented reasonterminator_prefixstring removed, mirroring feat(ptx): add structured surface dialect #915)Testing and validation
brx.idxbyte-identical.paramcall frames, the same boundary feat(ptx): analyze CFG and lexical normalization #916 enforces); no crashes, no wrong outputKnown boundary
Raising is not universal: callables with nested call-frame scopes refuse to raise rather than guess. Intended fail-closed posture; widening it is future work with its own tests.
Landing
Merging this PR lands the stack; #914, #915, #916 then close as already-fixed.