Repository navigation
refactor(codegen): parse targets once, one vocabulary owner - #1184
Conversation
|
Reviewed as a stacked draft. The direction is sound, and I re-derived the key equivalences:
Before this leaves draft:
Small body fixes for the same pass:
We'll re-check the CUDA 13.3 ptxas evidence at validation. Labels added. |
Parse external CUDA target spellings at target resolution and retain the CudaArch witness through selection, generated-intrinsic checks, LLVM validation, final-IR validation, and PTX feature selection. Preserve target provenance, fail-closed recorded PTX floor checks, diagnostics, llc arguments, and generated probe evidence while removing internal render-and-reparse round trips. Signed-off-by: Sam, Joochul Chang <[email protected]>
Centralize PTX feature selection above a recorded target floor in the shared target-spec leaf and use it from codegen and probe derivation. Pin the derived PtxIsaRequirement ordering to the shared spelling vocabulary so max-based requirement composition stays valid. Signed-off-by: Sam, Joochul Chang <[email protected]>
Make vocabulary membership and numeric ordering properties of the shared PtxSpelling type. Represent codegen requirements as an optional spelling and thread the proven spelling through probe feature derivation. Signed-off-by: Sam, Joochul Chang <[email protected]>
Make the shared floor-table order the target-selection preference and iterate it directly in codegen. The prior candidate key-set assertion is now true by construction. Signed-off-by: Sam, Joochul Chang <[email protected]>
Use the direct cuda-target-spec path in codegen target selection while retaining the libnvvm-sys re-export for other consumers. Signed-off-by: Sam, Joochul Chang <[email protected]>
Move compare-and-render behavior onto proof-carrying PtxSpelling and route both codegen and probe consumers through it. The off-vocabulary branch disappears because invalid spellings cannot construct the receiver. Signed-off-by: Sam, Joochul Chang <[email protected]>
61cc3fe to
c66bd6d
Compare
…o the module split
Main moved and rewrote code under this PR while it sat:
PR edited main now has
--------- ------------
src/target.rs (monolith) -> src/target/{arch,features,select,
generated_requirements,detect,tests/}
llc invocation (inline) -> base_llc_args() + ptx_isa_with_debug_floor()
LLVM 22 floor comments -> LLVM 23 (nightly 2026-08-28 bump)
Conflict resolutions, all porting the PR's delta onto main's layout:
- target.rs: deleted (as on main); its PR delta is re-applied per module:
- features.rs: PtxIsaRequirement enum -> struct over Option<PtxSpelling>
- arch.rs / generated_requirements.rs / select.rs: &str arch params -> &CudaArch,
is_known_cuda_target folded into recorded_ptx_floor().is_ok()
- select.rs: candidates derived from RECORDED_PTX_FLOORS (order verified
identical to the removed KNOWN_CUDA_TARGET_CANDIDATES list)
- tests/: mechanical parse().unwrap() updates; drift test retired with the
hardcoded list; new compute_-hint test added
- ptx.rs: kept main's base_llc_args + debug-floor call, fed the PR's typed
CudaArch through it
Signed-off-by: nihalpasham <[email protected]>
…e crate doc - adds a tiny before/after visual: N parse sites -> one CudaArch owner - notes that holding a PtxSpelling is itself the vocabulary-membership proof Signed-off-by: nihalpasham <[email protected]>
…DED_PTX_FLOORS The list's entry order became load-bearing when candidates started deriving from it (selection takes the first satisfying entry), but the old unordered set-equality test was deleted with the list it compared against. One windows(2) walk freezes the contract: [ base asc ][ 'a' asc ][ 'f' asc ] preferred ------------> last resort An out-of-section insert now fails the build instead of silently reshuffling which target wins. Signed-off-by: nihalpasham <[email protected]>
|
Gave this the full review it hadn't had yet (the earlier pass only judged direction, back when the diff still bundled #1105), then rebased and validated it ourselves since the conflicts were all fallout from our module split. Your six commits are intact under your authorship; our merge commit only re-homes your The bar for a refactor is "provably no behavior change", so we proved it: Plus the full battery: workspace tests, clippy Two deliberate rejection-path tightenings ship with it (unreachable from any supported producer, and better errors): Two small things we added:
Review verdict on the whole final delta: clean. Dropping |
Measured against current main: sm_05 and sm_ produce identical TargetSelection errors as explicit overrides on both sides of the typed-target refactor, and both are ignored as device hints. Pin that equivalence so the reviewer-raised reject paths stay observable. Signed-off-by: Sam, Joochul Chang <[email protected]>
|
@nihalpasham |
Implements the direction proposed in #1183. The three boundary choices it raises -- parse at the resolution
boundary, direct import with the re-export kept, one migration rather than a staged one -- were confirmed
aligned in review.
Rebased onto main now that #1105 has landed, so the range below is this PR's own diff. The patch is
byte-identical to the pre-rebase range (same patch ID,
git range-diffmaps all six commits=).Problem 1 — targets flow as strings
Problem 2 — consumers re-encode leaf facts
Changes
CudaArchonce at the resolution boundary; resolution returns the typed value plus its source label. Internal checks take&CudaArch; rendering happens only at llc arguments and diagnostics.PtxSpelling(new, incuda-target-spec): construction proves vocabulary membership,Ordis numeric, feature rendering is total.PtxIsaRequirementwrapsOption<PtxSpelling>—.max()merges hold by construction, and the enum variants had no external consumers.RECORDED_PTX_FLOORSorder is now documented as the selection preference (existing order preserved exactly); the duplicate candidate list is deleted.Behaviour
Accepted inputs keep identical selected targets, feature strings, and error text.
Two rejection paths do change, both deliberately.
sm_05was accepted before and is now rejected(
compute capability must contain at least two digits);sm_now reportscompute capability is not a valid integerwhere it previously reported a different message. The unchanged-error-text claim holds on the acceptpaths only.
One legacy asymmetry is deliberately kept and pinned by a regression test: the PTX path ignores
compute_XXdevice hints while the NVVM path normalizes them. #1189 tracks that question rather than carrying it here.
Size and verification
+938 / −610overall across six files.-D warnings; fmt; all 13 guard scripts -- all re-run after the rebase.--all-targetspasses, bothsm_120libdevice tests executed by name. Run before the rebase, against the byte-identical patch.ptxas, not installed).Can land as one PR or split at maintainers' preference — a per-topic stack exists.