How to CUDA debug Visual Studio unit tests?


With a Visual Studio project exe I can debug simply by selecting NSIGHT and ‘start CUDA debugging’ off the menu. What about debugging unit tests from the Test Explorer window?

Do I have to attach to running process or set up a dummy test program with a main exe section and run that? Is there an easy way to CUDA debug unit tests?

Thanks for any help,

Hi Jules123,

I’m not quite sure how your unit test frame works, could you tell me more about it? Before that, I can still give you something about some scenarios I know.

  1. if your unit test app is a single exe file which contains cuda kernel and the unit test frame just launches the exe to get the UT result.
    A1. Under this circumstance, the easiest way to debug the app is attaching the cuda process launched by UT frame, but it’s very hard to make sure that the code you want to debug is not finished before you attach the app.

  2. if your unit test app is a dll which contains cuda kernel and the unit test frame just loads the dll to run the test case.
    A2. Under this circumstance, you just need to attach the UT frame process or launch the UT frame via visual studio, Nsight is supported to debug the cuda kernel in dll.

Best Regards

Thanks for the reply.

I have a C++ .lib project and a C++ unittest project in Visual Studio.

Each unit test calls a class from the .lib that loads (using ShellExecuteEx) a compiled dll (compiled by calling NVCC earlier). Then the same class calls a function from the dll that runs the host code to set up any CUDA devices and launches the kernel.

So I want to be able to debug the kernel using NSIGHT. How would I do that?

Hope that is clear what I am doing,

Hi Jules123,

You project sounds complicated, please let me explain what I got and make sure there is no misunderstanding.

  1. You have a c++ unit test project which is a exe.
  2. This c++ unit test project invokes one class in a lib project.
  3. Actually the lib invokes a compiled dll which contains cuda host and device code via ShellExecuteEx (I think this should be loadlibrary, ShellExecuteEx works for exe)

By the way, if you can send me one UT sample if it isn’t for internal use, this will be very helpful for me to help you.

You can send the code to if it isn’t for internal use.

Hi harryz_,

Yes I meant loadlibrary, a typo there. I’ve emailed you a sample project.

Thanks for your help,

Hi Jules,

I just see part of your mail in my mailbox but I cannot unblock it from our internal spam manager, but in the mail you said you had sent a copy to dropbox, could you post the dropbox link in this topic? Sorry for the inconvenience, this forum really should have a attachment feature.

Best Regards

Hi Jules,

I got your mail before, here are what I got from your project.

  1. UnitTest1 is a dll which contains test cases, it uses Microsoft unit test framework
  2. UnitTest1 invokes SampleTest1 lib to load launch1.dll
  3. launch1.dll has real test cases which contains cuda host and target codes

Microsoft unit test framework uses a complicated way to debug and run the test case, visual studio invokes {vs_install_path}\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe to launch the test, vstest.console.exe will launch the {vs_install_path}\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.exe to load and run the test cases in UnitTest1.

Nsight VSE can debug the cuda kernal code in dll which is launched by no matter native c++ or managed .net code exe. But I tried to point the debug target to vstest.console.exe in Nsight, but no bp will be hit in launch1.dll, even the c++ debugger in visual studio cannot debug the native c++ code in UnitTest1 launched by vstest.console.exe.

I think visual studio uses a internal way to communicate with it’s own unit test frame, currently the only way I know to debug the kernel code is like you said in #1, set up a dummy test program with a main exe .

I’ll raise a request to our PM to see if we can support to debug the Microsoft unit test in future.

Best Regards

Thanks Harry for investigating.

Okay so it’s not my particular code set-up but the fact that NSIGHT doesn’t support debugging Visual Studio unit tests directly.

Thanks for submitting the request to support this.