Skip to content

[BUG]: cuTile: at a cuda_tile_assert! trap, cuda-gdb reports the module's first line and drops the inlined helper frames #1379

Open
GiGiKoneti/cutile-rs
#1

Description

@elibol

Description

With full device debug information (dev profile, cutile 0.4.0), a cuda-gdb breakpoint on a cuda_tile_assert! line inside a helper two calls deep stops with the complete inlined backtrace. But when that assertion actually fires, the SIGTRAP PC is attributed to src/gpu.rs:10, which is the pub mod kernels { line, in the scope of the user kernel function, and the two helper frames are missing. A GPU coredump of the same trap shows the same two-frame backtrace. The device-side assertion message prints the correct line (src/gpu.rs:106), so the assert op itself carries the right location; it is the trap instruction's location that is wrong.

Error / actual behavior

Breakpoint on the assertion line (correct):

CUDA thread hit Breakpoint 1, assert_in_range@gpu:104:7 () at src/gpu.rs:105
#0  assert_in_range@gpu:104:7 () at src/gpu.rs:105
#1  validate_factor@gpu:97:7 () at src/gpu.rs:98
#2  checked_scale@gpu:86:7<<<(4,1,1),(128,1,1)>>> () at src/gpu.rs:91
#3  checked_scale_entry<<<(4,1,1),(128,1,1)>>> () at src/gpu.rs:10

The same launch with an out-of-range factor, stopped at the trap:

src/gpu.rs:106: tile block: [0, 0, 0], position: []: checked_scale: factor above the allowed range
Thread 1 "demo" received signal SIGTRAP, Trace/breakpoint trap.
checked_scale@gpu:86:7<<<(4,1,1),(128,1,1)>>> () at src/gpu.rs:10
10	pub mod kernels {
#0  checked_scale@gpu:86:7<<<(4,1,1),(128,1,1)>>> () at src/gpu.rs:10
#1  checked_scale_entry<<<(4,1,1),(128,1,1)>>> () at src/gpu.rs:10

target cudacore on the coredump written by CUDA_ENABLE_COREDUMP_ON_EXCEPTION=1 gives the same two frames at line 10.

Expected behavior

At the trap, the same frames as at the breakpoint: assert_in_range ... at src/gpu.rs:106, validate_factor ... :98, checked_scale ... :91, entry.

Minimal reproduction example

use cutile::prelude::*;

#[cutile::module]
mod kernels {
    use cutile::core::*;

    #[cutile::entry()]
    fn checked_scale<const S: [i32; 1]>(out: &mut Tensor<f32, S>, x: &Tensor<f32, { [-1] }>, factor: f32) {
        validate_factor(factor);
        let tile_x = x.load_like(out);
        out.store(tile_x * factor.broadcast(out.shape()));
    }

    fn validate_factor(factor: f32) {
        assert_in_range(factor, 0.0f32, 1000.0f32);
    }

    fn assert_in_range(value: f32, lo: f32, hi: f32) {
        cuda_tile_assert!(value >= lo, "checked_scale: factor below the allowed range");
        cuda_tile_assert!(value <= hi, "checked_scale: factor above the allowed range");
    }
}

fn main() -> Result<(), Error> {
    let device = Device::new(0)?;
    let stream = device.new_stream()?;
    let x: Arc<Tensor<f32>> = api::arange(512).sync_on(&stream)?.into();
    for factor in [3.0f32, 5000.0] {
        let out = api::zeros::<f32>(&[512]).sync_on(&stream)?.partition([128]);
        match kernels::checked_scale(out, x.clone(), factor).sync_on(&stream) {
            Ok(_) => println!("factor {factor}: ok"),
            Err(e) => { println!("factor {factor}: {e}"); std::process::exit(3) }
        }
    }
    Ok(())
}
cargo build   # dev profile => full device debug info
cuda-gdb --batch -nx -ex 'set breakpoint pending on' -ex 'break gpu.rs:<assert line>' \
  -ex run -ex bt -ex delete -ex continue -ex bt --args ./target/debug/<bin>

Operating System

Ubuntu 24.04.4 LTS

GPU and GPU Architecture

NVIDIA GeForce RTX 5090 (sm_120)

CUDA driver version

610.43.02; CUDA toolkit 13.3, tileiras V13.3.36

rustc version

rustc 1.98.0 (stable)

Additional context

What the compiled kernel contains (readelf --debug-dump=info, nvdisasm --print-line-info):

  • The DWARF has DW_TAG_inlined_subroutine entries for checked_scale, validate_factor and assert_in_range with the right call_lines (91, 98), so the inline structure is emitted correctly.
  • The line table has rows for the module's first line (10). They come from constant and other type-derived ops that the frontend emits with a call-site span, which the span base resolves to the module's first line.
  • The assembler's lowering of the assert (the vprintf call, the delay spin and the trap) is stamped with lines past the assertion that do not exist in the kernel's debug section (107 to 116 here), and the trap ends up attributed to a neighbouring module-line row in the checked_scale scope.

Two halves, then. The assembler half is being reported to the Tile IR team separately. The frontend half is ours: type-derived constants should carry the location of the statement that needs them (or at least the kernel's definition line), never the module header, so that whatever neighbour the assembler picks, the frame is at least in the right function at a plausible line. The same module-line rows also show up as a line 10 entry in Nsight Compute source views and in Compute Sanitizer's Device Frame line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcutile-rsdebug info

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions