问题
i have a cpp function (function.cpp") which i "mex"-ed. then i open the function.cpp file in visual studio and attach visual studio to a running matlab process.
when i call the function in matlab i am able to set breakpoints in the function.cpp file and step through it observing the variables.
The debugging process breaks down when i change the function to a cuda file (function.cu). Following the process described above i am still able to stop within function.cu but i cannot see any variables. when i try to "watch" a variable it says "Error symbol .. not found"
i have nsight installed in visual studio. question: how can i observe my variables in the file function.cu in the debug mode as i do for the function.cpp file. Is this possible ?
Note that the function.cu is not in a project. it is just a standalone file with cpp code of a function (say somefunction(){}). for debugging purpose i am opening it up in visual studio. i am compiling the function.cu file in matlab using "nvmex -g wrapper.cu" the wrapper.cu is a matlab mexfunction wrapper which makes calls to somefunction() written inside function.cu
回答1:
You're using the VS debugger which is a host debugger, so it doesn't know how to debug device programs. To debug device code in Windows you should look at Parallel Nsight Visual Studio Edition.
You can search the docs for a guide to attaching to a running process, for the current release (2.2) the specific page is here.
回答2:
You attached VS in, but stopped in function 'main'. Looks like you are still hitting the CPU code. When you follow Tom's suggestion to attach the debugger, have you choosed "NVIDIA GPU Debugger" in the Transport dropdown?
回答3:
To debug any cuda-code you'll need a gpu on which no desktop environment/server is running. For windows that means, that you need a second gpu. I'm not to 100% sure if it has to be a nvida gpu, too. Than you will be able to bedubg your code. Under linux you're able to debug with only one gpu because you can shut down the x-server and debug with cuda-gdb per command line. Further informations will give you the cuda-gdb manual
来源:https://stackoverflow.com/questions/14386982/debugging-cuda-files-in-visual-studio