How to use cuda-gdb

来源:互联网 发布:淘宝美工累吗 编辑:程序博客网 时间:2024/05/22 02:12

When developing massively GPU programs, we definitely need a debugger.

If you have more than one nVidia device in your computer, you can choose to use the NVIDIA Parallel Nsight for Visual Studio. However, if you have only one device, it is not possible to debug your CUDA program in Windows. When you are debugging, the CUDA device is paused so that the computer would have no working video card and it cannot afford the display. So, the solution is to use cuda-gdb which is included in the cuda toolkit. 

CUDA-GDB is a ported version of GDB: The GNU Debugger, version 6.6. Taking advantage of it, we can have an all-in-one debugging environment that is capable of debugging native host code as well as CUDA code. Therefore, it is an extension to the standard i386 port that is provided in the GDB release.

It is only supported on 32-bit Linux in the 2.1 Beta release.

1. Installing CUDA-GDB

Visit the CUDA Zone, download & install the NVIDIA driver, CUDA toolkit and CUDA SDK. 

You need a 32-bit Linux such as Fedora or Red Hat Enterprise.

Make sure that the PATH contains: /usr/local/cuda/bin and theLD_LIBRARY_PATH contains:/usr/local/cuda/lib


2. Compiling CUDA applications with debugging support

Stop the gdm service of Linux at the first place and then go to the directory which contains the application.

Type in the command:

nvcc -g -G xxx.cu -o xxx

This will force –O0 compilation; spills all variables to memory and make the compiler dump debugging information into the executable.


3. Start debugging

cuda-gdb xxx


4. Pause CUDA execution by adding breakpoints

If you want to add breakpoints at the 100th line, type in the command

break 100
or, you may want to break at some kernel's function

break [kernel_name]


5. next or step

CUDA-GDB supports stepping GPU code at the finest granularity of a warp which means if you type in the commandnextor step, the gdb will advance all threads in the same warp as the current thread of focus.


6. print

Using the print command, you can print any CUDA program variable: 

- Allocations made via cudaMalloc()

- Data that resides in various GPU memory regions such as shared, local and global memory

- Special CUDA runtime variables, such as the blockIdx or threadIdx


7. run

After adding all of the breakpoints, you can start the running of your applications by typing in theruncommand.

The application will pause at the breakpoints and you can use all the above commands to debug.


It is advised that you'd better to promote the quality of your code before debugging since debugging here using cuda-gdb is not as easy as using Visual Studio and you have no GUI to rely on. 

Please check the CUDA-GDB user manual in the toolkist docs with CUDA for much more detail information.


原创粉丝点击