Skip to content

perf(cute): speed up the CuTe verifier's provenance analysis - #1648

Merged
nihalpasham merged 5 commits into
NVIDIA:mainfrom
juliankang4:perf/cute-verifier-linear
Nov 3, 2026
Merged

nihalpasham merged 5 commits into
NVIDIA:mainfrom
juliankang4:perf/cute-verifier-linear

Conversation

@juliankang4

@juliankang4 juliankang4 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What This PR Does

Speeds up dialect-cute's whole-module semantic provenance verifier from $O(N^3)$ to linear $O(N)$ time without changing any accepted/rejected kernel or diagnostic:

  1. Skip Unused Stories (cfg.rs, scheduler.rs, pipeline.rs, mma.rs): scope_has_any skips building fixed-point provenance tables when a function has no operations from that semantic family.
  2. Nested Carrier Map (provenance.rs): Indexes OrdinaryFacts as HashMap<Value, HashMap<Vec<u32>, HashSet<F>>> so entries and copy_entries look up a carrier in $O(1)$ instead of scanning every (Value, path) entry in the function.
  3. Cached LocalCells & Capped Opaque Facts (provenance.rs): Precomputes local_cell_is_closed once per mir.alloca in the scope and keeps at most 2 opaque (Unknown / Scalar) facts per path (sufficient to trigger len() != 1 merge rejection without unbounded set growth).
BEFORE (200-block function / 1,600 store-load pairs):
  Flat CarrierKey scan + per-access alloca walk + uncapped Unknown sets ──► 37.6 s / 30.5 s (cubic)

AFTER (nested Value map + cached LocalCells + 2-opaque-fact cap + scope_has_any):
  O(1) carrier lookup + single alloca walk + bounded sets               ──► 0.018 s / 0.058 s (~2,000x faster)

Verification

  • cargo test -p dialect-cute --all-targets: 101/101 PASS (93 lib tests + global_store, public_paths, and sm100_attention).
  • just fmt-check, cargo clippy -p dialect-cute --all-targets -- -D warnings, and repository guards: PASS

Closes #1647

`OrdinaryFacts` kept one flat map keyed by (value, field path), so
`entries(value)` scanned every key in the map. The ordinary plumbing
and the poison pass call it for every cast, aggregate, store, load and
block argument of a scope, which made each sweep quadratic in the
scope's size.

Key the facts by SSA value first and by field path second. `entries`,
`at_path` and `copy_entries` now touch only the named carrier, and
`copy_entries` still forwards a snapshot of the source taken before
the copy. The shared-MMA use closure walks the nested map and tests
scope membership through a set instead of a linear search.

Signed-off-by: juliankang4 <[email protected]>
…tions

The scheduler, pipeline and shared-MMA stories built their provenance
facts for every scope, including every function with no CuTe operation
at all. Each analysis seeds every integer value of the scope, so this
cost was paid for every ordinary kernel.

Return before building the facts when the scope holds no operation of
the story's family. Every check in those stories starts from such an
operation, so a scope without one was already accepted after the
analysis; consumer-only (malformed) stories still reach their checks
because their operations belong to the family.

Signed-off-by: juliankang4 <[email protected]>
Seeding gives every factless integer value an origin that names the
value itself (`Unknown`, and `Scalar` for shared MMA). Propagation
merges those origins through block arguments and closed local cells,
so a value's set grew with the length of every chain that reaches it,
and each sweep of the fixed point copied the grown sets: verification
time grew with the cube of the scope size.

Consumers read a set only through its size, its sole origin, or whether
it holds a given semantic origin, and they skip opaque origins when
walking a set. Two opaque origins therefore report a merge exactly as
any larger number does. `insert_path` now drops a third one, through a
`CarrierFact` trait that each family's fact type implements. Path
presence and semantic origins are unchanged, so every accept or reject
decision and the diagnostic each consumer reports stay the same.

Tests cover the cap, the snapshot copy, a scheduler state carried
through 48 blocks and cells, and the rejection wording for cursors that
merge one to eight unrelated values.

Signed-off-by: juliankang4 <[email protected]>
Every load and store that forwards provenance through a closed local
cell called `local_cell_is_closed`, which walks all uses of the cell
and its aliases. A cell with N accesses therefore cost N walks of N
uses on every fixed-point sweep, so verification time grew with the
square of the number of accesses to one cell.

The verifier does not change the IR it reads, so a cell's closedness
is fixed for the whole analysis. `LocalCells` walks the alias graph of
each `mir.alloca` in the scope once, and the scheduler, pipeline and
shared-MMA fact builders, the shared-MMA use closure and the epilogue
plumbing check look cells up there. A cell allocated outside the scope
is still walked on demand, so every answer is the one the walk gives.
The ordinary plumbing and the poison pass also read each incoming
edge's successor operands once per block instead of once per block
argument.

A new test compares the table with the alias walk for closed, aliased
and escaped cells, with and without their allocations in the scope.

Signed-off-by: juliankang4 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@midagedev

Copy link
Copy Markdown
Contributor

Tested on bloomery, a crate of large SIMT kernels with no CuTe operation, on its own box. Cold release build of one binary: 9df9e7c alone did not finish in 1700 s; with this PR, 480 s (388 s at 0143af5, before #1598). The PTX of 809 kernel entries is identical to a build that skips the verifier in scopes without CuTe operations. A block-chain probe with no CuTe operation verifies in 0.006 s at 800 blocks and 0.050 s at 8000.

midagedev added a commit to midagedev/bloomery that referenced this pull request Oct 26, 2026
…used by name without it; host flags generated per triple

tools/oxide-backend.sh applies tools/oxide-backend/cuda-rust-1648.patch to a copy of the pin's checkout, builds the
backend and records the patch's sha256 in PROVENANCE; tools/oxide-host.sh checks it before every cargo oxide build and
writes .cargo/cuda-oxide.toml's flags from .cargo/config.toml's table for the target triple, with the llc major check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
midagedev added a commit to midagedev/bloomery that referenced this pull request Oct 26, 2026
…used by name without it; host flags generated per triple

tools/oxide-backend.sh applies tools/oxide-backend/cuda-rust-1648.patch to a copy of the pin's checkout, builds the
backend and records the patch's sha256 in PROVENANCE; tools/oxide-host.sh checks it before every cargo oxide build and
writes .cargo/cuda-oxide.toml's flags from .cargo/config.toml's table for the target triple, with the llc major check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nihalpasham nihalpasham added cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book perf Performance of generated code or of the compiler itself cute-rs CuTe and CUTLASS Primitives in Rust (cute-rs, cutlass-primitives, dialect-cute, MLIR export) labels Oct 29, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

/ok to test 42c30cd

@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks, indexing OrdinaryFacts by Value, caching LocalCells per scope, capping opaque merge facts at 2, and skipping stories when scope_has_any is false turns the cubic fixed-point blowup into linear time while preserving all verifier diagnostics.

At 42c30cd0, all 101 dialect-cute unit and integration tests, clippy, and guard checks pass. Merging once CI is green.

@nihalpasham
nihalpasham merged commit 44a85d3 into NVIDIA:main Nov 3, 2026
77 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda-oxide SIMT programming model: rustc backend, cargo oxide, cuda-device, cuda-host, book cute-rs CuTe and CUTLASS Primitives in Rust (cute-rs, cutlass-primitives, dialect-cute, MLIR export) perf Performance of generated code or of the compiler itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dialect-cute: verify_cute_semantics takes cubic time on a function with no CuTe operation

3 participants