Skip to content

fix(codegen): reject invalid device architecture hints on both backends - #1256

Merged
nihalpasham merged 4 commits into
NVIDIA:mainfrom
almightychang:device-hint-spelling
Sep 23, 2026
Merged

nihalpasham merged 4 commits into
NVIDIA:mainfrom
almightychang:device-hint-spelling

Conversation

@almightychang

@almightychang almightychang commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes

A device hint identifies the local GPU. The PTX and NVVM paths previously treated compute_120 differently; IKET could promote the unvalidated string into an explicit target.

before: compute_120 hint -> ignored by PTX, accepted by NVVM
 after: compute_120 hint -> one input error before either backend or IKET

DeviceArch accepts sm_<capability> with an optional a suffix. The shared pipeline validates the hint before materialization, while valid hints remain advisory and explicit compilation targets retain their existing vocabulary.

Maintainer follow-up

Rebased onto current main and added an isolated-process regression proving that a supplied typed hint still overrides an invalid environment hint. Absence continues to consult the environment.

Verification

  • Codegen and target suites, importer tests, strict Clippy, formatting and warning-free docs pass.
  • Negative cases cover malformed, compute_, family and non-Unicode hints; both backends and IKET are covered.
  • All seven hosted workflows passed at 617d13f4. The IKET example passed on RTX 5090 with automatic device detection, checking 1,024 elements.

Closes #1189.

almightychang and others added 4 commits September 23, 2026 11:20
…targets

A device hint names the GPU in this machine. Preserve that distinction in a DeviceArch type: require sm_ spelling and reject family targets, whose compatibility set does not identify the detected device.

Delegate capability and suffix grammar to CudaArch, preserving explicit compute_ and family compilation targets. All in-tree detected-device spellings remain representable.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Advisory hints may yield to a feature floor; they must not silently swallow virtual architectures or malformed input. Parse once at the frontend boundary, retain invalid values for one TargetSelection diagnostic, and validate before IKET can promote the hint to a hard target.

Thread typed hints through both backends and reuse the rustc frontend value in mir-importer. Preserve explicit compute_ and family targets, no-hint feature floors, and every in-tree producer. Tests pin equal errors on both paths and the IKET ordering, including a positive control against the old source. Both 226-example container builds pass and all 624 collected artifacts are byte-identical.

Signed-off-by: Sam, Joochul Chang <[email protected]>
Construct a private validated backend view once before IKET handling. Derive its DeviceArch from the same options and remove the raw hint from downstream controls, preventing callers from pairing invalid options with an absent proof.

PTX generation and both resolvers now consume the proven hint without repeating fallible extraction. Move malformed-hint tests to shared entry and pin error precedence, real target propagation, and IKET provenance. Preserve explicit targets, feature floors, and frontend parsing.

Validation: unit suites, all-targets codegen tests, clippy, formatting, guards, and 226 compile-only examples pass. Of 624 artifacts, 623 are byte-identical; the remaining PTX declaration-order difference reproduces from unchanged baseline IR with the same llc (both hashes observed in 12 runs).
Signed-off-by: Sam, Joochul Chang <[email protected]>
@nihalpasham nihalpasham added bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Sep 23, 2026

@nihalpasham nihalpasham left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the single typed hint boundary and added a regression for caller-supplied hints overriding the environment. Invalid hints now fail before either backend or IKET promotion, while explicit compilation targets keep their existing behavior.

The codegen, target and importer suites, strict Clippy and docs pass on the rebased branch. The IKET example also passes on RTX 5090 with automatic device detection. All seven hosted workflows passed at 617d13f4.

This addresses #1189.

@nihalpasham
nihalpasham merged commit 731b5ba into NVIDIA:main Sep 23, 2026
55 checks passed
vyncint added a commit to vyncint/cuda-oxide that referenced this pull request Oct 11, 2026
Since NVIDIA#1256 the backend validates CUDA_OXIDE_DEVICE_ARCH once, at its input
boundary, and hands selection a DeviceArch: a hint that does not parse is an
error before either backend chooses a target. The three readings of a
malformed hint this stack used to pin -- the floor resolver and the PTX
selector ignoring it, the NVVM selector rejecting it -- no longer exist, so
that test was dropped rather than carried forward.

What the floor depends on now is narrower. cuda-device's build script reads
the same variable with `parse::<DeviceArch>().ok()`, so its floor matches
selection exactly when the boundary accepts the values that parse and rejects
the rest. The new test asks both about the same inputs -- valid, blank,
padded, bare, too short, virtual and family spellings -- and fails if they
disagree. Making the boundary trim its input fails it on `" sm_86"`, which
the build script would leave out while the backend selected it.

The resolver's doc no longer says malformed hints are ignored, since the
hint now reaches it parsed.

Signed-off-by: Vyncint Ng <[email protected]>
vyncint added a commit to vyncint/cuda-oxide that referenced this pull request Oct 22, 2026
Since NVIDIA#1256 the backend validates CUDA_OXIDE_DEVICE_ARCH once, at its input
boundary, and hands selection a DeviceArch: a hint that does not parse is an
error before either backend chooses a target. The three readings of a
malformed hint this stack used to pin -- the floor resolver and the PTX
selector ignoring it, the NVVM selector rejecting it -- no longer exist, so
that test was dropped rather than carried forward.

What the floor depends on now is narrower. cuda-device's build script reads
the same variable with `parse::<DeviceArch>().ok()`, so its floor matches
selection exactly when the boundary accepts the values that parse and rejects
the rest. The new test asks both about the same inputs -- valid, blank,
padded, bare, too short, virtual and family spellings -- and fails if they
disagree. Making the boundary trim its input fails it on `" sm_86"`, which
the build script would leave out while the backend selected it.

The resolver's doc no longer says malformed hints are ignored, since the
hint now reaches it parsed.

Signed-off-by: Vyncint Ng <[email protected]>
vyncint added a commit to vyncint/cuda-oxide that referenced this pull request Oct 30, 2026
Since NVIDIA#1256 the backend validates CUDA_OXIDE_DEVICE_ARCH once, at its input
boundary, and hands selection a DeviceArch: a hint that does not parse is an
error before either backend chooses a target. The three readings of a
malformed hint this stack used to pin -- the floor resolver and the PTX
selector ignoring it, the NVVM selector rejecting it -- no longer exist, so
that test was dropped rather than carried forward.

What the floor depends on now is narrower. cuda-device's build script reads
the same variable with `parse::<DeviceArch>().ok()`, so its floor matches
selection exactly when the boundary accepts the values that parse and rejects
the rest. The new test asks both about the same inputs -- valid, blank,
padded, bare, too short, virtual and family spellings -- and fails if they
disagree. Making the boundary trim its input fails it on `" sm_86"`, which
the build script would leave out while the backend selected it.

The resolver's doc no longer says malformed hints are ignored, since the
hint now reaches it parsed.

Signed-off-by: Vyncint Ng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working build-related Build scripts, toolchain discovery, or compilation setup codegen Device code-generation pipeline (Rust MIR to IR to PTX)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PTX and NVVM paths disagree on compute_XX device hints

2 participants