Skip to content

feat(intrinsics): probe every declared target - #1105

Merged
nihalpasham merged 17 commits into
NVIDIA:mainfrom
almightychang:probe-per-target
Aug 28, 2026
Merged

nihalpasham merged 17 commits into
NVIDIA:mainfrom
almightychang:probe-per-target

Conversation

@almightychang

@almightychang almightychang commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem

probe --all lowered each intrinsic record against one target: the one its
recorded evidence selected. Every other target the record claims was taken
on faith.

record:  clc_try_cancel_multicast
claims:  sm_100a  sm_101a  ...
probed:  sm_100a  (evidence target only)
  • 395 of 1,016 records declare more than one target
  • 1,349 record/target combinations never touched llc
  • a bad target claim only surfaced if driver ptxas happened to reject it at
    runtime; the near-miss was feat(intrinsics): add f32 redux.sync family #1032's first draft of redux.sync.f32, which
    listed sm_120a/sm_121a even though LLVM's hasReduxSyncF32() limits the
    instruction to the Blackwell 10x family

The PTX-floor table needed to check those targets was duplicated between
cuda-oxide-codegen and cuda-intrinsics-gen, with nothing keeping either
copy honest. Measuring both against the pinned backend found one real error:
sm_90a recorded a PTX 7.8 floor (inherited from sm_90), but
llc -mcpu=sm_90a -mattr=+ptx78 aborts with "Minimum required PTX version
is 8.0".

Fix

One owner for target policy, then exhaustive probing on top of it:

  • new dependency-free cuda-target-spec crate owns the target grammar
    (CudaArch) and the PTX floors recorded against the pinned LLVM 22
    backend; cuda-oxide-codegen, cuda-intrinsics-gen, and libnvvm-sys
    all resolve targets through it, so the tables cannot drift apart again
  • codegen fails closed: every PTX requirement, including Default, must
    resolve to a recorded floor before compilation proceeds; unknown targets
    are rejected instead of silently inheriting llc defaults
  • probe --per-target (CI now runs probe --all --skip-terminal --per-target) lowers every record against every declared target with
    that target's derived floor
  • derived targets are LLVM-selection-only; terminal ptxas evidence stays
    with the one selected evidence target, and the evidence schema is
    unchanged
  • the recorded floors are tested against the backend itself: each recorded
    target is lowered with no -mattr and the emitted .version must match
    the table (uses the Rust toolchain's bundled llc; requires LLVM 22, since
    LLVM 21 rejects several of these targets outright)
  • sm_90a's floor is corrected to PTX 8.0

Probe coverage

             llc runs    target claims checked
before          1,016    1,016 / 2,365   (43%)
after           2,365    2,365 / 2,365  (100%)

The exhaustive run found no live target-selection bug in the catalog; the
sm_90a floor was the only disagreement. Warm local timing for the probe
step: 7.4s before, 13.8s after.

Validation

  • cargo test -p cuda-target-spec -p cuda-oxide-codegen -p libnvvm-sys -p cuda-intrinsics-gen (all green; the floor-derivation tests ran
    against the toolchain's LLVM 22.1.2 llc, not skipped)
  • cargo run -p cuda-intrinsics-gen -- check (generated outputs current)
  • cargo run -p cuda-intrinsics-gen -- probe --all --skip-terminal --per-target (2,365 target configurations across 1,016 routes, no
    failures)
  • cargo oxide fmt --check (root, codegen, and every example workspace)
  • status/naming/license guard scripts and all three cargo-deny workspaces
  • cargo oxide run vecadd end to end on an RTX 5090 (sm_120a), plus a
    CUDA_OXIDE_TARGET=sm_90a compile-only build emitting .target sm_90a
    PTX

@nihalpasham nihalpasham added enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings codegen Device code-generation pipeline (Rust MIR to IR to PTX) tests Adds or improves test coverage build-related Build scripts, toolchain discovery, or compilation setup needs-implementation labels Aug 23, 2026
@nihalpasham

nihalpasham commented Aug 23, 2026 •

Copy link
Copy Markdown
Collaborator

@nihalpasham nihalpasham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Benefit: probing every declared target closes a real CI-correctness gap: an unsupported target/PTX pair can otherwise pass on one valid selected target and fail only for users of another target. That prevention benefit is worth adding; it is not a runtime-performance change.
  • Blocker: the probe copies production's target → PTX policy, creating two authorities. The copy is already wrong for sm_90a: pinned LLVM rejects +ptx78 and requires PTX 8.0, so the new check can report a false green.
  • Required design: move the policy into one small dependency-free component used by both production codegen and the probe. Unknown or malformed targets must fail closed; neither consumer should keep a private fallback table.
  • Required tests: derive every supported target's default/minimum against the pinned LLVM binary, including sm_90a default / +ptx80 pass / +ptx78 reject and the existing sm_103a / PTX 8.6 near miss.
  • Keep derived per-target checks explicitly LLVM-selection-only; only the selected evidence target may claim terminal ptxas validation. Re-run the full 2,364-configuration probe and all inventory, license, CI-matrix, clippy, and docs guards after the redesign.

`target_minimum_ptx_isa` drops the architecture suffix for capability 90, so
`sm_90a` inherits `sm_90`'s PTX 7.8 floor. The pinned backend disagrees:
`llc -mcpu=sm_90a -mattr=+ptx78` aborts with "Minimum required PTX version is
8.0", and the default configuration emits `.version 8.0`.

No incorrect lowering follows from the wrong value today. It is used only as
the threshold below which an explicit `+ptxNN` is redundant, so understating it
can only widen the range that emits a feature. `PtxIsaRequirement` has no
spelling between 7.8 and 8.0, leaving that widened range empty. The recorded
floor is still wrong, and the next target whose suffix shifts the floor further
would not be masked.

Measuring all 28 targets the table records against the pinned backend found
this as the only disagreement. That measurement is now a test: each target is
lowered with no `-mattr` and its emitted `.version` is compared against the
recorded floor, so the copy cannot drift from the backend it describes.

The suffix-sensitive cases already carried assertions for sm_100a, sm_100f,
sm_120a, sm_120f, and sm_121a. sm_90a was the one omission, which is why the
disagreement survived.

Signed-off-by: Sam, Joochul Chang <[email protected]>
The floor table in this crate and the one in `cuda-intrinsics-gen` describe the
same backend behaviour, and nothing prevented them from drifting apart. The
probe copy is now derived from the pinned backend; this gives the production
copy the same guard, so a wrong entry fails here rather than reaching a user.

The two copies stay separate. Sharing them means a new dependency-free crate,
which pulls in workspace, licence, and CI-matrix changes this branch should not
carry. Derivation removes the failure mode that duplication actually causes.

The check runs only against an LLVM 22 backend. LLVM 21 refuses several of
these targets outright, so its defaults cannot stand in for the table.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Keep target grammar and LLVM 22-derived PTX floors in one dependency-free crate so production codegen and probe orchestration cannot drift. libnvvm-sys preserves its public re-export, while backend-version support remains consumer-owned.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Resolve explicit PTX requirements through the shared target policy so unlisted and formerly wildcard-only targets cannot silently inherit llc defaults. Preserve LLVM-major gating and requirement merging while sharing the discrete PTX spelling round-up.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Parse derived targets and resolve their LLVM 22 floors through cuda-target-spec so the probe has no fallback policy of its own. Round instruction floors to production llc spellings while preserving LLVM-selection-only derived checks and terminal validation for selected evidence.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Record the shared leaf in rustc-codegen-cuda's separate lockfile and the repository license inventory so locked verification and policy gates remain reproducible.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Make every PTX requirement, including Default, prove that its target has a recorded floor before codegen proceeds. Reuse the shared key set for known-target admission while preserving the explicit candidate preference order, and test both set parity and complete feature rendering.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Restore the CUDA architecture rationale that was lost when parsing moved into the leaf crate, and document exact LLVM 22 floor and spelling semantics at the authority boundary. Require both backend rejection tests to prove the expected minimum-version diagnostic.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Keep the explicit f8f6f4 and Blackwell ldmatrix admission sets while deriving their effective PTX values from the shared LLVM 22 floor authority. Parse evidence targets through CudaArch first, then retain the existing canonical spelling and width restrictions.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Express the LLVM 21 backend limitation through the shared PTX 9.0 floor fact instead of a private capability list. Preserve this validator as a backend-support check only: malformed, unknown, and non-sm targets continue to be handled elsewhere.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Let consumers move directly from validated capability parts to CudaArch and from shared PTX spellings to llc features. These inverse mappings belong beside the leaf invariants and vocabulary, eliminating representation round trips while preserving the accepted grammar and emitted strings.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Use the target-spec construction and PTX feature mapping APIs at policy boundaries. This removes format-and-reparse and duplicated feature rendering while preserving admitted targets, floors, and emitted strings.

Signed-off-by: Sam, Joochul Chang <[email protected]>
@almightychang

almightychang commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@nihalpasham

Addressed the changes requested in the review:

  • Single policy component: cuda-target-spec is now the dependency-free owner of CUDA target parsing, exact LLVM 22 target-to-PTX floors, and supported PTX feature spellings; production codegen and the probe both consume it (f1955637, 38f872dc).
  • Fail closed / no private fallbacks: malformed and unrecorded targets, including Default requirements, now fail before codegen, and the remaining consumer-local floor/feature tables and format/reparse detours were removed (787e256c, aed7ebda).
  • Backend-derived coverage: leaf tests check every recorded target's default/minimum against the pinned LLVM 22.1.2 llc, including sm_90a default 8.0 / +ptx80 pass / +ptx78 reject and sm_103a default 8.8 / +ptx86 reject / +ptx88 pass (f1955637, with the original correction in 5055ecae).
  • Evidence attribution: derived per-target checks remain explicitly LLVM-selection-only; only the selected evidence target claims terminal ptxas validation (38f872dc).
  • Verification: reran all crate tests (including 300 cuda-intrinsics-gen tests), the full 2,364-configuration probe across 1,015 routes, generated-output checking, clippy with warnings denied, formatting/docs checks, and the inventory, SPDX, dependency-license, and CI-matrix guards; all passed.

Local caveat: CUDA 12.0 ptxas predates sm_120, so the two pre-existing libdevice_linking integration tests for sm_120 cannot pass locally; this branch does not touch them, and CI covers them with a current toolkit.

@nihalpasham

nihalpasham commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

The redesign lands what the review asked for, verified value for value:

  • cuda-target-spec is the one owner of grammar + PTX floors, used by production codegen, the probe, the resolver, and libnvvm-sys
  • floor table matches the deleted copy except the intended sm_90a 7.8 -> 8.0 fix; known-target set unchanged; unknown targets fail closed
  • backend-derived tests check every floor against the pinned LLVM 22 llc (sm_90a reject/pass pair, sm_103a near miss)
  • production llc invocations behave the same for every reachable target
  • per-target probing covers all declared configurations (2,365 across 1,016 routes on the merged tree; feat(intrinsics): add ex2 approximate f16 #1104 added a route since the PR body was written)

The rest I handled at landing:

  • refreshed the PR description (it still described the superseded first draft, and it becomes the squash body)
  • rebased onto current main and regenerated the example lockfiles
  • full validation: per-target probe, generated-output check, ABI history, guard scripts, workspace tests

Sequencing: #1184 stacks on this and currently bundles it. This lands first; #1184 then rebases down to its own diff. Dropping the stale needs-implementation label.

The merge from main brought in two new examples (ptr_without_provenance,
shared_debug) whose lockfiles predate libnvvm-sys's cuda-target-spec
dependency. Re-resolve them the same way the branch refreshed the other
217 example lockfiles.

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

@nihalpasham nihalpasham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redesign verified value for value on the merged tree (2,365-config per-target probe, llc-derived floors, end-to-end 5090 run); supersedes the earlier changes-requested review. Merging.

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 codegen Device code-generation pipeline (Rust MIR to IR to PTX) enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants