Repository navigation
feat(intrinsics): probe every declared target - #1105
Conversation
Signed-off-by: Sam, Joochul Chang <[email protected]>
Signed-off-by: Sam, Joochul Chang <[email protected]>
|
nihalpasham
left a comment
There was a problem hiding this comment.
- 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+ptx78and 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_90adefault /+ptx80pass /+ptx78reject and the existingsm_103a/ PTX 8.6 near miss. - Keep derived per-target checks explicitly LLVM-selection-only; only the selected evidence target may claim terminal
ptxasvalidation. 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]>
|
Addressed the changes requested in the review:
Local caveat: CUDA 12.0 |
Signed-off-by: Sam, Joochul Chang <[email protected]>
|
The redesign lands what the review asked for, verified value for value:
The rest I handled at landing:
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. |
Signed-off-by: nihalpasham <[email protected]>
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
left a comment
There was a problem hiding this comment.
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.
Problem
probe --alllowered each intrinsic record against one target: the one itsrecorded evidence selected. Every other target the record claims was taken
on faith.
runtime; the near-miss was feat(intrinsics): add f32 redux.sync family #1032's first draft of
redux.sync.f32, whichlisted sm_120a/sm_121a even though LLVM's
hasReduxSyncF32()limits theinstruction to the Blackwell 10x family
The PTX-floor table needed to check those targets was duplicated between
cuda-oxide-codegenandcuda-intrinsics-gen, with nothing keeping eithercopy 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=+ptx78aborts with "Minimum required PTX versionis 8.0".
Fix
One owner for target policy, then exhaustive probing on top of it:
cuda-target-speccrate owns the target grammar(
CudaArch) and the PTX floors recorded against the pinned LLVM 22backend;
cuda-oxide-codegen,cuda-intrinsics-gen, andlibnvvm-sysall resolve targets through it, so the tables cannot drift apart again
Default, mustresolve to a recorded floor before compilation proceeds; unknown targets
are rejected instead of silently inheriting llc defaults
probe --per-target(CI now runsprobe --all --skip-terminal --per-target) lowers every record against every declared target withthat target's derived floor
with the one selected evidence target, and the evidence schema is
unchanged
target is lowered with no
-mattrand the emitted.versionmust matchthe table (uses the Rust toolchain's bundled llc; requires LLVM 22, since
LLVM 21 rejects several of these targets outright)
Probe coverage
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 ranagainst 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, nofailures)
cargo oxide fmt --check(root, codegen, and every example workspace)cargo oxide run vecaddend to end on an RTX 5090 (sm_120a), plus aCUDA_OXIDE_TARGET=sm_90acompile-only build emitting.target sm_90aPTX