Skip to content

fix(intrinsics-gen): fail closed when an unsafe family has no safety renderer - #1153

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
almightychang:safety-guard-red
Aug 28, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
almightychang:safety-guard-red

Conversation

@almightychang

@almightychang almightychang commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #1152. The unsafe-family guard checked a hand-maintained family allowlist rather than whether render_raw_abi had a matching safety renderer, allowing CLC intrinsics to inherit the terminal packed-atomic contract. This change makes raw-ABI safety rendering fail closed and gives CLC shared safety contracts across the raw and compatibility renderers.

Changes

  • b0b57459 adds two rendered-safety invariants. At that commit they are RED: 298 existing tests pass and exactly the two new tests expose the CLC/packed-atomic collision.
  • 50a4d0b1 makes the tests GREEN by giving packed_atomic an explicit arm, returning a generation error for any unhandled unsafe family, removing the redundant mirrored allowlist, and rendering reviewed CLC contracts through one shared helper.
  • Regenerated changes in abi_v1.rs and clc.rs are doc comments only; comparison confirmed that no non-/// line changed. No catalog, ABI ledger, PTX, or lowering file is touched, so runtime/GPU validation is not applicable.

Testing

  • just check passes (the local mirror of CI: fmt, clippy, tests, CUDA-linked tests, guards, generated-intrinsic checks, rustdoc, and doctests). Exit 0 on the commits in this PR, with CUDA 12.9.86 and the pinned toolchain; 90 test binaries pass and none fail.
    • A fork-internal CI dry run of these identical commits passed all 50 applicable checks, including examples-compile, CodeQL, and the book gates; only deploy was skipped, as it is on every pull request.
  • cargo oxide run <example> passes, or scripts/smoketest.sh -o '^<example>$' (not applicable: documentation-only generated changes; no runtime, PTX, or lowering change)
  • New example added (not applicable)

Checklist

  • All commits signed off (git commit -s)
  • SPDX headers on new source files (no new source files)

Two invariants over the rendered raw-ABI # Safety blocks:

- a safety block that names `addr` must belong to a record that takes a
  pointer argument
- no two families may render the identical safety block

Both fail on main: the # Safety dispatch in render_raw_abi silently falls
back to the packed-atomic contract for families without a dedicated arm,
so the six clc_* intrinsics document a four-byte global atomic they do
not perform, and four of them take no pointer at all.

    unsafe safety docs reference `addr` without a pointer argument:
      clc_query_get_first_ctaid_x, clc_query_get_first_ctaid_y,
      clc_query_get_first_ctaid_z, clc_query_is_canceled
    unsafe safety blocks shared across families: [{"clc", "packed_atomic"}]

Signed-off-by: Joochul Chang <[email protected]>
…renderer

The unsafe-record guard in validate_renderable only checked that a family
name appeared in a hand-maintained allowlist, while the # Safety dispatch
in render_raw_abi silently fell back to the packed-atomic contract for
any family without a dedicated arm. Adding an allowlist line was enough
to pass the guard, which is how the clc family shipped six intrinsics
carrying a four-byte global-atomic contract they do not perform.

Give packed_atomic an explicit arm and make the terminal else a
generation error naming the record and family, so a family missing from
the dispatch can no longer inherit another family's contract. Delete the
allowlist: the per-family shape checks it duplicated remain, and the
dispatch itself is now the single source of truth.

Add a dedicated clc arm. Its contracts are shared with render_compat_clc
through clc_safety_lines, so the raw and compatibility renderers cannot
drift, and they now state the obligations the repository already
documents: the 16-byte shared::cta response and its expect-tx arming, the
prohibition on retrying after an observed failed cancellation, and that
the query results are meaningful only after a successful cancellation.

Signed-off-by: Joochul Chang <[email protected]>
@almightychang
almightychang marked this pull request as draft August 23, 2026 15:36
@almightychang
almightychang marked this pull request as ready for review August 23, 2026 15:48
@nihalpasham

nihalpasham commented Aug 28, 2026 •

Copy link
Copy Markdown
Collaborator

Verified end to end. On main only packed_atomic and clc reach the silent catch-all, so the six CLC intrinsics really did ship an atomic contract they never perform:

before: clc record -> no arm -> catch-all -> packed-atomic "# Safety" text
after:  clc record -> clc arm -> reviewed CLC contract
        unknown unsafe family -> hard error naming the record
  • allowlist deleted, dispatch is the single source of truth; the checks that made it redundant stay in validate_renderable
  • every line of the new CLC prose matches the PTX ISA clusterlaunchcontrol section
  • the two catalog-wide tests fail on main with the CLC collision and pass here

Two notes, neither blocking:

  • the duplicate-block test forbids identical text across families even when legitimately shared; a future shared contract needs distinct wording or a test tweak
  • no direct negative test hits the new bail path; the catalog invariants cover recurrence

CI is approved on the newest head. The #1152 contract-depth question stays a separate decision. Labels added.

@nihalpasham nihalpasham added bug Something isn't working intrinsics Device intrinsics and libdevice math mappings labels Aug 28, 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.

Verified on the merged tree with #1105 in: generator tests green, generated outputs byte-current; CI green. Merging.

@nihalpasham
nihalpasham merged commit c976f04 into NVIDIA:main Aug 28, 2026
51 checks passed
@almightychang
almightychang deleted the safety-guard-red branch September 15, 2026 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working intrinsics Device intrinsics and libdevice math mappings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda-intrinsics-gen: unsafe families without a safety renderer inherit the packed-atomic contract

2 participants