This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Do not emit debug info for stub function
ClosedPublic

Authored by yaxunl on May 13 2020, 8:09 AM.

Details

Summary

The stub function is generated by compiler and its instructions have nothing
to do with the kernel source code.

Currently clang generates debug info for the stub function, which causes
confusion for the debugger. For example, when users set break point
on a line of a kernel, the debugger should break on that line when the kernel is
executed and reaches that line, but instead the debugger breaks in the stub function.

This patch disables debug info for stub function.

Diff Detail

Event Timeline

yaxunl created this revision.May 13 2020, 8:09 AM
tra added a comment.May 13 2020, 10:22 AM

I do not see the behavior the patch is supposed to fix in CUDA.
If I compile a simple program, host-side debugger does not see the kernel, sees __device_stub_kernel and, if the breakpoint is set on kernel, it treats it as a yet-to-be-loaded one and does end up breaking on intry into the kernel on the GPU side.

E.g.:

(cuda-gdb) info symbol kernel
No symbol "kernel" in current context.
(cuda-gdb) info symbol __device_stub__kernel
__device_stub__kernel() in section .text
(cuda-gdb) b kernel
Function "kernel" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (kernel) pending.
(cuda-gdb) r
Starting program: /usr/local/google/home/tra/work/llvm/build/debug/print
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Hello from host
[New Thread 0x7fffdffff700 (LWP 227347)]
[New Thread 0x7fffdf7fe700 (LWP 227348)]
[New Thread 0x7fffdeffd700 (LWP 227349)]
[Switching focus to CUDA kernel 0, grid 1, block (0,0,0), thread (0,0,0), device 0, sm 0, warp 0, lane 0]

Thread 1 "print" hit Breakpoint 1, kernel<<<(1,1,1),(1,1,1)>>> () at print.cu:3
3         printf("Hello\n");

Perhaps it's HIP-specific behavior that needs this tweak.
For CUDA, I would rather that we continue to emit debug info for the stub (in it's __device_stub form). It is useful for debugging some issues.

In D79866#2034460, @tra wrote:

I do not see the behavior the patch is supposed to fix in CUDA.
If I compile a simple program, host-side debugger does not see the kernel, sees __device_stub_kernel and, if the breakpoint is set on kernel, it treats it as a yet-to-be-loaded one and does end up breaking on intry into the kernel on the GPU side.

E.g.:

(cuda-gdb) info symbol kernel
No symbol "kernel" in current context.
(cuda-gdb) info symbol __device_stub__kernel
__device_stub__kernel() in section .text
(cuda-gdb) b kernel
Function "kernel" not defined.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (kernel) pending.
(cuda-gdb) r
Starting program: /usr/local/google/home/tra/work/llvm/build/debug/print
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Hello from host
[New Thread 0x7fffdffff700 (LWP 227347)]
[New Thread 0x7fffdf7fe700 (LWP 227348)]
[New Thread 0x7fffdeffd700 (LWP 227349)]
[Switching focus to CUDA kernel 0, grid 1, block (0,0,0), thread (0,0,0), device 0, sm 0, warp 0, lane 0]

Thread 1 "print" hit Breakpoint 1, kernel<<<(1,1,1),(1,1,1)>>> () at print.cu:3
3         printf("Hello\n");

Perhaps it's HIP-specific behavior that needs this tweak.
For CUDA, I would rather that we continue to emit debug info for the stub (in it's __device_stub form). It is useful for debugging some issues.

can you try set bp by using file name and line number on the kernel?

tra added a comment.May 13 2020, 11:44 AM

can you try set bp by using file name and line number on the kernel?

In regular gdb it is set on the stub.
In cuda-gdb the behavior is interesting -- it initially gets set and breaks on the stub, but it also breaks on the entry into kernel. Once the kernel address is known, cuda-gdb no longer breaks on the stub. If I set breakpoint after the kernel is known, it's set on the kernel only and never stops on stub.

Overall the behavior is reasonable, IMO.

In D79866#2034748, @tra wrote:

can you try set bp by using file name and line number on the kernel?

In regular gdb it is set on the stub.
In cuda-gdb the behavior is interesting -- it initially gets set and breaks on the stub, but it also breaks on the entry into kernel. Once the kernel address is known, cuda-gdb no longer breaks on the stub. If I set breakpoint after the kernel is known, it's set on the kernel only and never stops on stub.

Overall the behavior is reasonable, IMO.

According to our debugger developers, cuda-gdb's behavior is not upstreamable. I can limit this patch to HIP if it is not needed for CUDA.

yaxunl updated this revision to Diff 263831.May 13 2020, 12:57 PM
yaxunl retitled this revision from [CUDA][HIP] Do not emit debug info for stub function to [HIP] Do not emit debug info for stub function.

limit change to HIP

tra accepted this revision.May 13 2020, 1:42 PM
This revision is now accepted and ready to land.May 13 2020, 1:42 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 13 2020, 3:17 PM