Repository navigation
codegen: attribute target selection to whoever chose the target - #416
Conversation
A rejected target produced an error naming CUDA_OXIDE_TARGET, and classified
the failure as a codegen stage failure. Both were wrong for every caller
that reaches target selection by some other route.
resolve_ptx_target hardcoded "CUDA_OXIDE_TARGET" as the provenance of any
explicit override, because the env-driven rustc pipeline was once the only
caller. The standalone experimental API passes a Target the caller built in
Rust and never touches the environment, so a caller who requested sm_75 for
a module needing sm_80 was told to go and look at an environment variable
they had never set. BackendOptions now carries target_arch_source alongside
target_arch, and resolve_ptx_target reports the label it was given.
mir-importer's PipelineConfig carries the same label, defaulting to
PipelineConfig::target_arch and set to CUDA_OXIDE_TARGET by
rustc-codegen-cuda, which reads that variable itself. Previously the
config-level override replaced target_arch and left from_env's label behind,
which reproduced the same mis-attribution one layer up.
The merge of environment and config options moves into backend_options_for
so this precedence is testable without running a compilation.
Target and feature-floor rejections were reported as
PipelineError::PtxGeneration, so the standalone API mapped them to
CompilationStage::Codegen. They are decided before llc is reached and
describe the caller's request, so they now travel as
PipelineError::TargetSelection and land in CompilationStage::Input.
CompileError gains a matching TargetSelection variant. InvalidTarget renders
as "invalid CUDA target `{target}`: {reason}", which suits a parse failure
from Target::parse and misdescribes a feature-floor rejection: sm_75 is a
valid architecture, and the reason text already names it, so routing
feature-floor failures through InvalidTarget called a valid target invalid
and printed the architecture twice. TargetSelection renders its reason alone,
which is already phrased for a user. InvalidTarget keeps its parse-failure
meaning and its rustdoc now points at the new variant.
target_arch_source stays &'static str. Every label in the tree is a fixed
string. Widening it to Cow<'static, str>, which would let a caller build a
label carrying the target text itself, can wait until a caller needs one.
Signed-off-by: Alejandro Soto Franco <[email protected]>
The provenance label was threaded through but only printed on the verbose success path; rejected targets still gave env/--arch users no pointer to the knob that chose the target. Interpolate it into the parse-failure, feature-floor, and generated-floor reasons, and stop double-wrapping the parser's own 'invalid CUDA target' prefix.
|
LGTM, the I pushed one follow-up: the provenance label was threaded through but only printed on the verbose success path, so env and One follow-up to track separately: the NVVM-IR path's resolver still reports target rejections as |
nihalpasham
left a comment
There was a problem hiding this comment.
Validated; see merge comment.
The NVVM IR resolver returned PipelineError::Export for every failure, so a target the caller requested and the compiler refused was reported as an export failure. The PTX resolver already routes the same rejections through TargetSelection, which reaches the caller as CompilationStage::Input. Classify the rejections the NVVM IR route attributes to a target the same way: an unparsable explicit target or device hint, a target below a detected feature floor, a target below a generated intrinsic floor, and the case where nothing supplied a target at all. Failures that belong to the export keep reporting as Export. select_target_with_generated fails when no target satisfies the module, which the PTX resolver also classifies away from Input, and the PTX ISA catalogue floor is a compiler capability limit decided before any target is chosen. Follow-up to #416. Signed-off-by: Alejandro Soto Franco <[email protected]>
One of three parts of #357, split so each can be reviewed on its own. #357 bundled eight unrelated fixes across 12 files, which put the small ones behind a dependency discussion. The three parts are independent: each applies cleanly to
mainalone, and they merge cleanly in any order. #357 will be closed once all three are open.Sibling parts: #415 (clone, liveness and diagnostic paths), #417 (scratch directory on tempfile).
Summary
A rejected target produced an error naming
CUDA_OXIDE_TARGET, and classified the failure as a codegen stage failure. Both are wrong for every caller that reaches target selection by some other route.Changes
BackendOptionscarriestarget_arch_sourcealongsidetarget_arch, andresolve_ptx_targetreports the label it was given.PipelineConfigcarries the same label, defaulting toPipelineConfig::target_archand set toCUDA_OXIDE_TARGETbyrustc-codegen-cuda, which reads that variable itself.backend_options_for, so the precedence is testable without running a compilation.PipelineError::TargetSelectionand land inCompilationStage::Input.CompileErrorgains a matchingTargetSelectionvariant.tests/target_provenance.rs, plus threemir-importertests over the label precedence.Rationale
resolve_ptx_targethardcoded"CUDA_OXIDE_TARGET"as the provenance of any explicit override, because the env-driven rustc pipeline was once the only caller. The standalone experimental API passes aTargetthe caller built in Rust and never touches the environment, so a caller who requestedsm_75for a module needingsm_80was told to go and look at an environment variable they had never set.The same mis-attribution existed one layer up:
PipelineConfig::target_archreplacedtarget_archand leftfrom_env's label behind, so a caller setting the config field directly was still blamed on the environment. That is fixed here too, which is the only in-tree site that needed the new mechanism.Target and feature-floor rejections are decided before
llcis reached and describe the caller's request, soCodegenwas the wrong stage for them.CompileError::TargetSelectionis a new variant rather than a reuse ofInvalidTarget.InvalidTargetrenders asinvalid CUDA target `{target}`: {reason}, which suits a parse failure fromTarget::parseand misdescribes a feature-floor rejection:sm_75is a valid architecture, and the reason text already names it, so routing feature-floor failures throughInvalidTargetcalled a valid target invalid and printed the architecture twice.TargetSelectionrenders its reason alone, which is already phrased for a user.InvalidTargetkeeps its parse-failure meaning and its rustdoc now points at the new variant.target_arch_sourcestays&'static str. Every label in the tree is a fixed string. Widening it toCow<'static, str>, which would let a caller build a label carrying the target text itself, can wait until a caller needs one.Validation
cargo check --workspace --all-targetscargo test -p cuda-oxide-codegen(123 passed)cargo test -p mir-importer(804 passed)cargo clippy --workspace -- -D warningscargo clippy -p mir-importer --all-targets -- -D warningscargo fmt --all -- --check(cd crates/rustc-codegen-cuda && cargo fmt --all -- --check)(cd crates/rustc-codegen-cuda && cargo check), since this adds a field to aPipelineConfigliteral indevice_codegen.rsand that crate is excluded from the workspaceRUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace