Skip to content

debug: keep generated kernel prologue off attribute lines - #1125

Merged
nihalpasham merged 3 commits into
mainfrom
fix/debug-kernel-prologue-lineinfo
Aug 28, 2026
Merged

nihalpasham merged 3 commits into
mainfrom
fix/debug-kernel-prologue-lineinfo

Conversation

@nihalpasham

@nihalpasham nihalpasham commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Kernel-name breakpoints no longer treat #[kernel] as executable source.
Compiler-generated setup uses an artificial line, while the user's index call
keeps its real span.

Before                              After
#[kernel]  line 13                  #[kernel]  line 13
   │                                   │
   └─ generated setup: .loc 13         └─ generated setup: line 0
      index_1d():      .loc 13            index_1d():      line 15
      cuda-gdb may show line 13            cuda-gdb shows line 15

Closes #1117.

Changes

  • Rewrite thread-index calls in place so their original spans survive.
  • Mark injected kernel setup as artificial instead of falling back to the
    attribute line.
  • Add a PTX/LLVM shape check with docs and multiple attributes.
  • Update three affected compile-fail snapshots to the new diagnostic spans.

Testing

  • Full macro/importer/exporter/lowering suites passed on af66e381.

  • Final head 63ce7c7e passes cargo test -p cuda-device --all-targets,
    including all 29 thread-index compile-fail cases; the hosted check that
    exposed the stale snapshots is now green.

  • The debug compile-only smoketest and PTX shape gate pass.

  • CUDA 13.3 / RTX 5090: the T01 shape stops on the first body expression; the
    multi-attribute control stops on line 35, not lines 32/33.

  • just check passes (affected suites and targeted smoketest pass)

  • Live GPU debugger regression exercised

  • New example added (existing debug 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 bug Something isn't working debug info Debug information in generated PTX/IR (line/source maps) codegen Device code-generation pipeline (Rust MIR to IR to PTX) labels Aug 21, 2026
@nihalpasham
nihalpasham force-pushed the fix/debug-kernel-prologue-lineinfo branch from 63ce7c7 to b1e74c2 Compare August 28, 2026 11:31
@nihalpasham
nihalpasham marked this pull request as ready for review August 28, 2026 12:05
@nihalpasham
nihalpasham merged commit 768f6da into main Aug 28, 2026
84 of 85 checks passed
@nihalpasham nihalpasham mentioned this pull request Aug 28, 2026
4 of 5 tasks
@nihalpasham
nihalpasham deleted the fix/debug-kernel-prologue-lineinfo branch August 28, 2026 12:54
nihalpasham added a commit that referenced this pull request Nov 3, 2026
…ine (#1677)

## What This PR Does

Uses `llvm_export::artificial_debug_location()` for the synthetic
`MirGotoOp` emitted when `mir-importer` replaces `__unroll_config` and
`__nounroll_config` loop-hint markers, keeping `#[unroll]` and
`#[nounroll]` attribute lines out of `--device-debug` line tables while
preserving the attribute span on `MirUnrollHintOp` / `MirNoUnrollHintOp`
for not-unrolled diagnostics.

---

### Why the Attribute Line Appeared in `--device-debug`

`#[kernel]` and `#[device]` inject a `__unroll_config` /
`__nounroll_config` marker call at the top of every annotated loop.
`mir-importer` replaces that call with a hint op plus a `MirGotoOp`.
Previously, the `MirGotoOp` inherited the marker call's source location
(the attribute line), so under `--device-debug` (`-O0`), the unoptimized
`bra.uni` emitted `.loc` pointing at the attribute line (38 of 38 loops
in `unroll_smoke`).

```text
BEFORE (cargo oxide build unroll_smoke --device-debug):
  $L__BB0_16:
      .loc 1 80 9      // main.rs:80:9 (the #[unroll] attribute line)
      bra.uni $L__BB0_17;

AFTER (with artificial_debug_location() on the marker goto):
  $L__BB0_16:
      .loc 1 0 0       // artificial location (matches #1125 kernel metadata markers)
      bra.uni $L__BB0_17;
```

| `--device-debug` | Attribute lines with a `.loc`: before -> after |
|:-----------------|:-----------------------------------------------|
| `unroll_smoke`   | `38 of 38` -> `0`                              |
| `nounroll`       | `8 of 8` -> `0`                                |

---

## Verification

* **Regression (`examples/debug`)**: Adds `loop_hint_test` covering
`#[unroll]`, `#[unroll(4)]`, `#[unroll(never)]`, and `#[nounroll]`;
`verify-code-shape.sh` rejects any LLVM IR `!dbg` or PTX `.loc` on those
attribute lines while verifying each loop body keeps its own line
(`debug kernel-entry and loop-hint lineinfo shape: PASS`).
* **GPU Execution (`RTX 5090`, `sm_120a`)**: `debug` runs clean under
`compute-sanitizer --tool memcheck` (`0 errors`).
* **Tests & CI Gates**: `cargo test -p mir-importer --all-targets`
(`1,234/1,234 PASS`), `just fmt-check`, `cargo clippy`, and repository
guards all pass.

Closes #1676

Signed-off-by: Vyncint Ng <[email protected]>
Signed-off-by: nihalpasham <[email protected]>
Co-authored-by: nihalpasham <[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 codegen Device code-generation pipeline (Rust MIR to IR to PTX) debug info Debug information in generated PTX/IR (line/source maps)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debug info: keep #[kernel] prologue instructions off the attribute line

1 participant