Repository navigation
Description
Problem
CUDA_OXIDE_DEVICE_ARCH is an advisory device-architecture hint, but its accepted spelling depends on which artifact path the pipeline takes. A compute_XX hint is ignored by the PTX path and accepted by the NVVM path. Issue #1183 covers parsing CUDA targets once and threading CudaArch through codegen, but does not decide whether these two paths should treat the same hint consistently. PR #1184 preserves the existing behavior and was asked to move that policy question to a separate issue.
CUDA_OXIDE_DEVICE_ARCH=compute_120
│
▼
BackendOptions.device_arch_hint
│
┌────────┴────────┐
│ │
▼ ▼
PTX output NVVM IR output
sm_-only gate CudaArch::from_str
│ │
▼ ▼
hint ignored hint accepted
│ │
▼ ▼
feature default normalized target
sm_80 sm_120
Current behavior
The rustc codegen entry point reads CUDA_OXIDE_DEVICE_ARCH without parsing it and places the string in PipelineConfig.device_arch_hint (crates/rustc-codegen-cuda/src/device_codegen.rs:1101-1119). BackendOptions::from_env provides the other environment-driven entry point and does the same (crates/cuda-oxide-codegen/src/options.rs:100-105). cargo oxide run normally populates this variable from detected hardware through apply_device_arch_hint (crates/cargo-oxide/src/commands.rs:6304-6319); that producer documents and emits sm_XX spellings (crates/cargo-oxide/src/commands.rs:6330-6337). A user or another frontend can nevertheless supply compute_XX directly.
After lowering, the shared pipeline forwards the hint to one of two resolvers:
- The PTX path copies
BackendOptions.device_arch_hintand passes it toresolve_ptx_target_with_generated(crates/cuda-oxide-codegen/src/ptx.rs:372). That resolver considers only hints beginning withsm_; other spellings, including validcompute_XX, fall through to feature-based target selection: the hint is gated byarch_satisfies(crates/cuda-oxide-codegen/src/target.rs:1815), which resolves the string througharch_compute_capability_and_suffix(target.rs:1640,target.rs:1910-1916) and rejects anything not starting withsm_. PR refactor(codegen): parse targets once, one vocabulary owner #1184 lifts that condition into an explicit filter and pins it with a newresolve_ptx_target_ignores_compute_spelled_device_hintsregression test. - The NVVM path passes the same hint to
resolve_nvvm_target_with_generated(crates/cuda-oxide-codegen/src/pipeline.rs:379-384). That resolver parses the hint asCudaArchand uses it when it satisfies the detected and generated requirements (crates/cuda-oxide-codegen/src/export.rs:99-150; the no-automatic-feature branch does the same at lines 158-163).CudaArch::from_straccepts bothsm_XXandcompute_XX, and its renderers produce the spelling required by each downstream consumer (crates/cuda-target-spec/src/lib.rs:15-19,67-74,88-94).
The observable result is not limited to diagnostics. For example, with a basic kernel and CUDA_OXIDE_DEVICE_ARCH=compute_120, the PTX path ignores the hint and selects its feature default, currently sm_80; the NVVM path accepts the hint as capability 120 and reports/exports target sm_120. With compute_80, both paths currently arrive at sm_80, but the PTX path reports the source as feature requirement rather than detected GPU. Invalid hints also differ: the PTX path silently ignores them, while the NVVM resolver returns a target-selection error when it attempts to parse them.
| Advisory hint (basic kernel) | PTX path | NVVM path | Observable difference |
|---|---|---|---|
sm_120 |
selects sm_120 from detected GPU |
selects sm_120 |
none in target capability |
compute_120 |
ignores hint; selects default sm_80 from feature requirement |
accepts and normalizes to sm_120 |
different compiled target |
compute_80 |
ignores hint; selects default sm_80 from feature requirement |
accepts and normalizes to sm_80 |
same target, different provenance |
| malformed spelling | silently falls back | returns TargetSelection when parsed |
fallback versus error |
Provenance
The hint behavior was introduced by commit 9955a3ef (fix(codegen): treat detected GPU arch as a hint, not a hard target). Its compatibility helper was explicitly documented to accept examples such as sm_120a and to extract the capability from an sm_… string. The normal cargo oxide run producer also emits sm_ spellings. I found no commit message, test, or comment from that change identifying different compute_XX behavior between PTX and NVVM as an intended policy.
PR #1184 makes preservation deliberate during its typed-target refactor: the resolver comment says it preserves the legacy PTX behavior, and the regression test above records it. That is evidence that changing the behavior was intentionally kept out of the refactor; it is not evidence that the original asymmetry was deliberately designed. Whether the original omission was accidental is therefore unverified.
Why decide this
The same advisory input currently selects different compilation targets solely because the pipeline emits PTX or NVVM IR. It can also turn a malformed input into either a silent fallback or an error. This makes target provenance and the generated artifact depend on output mode rather than only on the requested/detected architecture and module requirements.
Decision options
-
Accept and normalize both spellings on both paths. Parse a device hint once as
CudaArch, then rendersm_XXfor LLVM/PTX consumers andcompute_XXwhere libNVVM requires it. This makescompute_XXpreserve the user's advisory capability across output modes and matches the shared type's current grammar. It changes the PTX result for callers that currently passcompute_XXand receive a feature-default target. -
Restrict device hints to
sm_XXon both paths. Treatcompute_XXas invalid at the shared input boundary. This matches the spelling produced bycargo oxide runand keeps the hint described as a device architecture rather than a libNVVM target. It would remove NVVM's current acceptance ofcompute_XX; a decision is also needed on whether invalid advisory hints should fail or be ignored. -
Keep the path-specific behavior and document it. This has the lowest compatibility risk, but retains output-mode-dependent target selection and different malformed-input handling. The reason for exposing two accepted vocabularies would need to be made explicit because no such rationale is currently documented.
This issue is requesting a maintainer decision on the input contract and invalid-hint policy before an implementation change is proposed.
Activity
[-]Device-arch hint has no single contract: PTX and NVVM paths disagree on spelling and on malformed input[/-][+]PTX and NVVM paths disagree on `compute_XX` device hints[/+]nihalpasham commentedon Sep 3, 2026
My call: option 2. A device hint is
sm_XY[a]only, and a hint that does not parse fails loudly on both paths.cargo oxiderun, sanitize, debug, and run's interop device builds; build/pipeline/test never detect) writessm_XY[a]from nvidia-smi through one helper (codegen_env.rs:446,:638).compute_XXnames a virtual PTX architecture (an ISA level, not a chip), so here it is a mistake, not a synonym.sm_80forcompute_120with no message is the silent-wrong-artifact case I reject elsewhere.CUDA_OXIDE_IKETshows the pattern: parse at the boundary, keepInvalid(value), error where the label lives (options.rs:94,iket.rs:114).pipeline.rs:209-224copies the raw hint into the hard target, socompute_120is honored there on both paths.Since you filed this, #1184 landed with the
starts_with("sm_")filter and its "legacy" comment (select.rs:198), and its crate doc now promises one parse at the boundary. The hint is the last target input that breaks that promise, so the fix deletes a special case. The typed hint belongs incuda-target-spec(aCudaArchforgets its prefix), threaded throughBackendOptionsandPipelineConfig. Raise the error before the IKET promotion or it slips through as a hard target. Explicit--arch compute_XXstays as is; only the hint narrows.Compatibility: nothing in the repo, CI, or sibling repos writes anything but
sm_, and NVVM only sees a hint on the libdevice (NVIDIA math library) auto-switch or interop cubin crates, bothsm_. Only a hand-set env var changes, from silent to loud.PR under the criteria (https://discord.com/channels/1515530041767759993/1515561621156663487/1540970771323551775): before/after as above; tests:
sm_120accepted on both paths,compute_120and malformed rejected on both with one message, no-hint control, IKET +compute_hint errors; replaceresolve_ptx_target_ignores_compute_spelled_device_hintsand the hint half ofmalformed_low_width_targets_keep_override_errors_and_ignore_device_hints(NVVM has no test to replace); one README line on the spelling. Order across your three open asks with me, one series at a time: #1211 first (small, unblocks every nix contributor), then this one, then #1213. Does that order work for you?almightychang commentedon Sep 3, 2026
@nihalpasham
Yes, that order works for me. Thanks for the clarification on #1189.
I'll start with #1211.