How to step out of a CUDA kernel using CUDA-GDB? - Stack Overflow

admin2025-04-29  2

I am using CUDA-GDB to explore a large CUDA project. I can discover the first CUDA kernel using the following command:

set cuda break_on_launch application

I can then step-debug through the kernel, and GDB's continue will conveniently take me to the next kernel launch.

As explained here I can also disable these breaks, returning to the default behaviour:

set cuda break_on_launch none

I would like to exit the kernel, and return to the host code. The GDB finish command doesn't help here, reporting:

(cuda-gdb) finish
"finish" not meaningful in the outermost frame.

Is it possible to exit a CUDA kernel and return to the subsequent line of host code?

I am using CUDA-GDB to explore a large CUDA project. I can discover the first CUDA kernel using the following command:

set cuda break_on_launch application

I can then step-debug through the kernel, and GDB's continue will conveniently take me to the next kernel launch.

As explained here I can also disable these breaks, returning to the default behaviour:

set cuda break_on_launch none

I would like to exit the kernel, and return to the host code. The GDB finish command doesn't help here, reporting:

(cuda-gdb) finish
"finish" not meaningful in the outermost frame.

Is it possible to exit a CUDA kernel and return to the subsequent line of host code?

Share Improve this question edited Jan 8 at 17:27 paleonix 3,1385 gold badges17 silver badges39 bronze badges asked Jan 8 at 13:11 user2023370user2023370 11.2k6 gold badges58 silver badges91 bronze badges 2
  • set a breakpoint in host code, after a cudaDeviceSynchronize() call placed immediately after the kernel call. – Robert Crovella Commented Jan 9 at 2:54
  • I don't know where the kernel calls are. I'm using break_on_launch as a way to find them, and especially find which ones are called. Once I know where they are, there isn't a problem. – user2023370 Commented Jan 9 at 9:43
Add a comment  | 

1 Answer 1

Reset to default 1

It is possible to switch the focus to any host thread with the thread command the same way you would do in the original GDB, as mentioned in the docs:

[...] the GDB command to display the host threads and switch to host thread 1 are, respectively:

(cuda-gdb) info threads
(cuda-gdb) thread 1

As kernel launches are in general asynchronous, "subsequent line of host code" is not necessarily well defined. But you can set the environment variable CUDA_LAUNCH_BLOCKING to 1 to get synchronous operation between CPU and GPU which should help exploration (and debugging).

转载请注明原文地址:http://anycun.com/QandA/1745856098a91283.html