Attach NSIGHT CUDA debugger to a Dll from NVCC?

I have compiled a Dll using NVCC. I then run a 64-bit process (.exe) that uses LoadLibrary to load the dll and to call methods from the dll to run it. How can I debug the CUDA code inside this dll, using NSIGHT?

I should add that this 64-bit process is in fact a Visual Studio’s Unit Test that I run manually by calling vstest.console.exe. It is the unit test code that loads into its process,the dll compiled from NVCC

When I use Visual Studio 2017 in admin mode, debug->Attach to Process and choose Nsight GPU Debugger, then my local computer, I see the vstest.console process but it is greyed out and cannot be selected for debugging.

Is there a way that the NSIGHT debugger can debug a dll complied from NVCC that is loaded into a 64-bit process?

Here is more detail on the structure of code. I would like NSIGHT to be able to break on the line with comment ‘break on this line !!’

----- In CMD window (administrator) to start the Visual Studio unit test ------

vstest.console.exe C:\SampleTest1\x64\Debug\UnitTest1.dll /tests:TestMethod1 /platform:x64


//------ In Visual Studio 2017 UnitTest1 project ------

typedef int(__stdcall* func_ptr_t)(void *, void *, void *);

TEST_METHOD(TestMethod1)
{
	.....
	HINSTANCE hGetProcIDDLL = LoadLibrary("MyCudaProgram.dll");
	f = (func_ptr_t)GetProcAddress(hGetProcIDDLL, "run_computation");
	f(a, b, c);
}	



//------ MyCudaProgram.dll compiled by NVCC compiler ------

__global__
void Kernel_launch_0(double *a, double *b, double *c) {
	unsigned int i = offset + blockIdx.x * blockDim.x + threadIdx.x;   // break on this line !!

	if (i<N) {
		c[i] = (a[i] + b[i]);
	}
}

__declspec(dllexport) void run_computation(void *a, void *b, void *c)
{
	......
	// Launch kernel
	Kernel_launch_0 << <1, N >> >(dev_a, dev_b, dev_c);
}

AFAIK you don’t need to anything special if you exe comes from a vc++ not a .not project, you just need to right click your project and start cuda debugging.

If you want to attach your app, you should follow the steps at https://docs.nvidia.com/gameworks/index.html#developertools/desktop/nsight/attach_cuda_to_process.htm#kanchor604

Also you need to launch the Nsight Monitor with administrator privileges on win10 if your exe is grey in processes list.

Hi Harryz_

Seems I’ve asked sometime ago and you replied. Here is the old thread:
https://devtalk.nvidia.com/default/topic/932570/nsight-visual-studio-edition/how-to-cuda-debug-visual-studio-unit-tests-/

I can debug the host code in a nvcc compiled dll that is called from a unit test by adding a breakpoint in Visual Studio and then right click on the unit test name and select debug unit test. Visual Studio’s debugger then breaks at the breakpoint in the host code as expected.

Unhfortunately, there is no right click and debug unit test with NSight. Hence why I am having to call the unit test directly using vstest.console.exe. Despite having Nsight Monitor with admin prviliedges, when I try to attach to the vstest.console.exe process with the GPU debugger, that exe is greyed out.

So I cannot use NSIGHT to debug a Visual Studio Unit Test. In the old thead you said that the request to be able to do this was submitted. Any progress or can the request be resubmitted?

Nope, nothing updated, it’s a backlog issue, they are setting focused on next-gen debugger now, nsight monitor will be a legacy product.

If you know how to launch vstest.console.exe with your unit tests, there will be a detour for you, you know how to debug a dll in visual c++ right? If you try to launch a debugger for a dll project, visual studio will ask you to specify a exe you want to launch, then you can debug your dll in this process, you can do the same thing on with nishgt.

  1. right click your dll project, click Nisght User Properties.
  2. set vstest.console.exe in Launch external program, also make sure your argv and working directory are right, just make sure that your unit can work well.
  3. then you can right click and use night to debug you dll unit test project if you dll and vstest.console.exe are in the same memory space, this works like using visual studio to debug a normal c++ dll project

Thanks Harryz_,
Did that and still not able to get NSIGHT to work for me!

vstest.console.exe in fact spawns another process; vstest.executionengine.exe, that runs the unittest.dll which in turn runs my CUDA code.

I did GPU debugger attach to the vsttest.executionengine.exe process but NSIGHT never stopped at any breakpoint in my kernel code :(

Ah, I wish there was some way I can get this to work.

The CMD windows displays…

"Microsoft (R) Test Execution Command Line Tool Version 15.0.26929.2
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait…
Warning: Using Isolation mode to run tests as required by effective Platform:X64 and .Net Framework:Framework45 settings for test run. Use the /inIsolation parameter to suppress this warning."

I’m wondering now if vsttest.executionengine.exe runs this in another process still? Maybe that could be fooling NSIGHT?

Is there anything else do you think I could try?

You can try to select “Application is a launcher” in Nsight User Properties, if it still doesn’t work, I really have no idea how to make it work, maybe you should try the cppunit?