简体   繁体   中英

Debug cuda kernel on mexfunction by attaching Matlab with Nsight GPU Debugger

I would like to ask how can we debug cuda kernel that is called from a mexfunction with VS 2010 and Nsight. I followed the instructions in http://http.developer.nvidia.com/NsightVisualStudio/2.2/Documentation/UserGuide/HTML/Content/Attach_CUDA_to_Process.htm but the attach button is not enabled in order to attach matlab.

PS: Win 7 64x, Matlab 2011 x64, VS 2010, CUDA SDK 5.5 64x, Nsight 3.1 64x, GForce 9600.

在此处输入图片说明

  1. Open Nsight Monitor Nsight Visual Studio Edition 3.1 -> Nsight Monitor
  2. Go the Nsight Monitor Options (on the left of taskbar) -> CUDA -> Use this Monitor for CUDA attach ->true
  3. Add environmental variable NSIGHT_CUDA_DEBUGGER = 1 via Advance System Settings -> Environmental Variables and add the aforementioned variable both in User and System variables in the two panels.
  4. Start Matlab and Visual Studio and try to attach Matlab with the Nsight debugger and qualifier the Computer name and that it is.

Tested on Matlab 2011a 64x and VS 2010 with SP1.

在此处输入图片说明

It is enough to set the NSIGHT_CUDA_DEBUGGER environment variable just for MATLAB , so you don't have to slow down your entire system by having every process attachable. Quoting NVIDIA's Nsight documentation:

Setting NSIGHT_CUDA_DEBUGGER=1 can degrade the performance of an application, since the debugger is made resident. The effect is minimal on Tesla™ devices and headless devices; it is most severe on display devices with a desktop, where the debugger by necessity may need to serialize launches that would otherwise have been asynchronous. Therefore, it's not always desirable to set NSIGHT_CUDA_DEBUGGER=1 at a system-wide or user-wide level .

To set it in a running MATLAB session (and spare the rest of your system):

>> setenv('NSIGHT_CUDA_DEBUGGER','1')

Hit Refresh or reselect the Nsight GPU Debugger and it works:

在此处输入图片说明

You still need to configure Nsight to allow attaching, but it's a one-time setting:

在此处输入图片说明

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