简体   繁体   中英

how to profile CUDA using Nvidia Visual Profile with Matlab

I need to profile my CUDA code from Matlab. I have been converting some of the matlab code to CUDA in order to increase performance. I have done this by calling a mexFunction which calls the CUDA. The matlab feval function doesn't provide enough control. I can run the mexFunction through VS to debug this, but i need to debug the kernel as well, as i believe this is were the issue is.

So, my question is how do i run the CUDA code through the profiler when executing the matlab functions that call it?

It isn't practical to hard code the values of all the inputs into the CUDA function.

I am running Matlab 2012a 64bit on windows 7 64bit with a Tesla C2050 GPU card

If what you need is to profile your performance and not the debugging functionality nSight also gives you, you can use the following trick I use to run the matlab program on the visual profiler without having to make an exe with a test main function:

Create a batch file with

matlab -nojvm -nodesktop -wait -sd "yourBaseFolder" -r "theMFunctionYouWantToRun;exit;"

Then run the script on the nVidia Visual Profiler.

I am using the feval CUDA API, so this has the added advantage of showing you what is it that Matlab is actually doing. I guess it should work when using MEX also, but never tried it. Let me know if it worked for the MEX files also.

You can profile Matlab mexfiles including CUDA codes using the NVIDIA Visual Profiler by the following procedure.

  1. Write your mexfile including CUDA code by the guidelines in Compiling CUDA mex files with Visual Studio .
  2. Add cudaDeviceReset() at the end of your mexfunction.
  3. Write your Matlab .m file end add exit at its end.
  4. Launch the NVIDIA Visual Profiler . File -> New Session.
  5. File: add the full path of the Matlab executable file , for example C:\\Program Files\\MATLAB\\R2012b\\bin\\win64\\MATLAB.exe .
  6. Working directory: add the full path of the Matlab .m file .
  7. Arguments: -nojvm -nosplash -r file_name_without_m_extension .
  8. Next -> Finish and that's it!

NVIDIA Nsight Visual Studio Edition 2.2 should be able to profile you kernel.

  1. Nsight | New Analysis Activity
  2. Set Activity Type to Profile CUDA Process Tree (matlab can launch another executable)
  3. Experiments to Run set to All

Nsight Visual Studio CUDA Profiler has two features that should make this possible:

  1. The activity Profile CUDA Process Tree will profile the CUDA process and all children processes of the launched process. This is important as I think the default implementation of Matlab is to launch the 32-bit variant and if on a 64-bit system then launch the 64-bit executable so simply launching Matlab is not sufficient.

  2. Nsight profiler supports in application kernel replay which supports running your kernel multiple times with the same input in one execution of the application.

The NVIDIA Visual Profiler collects results by running the application multiple times. It does not support launcher applications. This may be overcome by directly launching the correct version of Matlab.exe. Due to the application replay mechanism you may be able to profile using the Visual Profiler if you can automate running your mexFunction. I have not tried profiling Matlab with the Visual Profiler but I know the Nsight team has tested this in the past.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM