Skip to content

Add line-table debug metadata - #225

Merged
nihalpasham merged 3 commits into
mainfrom
debug-info-metadata-allocator
Jun 15, 2026
Merged

nihalpasham merged 3 commits into
mainfrom
debug-info-metadata-allocator

Conversation

@nihalpasham

@nihalpasham nihalpasham commented Jun 15, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This adds the first useful slice of device debug info: line tables. It carries rustc spans into pliron locations, emits the minimal LLVM debug metadata needed by NVPTX, and wires the debug gate through rustc -C debuginfo plus a CUDA_OXIDE_DEBUG override.

Concretely:

  • decode MIR spans into Location::SrcPos instead of stringifying them
  • add a shared metadata ID allocator for NVVM + debug metadata
  • emit DIFile, DICompileUnit, DISubprogram, DILocation, !llvm.dbg.cu, and debug module flags
  • attach !dbg to function definitions and real LLVM instructions
  • keep constants, virtual ops, synthesized PHIs, and variable/type debug info out of this first pass
  • keep missing call spans valid for LLVM inlining by falling back to the containing function line

Closes #224.
Closes #105.

Follow-up for full variable/type debug metadata: #226.
Related: #106, #103, #67.

Validation

  • cargo fmt --all -- --check
  • cargo fmt --all -- --check in crates/rustc-codegen-cuda
  • cargo clippy --workspace -- -D warnings
  • cargo clippy --all-targets -- -D warnings in crates/rustc-codegen-cuda
  • non-example unit test matrix
  • cargo test -p cuda-core --lib
  • cargo test --manifest-path crates/rustc-codegen-cuda/Cargo.toml
  • cargo test -p llvm-export
  • RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace
  • cargo test --doc --workspace --exclude cuda-bindings
  • scripts/check-error-example-status.sh
  • naming guard equivalent
  • cargo deny check
  • CUDA_OXIDE_DEBUG=line-tables cargo oxide pipeline compiler_features
  • direct opt-20 -O2 round-trip on compiler_features.ll
  • manual cuda-gdb smoke: vecadd hits device source lines and shows a device backtrace through cuda-device/src/thread.rs and src/main.rs

Full examples smoketest is being run separately.

@nihalpasham

Copy link
Copy Markdown
Collaborator Author

Follow-up from testing a larger example: CUDA_OXIDE_DEBUG=line-tables cargo oxide pipeline compiler_features exposed one LLVM verifier issue. Some inlinable calls had a debug scope through the function, but the call instruction itself had no !dbg, so opt treated the debug info as invalid and stripped it before PTX.

I pushed a narrow fix in 72c8ed6: calls without their own source span now fall back to the containing function line. Other synthetic ops still stay location-less, so we avoid inventing extra stepping stops. Verified with cargo test -p llvm-export, direct opt-20 -O2, and the compiler_features pipeline; optimized IR keeps !llvm.dbg.cu/DILocation, and PTX now has .target ..., debug, .file, and .loc.

@nihalpasham nihalpasham self-assigned this Jun 15, 2026
…llocator

# Conflicts:
#	crates/llvm-export/tests/export_test.rs
@nihalpasham
nihalpasham merged commit 971e353 into main Jun 15, 2026
24 checks passed
@nihalpasham nihalpasham added debug info Debug information in generated PTX/IR (line/source maps) enhancement New feature or request llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate) codegen Device code-generation pipeline (Rust MIR to IR to PTX) tests Adds or improves test coverage labels Jun 15, 2026
@nihalpasham
nihalpasham deleted the debug-info-metadata-allocator branch June 19, 2026 11:30
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
Co-authored-by: Melih Elibol <elibol@users.noreply.github.com>
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
…NVIDIA#225, NVIDIA#185) (NVIDIA#256)

Three squash merges landed from branches that had resolved a merge against
main by keeping pre-merge copies of files, so each one quietly reverted an
earlier, unrelated merge:

- NVIDIA#239 (2482cb9) reverted NVIDIA#240 (1216aef): the const raw-pointer surface
  (as_ptr, program_id/num_programs, the cast_* and get_tensor_base helpers,
  unsafe on load_ptr_tko/store_ptr_tko), the compiler's const-pointer
  typing, the two GPU test files and the matching book and tutorial text.
- NVIDIA#247 (5f5f4c5) reverted NVIDIA#225 (a2843e7): integer division and remainder
  serialization (rounding<zero> and inferred signedness on divi/remi) and
  its test.
- NVIDIA#187 (35a9cc2) reverted NVIDIA#185 (cbf52c0): the flake.nix toolkit-assembly
  hardening and host-arch driver directory derivation.

This re-applies all three verbatim as cherry-picks. The only overlapping
file, cutile-book/guide/performance.md, merges cleanly with NVIDIA#239's own
edits. A per-file scan of the last 60 merges finds no other reversal still
missing at HEAD: NVIDIA#249's removal of the About page was deliberate, and the
two setup-python flips in .github/workflows/pages.yml were re-applied by
the later dependabot bump.

Verified: cargo fmt, cargo build, and the restored GPU tests
(const_pointers, program_id) plus integer_ops, memory_and_atomic_ops and
optimization_hints pass on an RTX 5090 with CUDA 13.3.

Signed-off-by: Melih Elibol <elibol@users.noreply.github.com>
Co-authored-by: Gabriel Wu <13583761+lucifer1004@users.noreply.github.com>
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 llvm-export Textual LLVM/NVVM IR exporter (llvm-export crate) tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plan: emit line-table debug metadata for cuda-gdb source breakpoints No debug information in the generated PTX

1 participant