简体   繁体   中英

CUDA: Debug with -deviceemu and gdb

I wrote a CUDA application that has some hardcoded parameters in it (via #define s). Everything seemed to work right, so I tried some other parameters. Now, the program doesn't work correctly anymore.

So, I want to debug it. I compile the application with -deviceemu -g -O0 options, because I read that I can then use gdb to debug it. In gdb, I set a breakpoint at the kernel start using break kernelstart .

However, gdb, jumps at the start of my CUDA kernel, but I can not step through it, because it doesn't let me inspect things within the kernel. I think it's best if I give the output of gdb:

Breakpoint 1, kernelstart (__cuda_0=0x100000, __cuda_1=0x101000, __cuda_2=0x102000, __cuda_3=0x102100) at cudatest.cu:287
(gdb) s
__device_stub__Z12kernelstartPjS_S_S_ (__par0=0x100000, __par1=0x101000, __par2=0x102000, __par3=0x102100) at /tmp/tmpxft_000003c4_00000000-1_cudatest.cudafe1.stub.c:7
7   /tmp/tmpxft_000003c4_00000000-1_cudatest.cudafe1.stub.c: No such file or directory.
    in /tmp/tmpxft_000003c4_00000000-1_cudatest.cudafe1.stub.c
(gdb) s
cudaLaunch<char> (entry=0x804a98d "U\211\345\203\354\030\213E\024\211D$\f\213E\020\211D$\b\213E\f\211D$\004\213E\b\211\004$\350\r\377\377\377\311\303U\211\345\203\354\070\307\004$\340 \005\b\350\345\341\377\377\243P!\005\b\307\004$x\234\004\b\350\b\001") at /usr/local/cuda/bin/../include/cuda_runtime.h:773
(gdb) s
(gdb) s
cudatest (__cuda_0=0x100000, __cuda_1=0x101000, __cuda_2=0x102000, __cuda_3=0x102100) at cudatest.cu:354
(gdb) s

After, this, it jumps back to my main procedure.

I know that my specifications are more than vague, but can anybody guess where the problem is? Is it possible to inspect kernels using gdb?

  1. Use cuda-gdb
  2. Compile: nvcc -g -G filename.cu
  3. Invoke cuda-gdb on your a.out
  4. You can set breakpoint inside your kernel function as usual.
  5. Run the program, and it should stop inside your kernel function.
  6. You can even get details of the current thread which is being executed using commands like cuda thread . Other commands like cuda block exist.
  7. To switch between threads say cuda thread (x,y,z)

For more details refer to the latest version of cuda-gdb's documentation. If you are using the latest version of cuda toolkit (ie, 3.2 as of today), make sure you are looking at the latest version of the documentation (as the options have changed a lot).

And also make sure you are running cuda-gdb from a console (outside X11), since you are stopping your GPU for debugging.

Hope this helps.

Compiling with :

nvcc -g -G --keep

fixed this problem for me. This ensures all the intermediate files generated during compilation are not erased so that the debugger can find them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM