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.
cudaDeviceReset()
at the end of your mexfunction. exit
at its end. NVIDIA Nsight Visual Studio Edition 2.2 should be able to profile you kernel.
Nsight Visual Studio CUDA Profiler has two features that should make this possible:
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.
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.