This project is read-only.

Unit Testing

Oct 15, 2014 at 8:58 PM
Edited Oct 15, 2014 at 8:59 PM
Great work sir!

Any suggestions on how to implement managedCuda with C# unit testing?

Particularly, how to debug managedCuda unit tests with the Cuda debugger.

I'd like to debug device functions from C# and be able to step through the code.
Oct 15, 2014 at 9:50 PM
If you compile your kernels with debug information (option -G for NVCC) you can step through your kernel code with the NSight-VisualStudio-Debugger. You only need to launch your application via NSight-launcher or attach Nsight to an already running Cuda process. This definitively works fine without any restrictions also using C#/managedCuda. Whereas I never tried to combine the Cuda debugger with unit testing, but I don't see why this shouldn't work... Simply run your unit tests through NSight-Launcher and it should stop at break points inside the kernel.

Oct 15, 2014 at 11:26 PM
You rock Michael.

I guess that's my problem. I don't know how to run my unit tests through the NSight-Launcher. I'm able to debug a managedCuda kernel during a C# program's execution, but in my unit tests project, the only option seems to be C# debugging--which will not connect to NSight, or hit any kernal breakpoints.


It seems that if I want kernal unit tests I can debug, I can either create a C# console program to set up, invoke and check the kernel output, or do the same thing in main() of the .cu file.

I still wonder if there is a way to explicitly tell Nsight to pickup debugging when running C# unit tests. I lack a low level understanding of debuggers in general to think of a way to do that myself.
Oct 16, 2014 at 12:45 AM
I get your point and as far can see for now, this is not trivial...
Visual studio runs the tests in a host process which would be needed to be attached to NSight, but as the host process only runs for a short time period during the tests, I'm not sure how this could be done. One might try to launch the host process manually with the right parameters and use the same command to let Nsight start the test, but I never tried that and have also no clue if this actually works.
Another idea would be to write a small test-hosting-application by your own which does nothing else then binding to the DLL with the unit tests and calls the corresponding test. If you have this, you can use this application as host in Nsight.
Finally it might be the easiest approach to write a console application and debug the kernels independently of the unit tests (just as you mentioned before...). It's not the "best solution" but one that would work ;-)

Marked as answer by Verterax on 10/15/2014 at 5:03 PM