Skip to content

debug: describe AS1 device globals - #1128

Merged
nihalpasham merged 2 commits into
mainfrom
feat/debug-as1-device-globals
Aug 28, 2026
Merged

nihalpasham merged 2 commits into
mainfrom
feat/debug-as1-device-globals

Conversation

@nihalpasham

@nihalpasham nihalpasham commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Ordinary Rust device statics now keep their source name and Rust type all the
way to the generated AS1 storage, so cuda-gdb can inspect them by their
qualified name.

Before
debuginfo::GLOBAL_COUNTER ──> @__device_global_0 ──> no DWARF name/type
cuda-gdb: No symbol

After
debuginfo::GLOBAL_COUNTER ──> @__device_global_0 + DIGlobalVariable
cuda-gdb: @global u64 = 0

Closes #1120.

Changes

  • Carry the source leaf, namespace, definition span, locality, and semantic
    Rust type through the full-debug pipeline.
  • Use an exact tagged mangled identity for storage, relocations, and debug joins
    so same-leaf statics and promoted constants cannot collide.
  • Emit retained AS1 global DWARF with the generated symbol as linkageName.
  • Fail closed per unsupported type without removing the real global.

Qualified lookup is the correctness boundary. Unqualified lookup is contextual
in cuda-gdb; AS3 shared and AS4 constant-memory debug metadata stay separate.

Testing

  • Importer, lowering, exporter, backend, strict Clippy, LLVM-verifier, and
    debug-mode checks passed on ac0282c4.

  • Final head a57bc934 only formats the device-global example; the exact
    per-example formatter gate now passes.

  • CUDA 13.3 / RTX 5090: debuginfo::GLOBAL_COUNTER is @global u64 = 0.

  • Same-leaf and opposite-block controls keep distinct values, addresses,
    relocations, and DIEs; repeated references deduplicate.

  • just check passes (affected suites and validators pass)

  • Live GPU debugger regression exercised

  • New example added (existing device-global example extended)

Checklist

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

Questions about the review? Ping us in #contributors on Discord.

@nihalpasham nihalpasham added enhancement New feature or request debug info Debug information in generated PTX/IR (line/source maps) codegen Device code-generation pipeline (Rust MIR to IR to PTX) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) labels Aug 21, 2026
@nihalpasham nihalpasham mentioned this pull request Aug 21, 2026
4 of 5 tasks
Reworked onto main's #1186 device-global declaration cache: debug
identity rides DeviceGlobalDeclaration as an equality-checked field
instead of a parallel record type, the promoted-key fingerprint keeps
main's align component under the domain tag, and the encoder covers
the TypedPointer debug type from #1126.

Signed-off-by: nihalp <[email protected]>
…storage

#1186 tightened classify_union_constant_storage so SharedRef union
alternatives with different pointee types fail closed. That is right
for SSA reconstruction, which mints the carrier field's own reference
type and could claim validity for a pointee the program never wrote.
But the device-static initializer gate shares the classifier while
emitting only exact bytes plus one integer-width relocation slot; no
typed reference is ever minted, and device code reads the storage
through its own field types.

Release builds hid the regression because optimized MIR folds the
example's union load away; any unoptimized device build (including
CUDA_OXIDE_DEBUG=full) materializes the static and failed to compile
device_global's documented union { word: &'static u32, byte: &'static u8 }
shape. Thread a UnionConstantUse through the classifier so the SSA path
keeps the pointee-identity rejection and the physical-storage gate does
not, and cover the SharedRef mixed-pointee shape at both call sites.

Signed-off-by: nihalp <[email protected]>
@nihalpasham
nihalpasham force-pushed the feat/debug-as1-device-globals branch from a57bc93 to c404327 Compare August 28, 2026 11:47
@nihalpasham
nihalpasham marked this pull request as ready for review August 28, 2026 12:05
@nihalpasham
nihalpasham merged commit 60cee76 into main Aug 28, 2026
51 checks passed
@nihalpasham

Copy link
Copy Markdown
Collaborator Author

Notes from the rebase onto post-#1186 main, for the record. The rework went beyond conflict resolution in three ways:

1. Latent #1186 regression found and fixed here. Full-debug builds of this PR's own device_global example failed on main before this landed:

union RelocatedPointerUnion { word: &'static u32, byte: &'static u8 }  // documented example

release build:      compiles (MIR opts fold the load away)
CUDA_OXIDE_DEBUG=full: "initializer cannot preserve pointer provenance:
                        ... mixes reference pointee types"   <- #1186's classifier

The rejection is load-bearing on the SSA-reconstruction path (it mints a value of the carrier field's reference type) but was firing on the physical-storage path too, where no typed reference is ever created: the static lowers to raw bytes plus one integer relocation slot, and provenance rides the relocation symbolically (ptrtoint (addrspacecast (getelementptr @target, addend)))). The classifier now takes a usage flag: reconstruction keeps the rejection, storage does not. Verified adversarially down to the emitted IR/PTX; negative tests cover both paths.

2. Structure folded into #1186 instead of duplicating it. #1186 independently landed DeviceGlobalRecord/DeviceGlobalDeclaration with equality-based cache validation, so this PR's parallel record and validator were dropped; debug identity is now a debug_info field on main's declaration and rides the existing equality check. The promoted-key fingerprint wrapper follows main's new alignment-carrying format.

3. Small #1126 catch-up: type_is_bounded in the debug-info encoder gained the TypedPointer arm (recurses into the pointee), required to compile against the new debug-type node.

Follow-ups noted, not blocking: (a) the mixed-union rejection on the SSA path is covered at unit level only; an end-to-end negative driving translate_union_constant_from_alloc would keep a future flag-flip honest. (b) Pre-existing and unrelated: GPU-less target detection falls back to sm_80, which can't hold this example's pointer initializers (needs PTX ISA 7.1), so CUDA_OXIDE_TARGET matters on GPU-less machines.

@nihalpasham
nihalpasham deleted the feat/debug-as1-device-globals branch August 28, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) debug info Debug information in generated PTX/IR (line/source maps) enhancement New feature or request IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full debug: describe ordinary Rust device globals (AS1)

1 participant