How to debug a mex file with CUDA code

Hi everyone,
hope this is the right place to post, I apologize if it is not.

I wrote a piece of code to run part of a program written in matlab to the gpu. I had to write a mex file to pass the data from matlab to C environment, than the cuda code to pass data from host to device, make here the computations and pass back the output from device to host to matlab again. Now I compiled the code and it gave me no errors but the output that I’m getting is not correct, it’s just zero. Now with a piece of “normal” code I would go step by step, ouputting intermediate results, to see where is the bug; but once given the data to the mex function it is like a black box untill I don’t have them back. How can I access the data flow to debug my code?

I managed to run the compute visual profiler but that is not of great help.

My system is windows xp 32bit and cuda 4.0

Does anyone have a suggestion?
Thanks

Hi everyone,
hope this is the right place to post, I apologize if it is not.

I wrote a piece of code to run part of a program written in matlab to the gpu. I had to write a mex file to pass the data from matlab to C environment, than the cuda code to pass data from host to device, make here the computations and pass back the output from device to host to matlab again. Now I compiled the code and it gave me no errors but the output that I’m getting is not correct, it’s just zero. Now with a piece of “normal” code I would go step by step, ouputting intermediate results, to see where is the bug; but once given the data to the mex function it is like a black box untill I don’t have them back. How can I access the data flow to debug my code?

I managed to run the compute visual profiler but that is not of great help.

My system is windows xp 32bit and cuda 4.0

Does anyone have a suggestion?
Thanks

Hi,

see: Debug Mex Files

bye

Hi PaCo, not sure if you’re aware, but the Jacket SDK makes life a lot easier (and code faster too) when trying to integrate CUDA with MATLAB. You might find this blog post interesting: http://blog.accelereyes.com/blog/2010/10/29/jacket_sdk_trumps_mex/

Cheers!

-John

I haven’t had to do this myself yet since my MEX usually needs the “round-trip” but isn’t it pretty trivial to implement this work-around yourself inside your mex-file? Call the mex with a certain flag/handle etc when you actually do want to retrieve the data ?

If you are using multiple MEX files you can get around this by using a bit of C++ or simply some pointer passing.Believe it’s disussed here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/278243

It is helpful if there is already software doing this for you though, I guess in the end its a development cost issue. :)

You can debug Matlab mexfiles including CUDA codes using Visual Studio and NVIDIA Nsight for Visual Studio by the procedure reported in https://devtalk.nvidia.com/default/topic/611272/cuda-programming-and-performance/integrate-cu-cpp-and-mex64-file-under-matlab/ and http://www.orangeowlsolutions.com/archives/564.