Skip to content

Preserve device debug info for gdb-oneapi (#1004)#1350

Open
pvelesko wants to merge 1 commit into
mainfrom
fix-1004-device-debug-info
Open

Preserve device debug info for gdb-oneapi (#1004)#1350
pvelesko wants to merge 1 commit into
mainfrom
fix-1004-device-debug-info

Conversation

@pvelesko

@pvelesko pvelesko commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Adds llvm-patches/llvm/0007 for the configure_llvm.sh build path. The HIPSPV toolchain force-disabled device debug info (adjustDebugInfoKind -> NoDebugInfo), so -g/-O0 produced SPIR-V with no debug metadata and gdb-oneapi could not resolve locals in kernels. The historical blocker (translator aborting on DW_OP_LLVM_convert) is gone. The patch honors -g and, when set, emits the NonSemantic.Shader.DebugInfo form that Intel IGC/gdb-oneapi consume.

The same change is upstreamed in llvm/llvm-project#210504 and applied to the fork branch in CHIP-SPV/llvm-project#6.

Refs #1004

Hardware validation on Aurora (PVC, i915, oneAPI 2025.3, LLVM 22)

Full in-kernel debugging works, including reading arguments and locals per SIMD lane:

addKernel (a=0xff00fffffffe0000, b=0xff00fffffffd0000, c=0xff00fffffffc0000, n=256)
    at dbgtest.hip:9
n = 256   idx = 64   lhs = 64   rhs = 128
print a[idx]  ->  $4 = 64
thread :3     ->  idx = 70, lhs = 70

Getting there needs three changes. This PR is one of them; the other two are chipStar-side and are not yet written.

  1. This patch: honor -g and request nonsemantic-shader-200 + SPV_KHR_non_semantic_info.
  2. Add +SPV_INTEL_optnone to the same extension list. At -O0 clang marks kernels optnone; without the extension the translator silently drops it, so IGC optimizes the kernel and every variable reads . Needed only on the Triple::ChipStar branch upstream, whose allowlist excludes it; the generic branch already uses --spirv-ext=+all.
  3. chipStar must stop discarding optnone and must pass -cl-opt-disable to zeModuleCreate:
    • llvm_passes/HipPasses.cpp RemoveNoInlineOptNoneAttrsPass strips optnone from every function unconditionally, before the translator runs. It should skip that when the module carries debug info (llvm.dbg.cu).
    • CHIPBackendLevel0::getDefaultJitFlags() returns "". It should yield -cl-opt-disable when the module has debug info.

Measured combinations, all with -g -O0 on PVC:

optnone in IR SPV_INTEL_optnone L0 build flags locals
stripped no -cl-opt-disable -g optimized out
stripped yes -cl-opt-disable -g optimized out
preserved yes (empty, current default) optimized out
preserved yes -g optimized out
preserved yes -cl-opt-disable readable

So -cl-opt-disable alone is not enough, and preserving optnone alone is not enough; both are required. -g in the L0 build flags is not needed.

Also confirmed: nonsemantic-shader-200 is the right choice. Testing nonsemantic-shader-100 changed nothing, and icpx -fsycl -g passes -spirv-debug-info-version=nonsemantic-shader-200 itself.

The -g binary runs correctly on PVC and there is no change when -g is absent.

Using gdb-oneapi with chipStar

Two prerequisites live outside the compiler entirely.

  1. Enable EU debug on the node. It is off by default but writable by a normal user inside a job; no root needed:

    for f in /sys/class/drm/card*/prelim_enable_eu_debug; do echo 1 > "$f"; done
    

    Without this, Level Zero enumerates zero devices under ZET_ENABLE_PROGRAM_DEBUGGING=1 and chipStar fails with hipErrorNotInitialized.

  2. Redirect gdb-oneapi's auto-attach hook. Its intelgt_auto_attach.py plants the trigger breakpoint on zeContextCreate, but chipStar calls zeContextCreateEx (src/backend/Level0/CHIPBackendLevel0.cc:2368). Different address, so the hook never fires, gdbserver-ze never starts, and device breakpoints stay pending while the program runs to completion. The extension provides an official override:

    export INTELGT_AUTO_ATTACH_HOOK="-qualified zeContextCreateEx"
    

Full session:

for f in /sys/class/drm/card*/prelim_enable_eu_debug; do echo 1 > "$f"; done
export ZET_ENABLE_PROGRAM_DEBUGGING=1
export INTELGT_AUTO_ATTACH_HOOK="-qualified zeContextCreateEx"
export CHIP_BE=level0
export CHIP_JIT_FLAGS_OVERRIDE="-cl-opt-disable"   # until item 3 above lands
hipcc -g -O0 test.hip -o test
gdb-oneapi -ex "set breakpoint pending on" -ex "break test.hip:42" -ex run ./test

Add INTELGT_AUTO_ATTACH_VERBOSE_LOG=1 to trace auto-attach; a successful run logs "gdbserver-ze started for process N".

Item 2 deserves its own fix: chipStar could call zeContextCreate when it is not subsetting devices, and Intel should hook both entry points, since any Level Zero application using the Ex form is invisible to auto-attach today.

The HIPSPV toolchain force-disabled device debug info (adjustDebugInfoKind
-> NoDebugInfo), so -g/-O0 produced SPIR-V with no debug metadata; gdb-oneapi
could not resolve locals in kernels. The historical blocker (translator
aborting on DW_OP_LLVM_convert) is gone. Honor -g and, when set, emit the
NonSemantic.Shader.DebugInfo form that Intel IGC/gdb-oneapi consume.

Applies on top of the existing HIPSPV spirv-ext patches for LLVM 17-22.
@pvelesko

Copy link
Copy Markdown
Collaborator Author

/run-aurora-ci

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant