Skip to content

PTX and NVVM paths disagree on compute_XX device hints #1189

Closed

Description

@almightychang

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_hint and passes it to resolve_ptx_target_with_generated (crates/cuda-oxide-codegen/src/ptx.rs:372). That resolver considers only hints beginning with sm_; other spellings, including valid compute_XX, fall through to feature-based target selection: the hint is gated by arch_satisfies (crates/cuda-oxide-codegen/src/target.rs:1815), which resolves the string through arch_compute_capability_and_suffix (target.rs:1640, target.rs:1910-1916) and rejects anything not starting with sm_. PR refactor(codegen): parse targets once, one vocabulary owner #1184 lifts that condition into an explicit filter and pins it with a new resolve_ptx_target_ignores_compute_spelled_device_hints regression 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 as CudaArch and 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_str accepts both sm_XX and compute_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

  1. Accept and normalize both spellings on both paths. Parse a device hint once as CudaArch, then render sm_XX for LLVM/PTX consumers and compute_XX where libNVVM requires it. This makes compute_XX preserve 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 pass compute_XX and receive a feature-default target.

  2. Restrict device hints to sm_XX on both paths. Treat compute_XX as invalid at the shared input boundary. This matches the spelling produced by cargo oxide run and keeps the hint described as a device architecture rather than a libNVVM target. It would remove NVVM's current acceptance of compute_XX; a decision is also needed on whether invalid advisory hints should fail or be ignored.

  3. 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

  1. changed the title [-]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[/+] on Aug 28, 2026
  2. nihalpasham commented on Sep 3, 2026

    @nihalpasham
    Collaborator

    My call: option 2. A device hint is sm_XY[a] only, and a hint that does not parse fails loudly on both paths.

    • The hint means "the GPU in this machine". Every producer (cargo oxide run, sanitize, debug, and run's interop device builds; build/pipeline/test never detect) writes sm_XY[a] from nvidia-smi through one helper (codegen_env.rs:446, :638). compute_XX names a virtual PTX architecture (an ISA level, not a chip), so here it is a mistake, not a synonym.
    • "Advisory" covers a valid hint yielding to the feature floor (the lowest arch the kernel's features need). It does not cover swallowing garbage. PTX building sm_80 for compute_120 with no message is the silent-wrong-artifact case I reject elsewhere. CUDA_OXIDE_IKET shows the pattern: parse at the boundary, keep Invalid(value), error where the label lives (options.rs:94, iket.rs:114).
    • A third outcome: when the module has IKET ops (In-Kernel Event Tracing), pipeline.rs:209-224 copies the raw hint into the hard target, so compute_120 is honored there on both paths.
    today   CUDA_OXIDE_DEVICE_ARCH=compute_120
              PTX ............ ignored, sm_80
              NVVM ........... accepted, sm_120
              IKET present ... hard target, sm_120
    
    after   one parse (options.rs / device_codegen.rs) into a typed sm_-only hint
              sm_120 ................. both paths, "detected GPU"
              compute_120, sm_, foo .. TargetSelection error, one text, both paths
              no hint ................ feature floor, unchanged
    

    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 in cuda-target-spec (a CudaArch forgets its prefix), threaded through BackendOptions and PipelineConfig. Raise the error before the IKET promotion or it slips through as a hard target. Explicit --arch compute_XX stays 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, both sm_. 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_120 accepted on both paths, compute_120 and malformed rejected on both with one message, no-hint control, IKET + compute_ hint errors; replace resolve_ptx_target_ignores_compute_spelled_device_hints and the hint half of malformed_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?

  3. almightychang commented on Sep 3, 2026

    @almightychang
    ContributorAuthor

    @nihalpasham
    Yes, that order works for me. Thanks for the clarification on #1189.

    I'll start with #1211.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions