Visual Profiler (NVVP.exe)

Jul 7, 2015 at 5:40 PM
Edited Jul 8, 2015 at 1:56 PM
I am able to debug, and profile from within VS2013 with the NSIGHT tools.

But when I run the stand-alone Visual Profiler, it runs the EXE 2-3 times and I see the console log generating values, but there is no visual trace created. Is this supposed to work with CUDAFY?

CUDA V7.0, CUDAfy V1.29
NSIGHT 4.6
Jul 10, 2015 at 7:34 PM
Hi
In order to enable profiling, you'll have to enable profiling through an api call.
Call cudaProfilerStart(); at the start of your program (or at the very least before calling the kernel) and
call cudaProfilerStop(); at the end of your program (or at the very least after calling the kernel).

Those api functions are not currently exposed by cudafy, so you'll have to add the extern references yourself. Personally, I added the following to CUDARuntime.cs in the Cudafy source code, but you can declare them elsewhere if you so chose, just make sure you point to the same dll as cudafy's:
    [DllImport(CUDART_DLL_NAME)]
    public static extern cudaError cudaProfilerStart();

    [DllImport(CUDART_DLL_NAME)]
    public static extern cudaError cudaProfilerStop();
Jul 10, 2015 at 7:36 PM
Of course, make sure you disable those calls when you release your code to production.
Jul 13, 2015 at 2:48 PM
I apologize for being a neophypte. Since my app is only built as a 64 bit app, I tracked down the CUDART dlls, and tried this at the top of the class definition (before the static methods)
    [DllImport("C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\cudart64_70.dll")]
    public static extern cudaError cudaProfilerStart();

    [DllImport("C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\cudart64_70.dll")]
    public static extern cudaError cudaProfilerStop();
But that gives compile errors: "Unrecognized escape sequence"

So then I tried to add a reference to the CUDART dll to the project, but it then complains, that it is not a valid COM or valid DLL.
Jul 14, 2015 at 11:13 AM
Hi
Make sure your c# strings are properly escaped. For instance, use the @ prefix:

[DllImport(@"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\cudart64_70.dll")]
public static extern cudaError cudaProfilerStart();

[DllImport(@"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\bin\cudart64_70.dll")]
public static extern cudaError cudaProfilerStop();
Jul 14, 2015 at 4:36 PM
Edited Jul 14, 2015 at 4:38 PM
Works great now, One more detail for anyone following this thread. make sure you add the following two usings:
using System.Runtime.InteropServices;
using GASS.CUDA;
FYI: I structure things so that all the CUDAfy code is in one DLL, then I have a tester.exe that uses that DLL. So my profiling is in the EXE version. The operaitonal code (DLL) is then clean of the profile start/stop code.