CUDA学习笔记(二)之调试工具:cuda-gdb

本文详细介绍如何使用cuda-gdb对CUDA程序进行调试,包括编译、设置断点、单步执行等基本指令,同时介绍了如何利用图形界面进行调试。

转自自己的github博客

一、Linux下命令行操作

使用cuda-gdb对CUDA程序进行编译

1、编译程序

编译程序的时候我们使用nvcc编译器,将其编译成可调式版本;-g 表示将CPU代码(host)编译成可调式版本,-G表示将GPU代码(kernel)编译成可调式版本。

例子:

nvcc -g -G XXX.cu -o XXX

2、进入调试器

cuda-gdb

进入调试器后可以使用3中的指令进行执行可执行文件,然后进行调试,也可以在cuda-gdb指令后面直接加上需要调试的可执行文件进行调试。

3、调试的基本指令

指令简写指令说明举例
file exe_name置顶可调试的可执行文件file program
set args arg1 arg2 …设置命令行参数set args 1 2
breakpointb设置断点,使代码在指定位置暂停执行。其参数可以是方法名,也可以是行号b main; b 数字
runr在调试器中执行程序
start开始执行程序,并在main的第一行停住
nextn单步执行到下一行
continuec继续执行已暂停的程序至下一个断点或程序结尾处
steps单步执行,会进入函数内部执行
continuec执行已暂停程序到下一断点或结尾处
printp打印参数信息,查看变量p var1
thread列出当前主机线程
cuda列出当前活跃的kernel/grid/block/thread内容,并允许将焦点移至此处cuda thread(1, 1, 1); cuda kernel 1 block(1, 2, 1)
cuda thread列出当前活跃的GPU线程(若有的话)
cuda kernel列出当前活跃的GPU Kernel,并允许将“焦点”转移到指定的GPU线程
info查看参数所包含的具体信息info devices; info kernels; info threads
backtracebt显示当前函数调用栈的内容
quitq退出cuda-gdb

二、Linux下使用图形界面

当我们装好了CUDA的时候,其实在图形界面下已经装好了一个叫“nsight”的编译器,我们可以直接用终端打开这个编译器,然后写好程序直接编译然后debug就可以了。

参考

https://blog.csdn.net/sinat_28750977/article/details/69062708
http://book.51cto.com/art/201301/376309.htm

cuda检测工具 devicequery.zip(不含源代码,源代码在cuda sdk 8.0里) deviceQuery.exe Starting... CUDA Device Query (Runtime API) version (CUDART static linking) Detected 1 CUDA Capable device(s) Device 0: "GeForce GTX 760" CUDA Driver Version / Runtime Version 9.2 / 8.0 CUDA Capability Major/Minor version number: 3.0 Total amount of global memory: 2048 MBytes (2147483648 bytes) ( 6) Multiprocessors, (192) CUDA Cores/MP: 1152 CUDA Cores GPU Max Clock rate: 1137 MHz (1.14 GHz) Memory Clock rate: 3004 Mhz Memory Bus Width: 256-bit L2 Cache Size: 524288 bytes Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096) Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 49152 bytes Total number of registers available per block: 65536 Warp size: 32 Maximum number of threads per multiprocessor: 2048 Maximum number of threads per block: 1024 Max dimension size of a thread block (x,y,z): (1024, 1024, 64) Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535) Maximum memory pitch: 2147483647 bytes Texture alignment: 512 bytes Concurrent copy and kernel execution: Yes with 1 copy engine(s) Run time limit on kernels: Yes Integrated GPU sharing Host Memory: No Support host page-locked memory mapping: Yes Alignment requirement for Surfaces: Yes Device has ECC support: Disabled CUDA Device Driver Mode (TCC or WDDM): WDDM (Windows Display Driver Model)
deviceQuery.exe Starting... CUDA Device Query (Runtime API) version (CUDART static linking) Detected 1 CUDA Capable device(s) Device 0: "GeForce GTX 650" CUDA Driver Version / Runtime Version 9.1 / 8.0 CUDA Capability Major/Minor version number: 3.0 Total amount of global memory: 2048 MBytes (2147483648 bytes) ( 2) Multiprocessors, (192) CUDA Cores/MP: 384 CUDA Cores GPU Max Clock rate: 1072 MHz (1.07 GHz) Memory Clock rate: 2500 Mhz Memory Bus Width: 128-bit L2 Cache Size: 262144 bytes Maximum Texture Dimension Size (x,y,z) 1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096) Maximum Layered 1D Texture Size, (num) layers 1D=(16384), 2048 layers Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers Total amount of constant memory: 65536 bytes Total amount of shared memory per block: 49152 bytes Total number of registers available per block: 65536 Warp size: 32 Maximum number of threads per multiprocessor: 2048 Maximum number of threads per block: 1024 Max dimension size of a thread block (x,y,z): (1024, 1024, 64) Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535) Maximum memory pitch: 2147483647 bytes Texture alignment: 512 bytes Concurrent copy and kernel execution: Yes with 1 copy engine(s) Run time limit on kernels: Yes Integrated GPU sharing Host Memory: No Support host page-locked memory mapping: Yes Alignment requirement for Surfaces: Yes Device has ECC support: Disabled CUDA Device Driver Mode (TCC or WDDM): WDDM (Windows Display Driver Model) Device supports Unified Addressing (UVA): Yes Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0 Compute Mode: deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.1, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 650 Result = PASS
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值