Integrating cuda and matlab mex under OS X (and/or linux)
Hi,
I have installed cuda 4.1 on my MacBook pro. Does anybody have an idea on how to integrate matlab's mex files and cuda?

To be more precise, I want to know how to compile a mex file containing a cuda kernel under OS X (and/or linux).

I've googled a bit and found two approaches.
The approach found [url="http://www.mathworks.com/matlabcentral/newsreader/view_thread/261866"]here[/url] converts a .cu file to a .cpp file using nvcc and subsequently uses the mex compiler
to compile the .cpp file. Unfortunately this method didn't work for me and produced a whole bunch of errors while compiling the generated .cpp file.

Another method which uses "nvmex"(a modified version of mex which supports .cu files) can be found [url="http://staff.washington.edu/dushaw/epubs/Matlab_CUDA_Tutorial_2_10.pdf"]here[/url]. However this seems to be outdated
and unsupported with newer versions of cuda. Infact I was unable to find the download location of the "nvmex" file that the solution refers to.

Any idea on how to accomplish this with latest versions of cuda?

Thanks,
Sachintha.
Hi,

I have installed cuda 4.1 on my MacBook pro. Does anybody have an idea on how to integrate matlab's mex files and cuda?



To be more precise, I want to know how to compile a mex file containing a cuda kernel under OS X (and/or linux).



I've googled a bit and found two approaches.

The approach found here converts a .cu file to a .cpp file using nvcc and subsequently uses the mex compiler

to compile the .cpp file. Unfortunately this method didn't work for me and produced a whole bunch of errors while compiling the generated .cpp file.



Another method which uses "nvmex"(a modified version of mex which supports .cu files) can be found here. However this seems to be outdated

and unsupported with newer versions of cuda. Infact I was unable to find the download location of the "nvmex" file that the solution refers to.



Any idea on how to accomplish this with latest versions of cuda?



Thanks,

Sachintha.

#1
Posted 05/05/2012 12:45 PM   
See my [url="http://forums.nvidia.com/index.php?showtopic=228324&st=0&p=1401672&#entry1401672"]post here[/url], explaining the latest state of CUDA/MEX/MATLAB integration.
See my post here, explaining the latest state of CUDA/MEX/MATLAB integration.

John Melonakos ([email="john.melonakos@accelereyes.com"]john.melonakos@accelereyes.com[/email])

#2
Posted 05/06/2012 09:52 PM   
Go straight to object files instead of cpp.

From inside Matlab:

!nvcc -c my.cu -Xcompiler -fPIC -I /usr/local/matlab/extern/include

mex my.o -L /usr/local/cuda/lib64 -lcudart -lcufft ( or if you are on a 32 bit system /usr/local/cuda/lib)
Go straight to object files instead of cpp.



From inside Matlab:



!nvcc -c my.cu -Xcompiler -fPIC -I /usr/local/matlab/extern/include



mex my.o -L /usr/local/cuda/lib64 -lcudart -lcufft ( or if you are on a 32 bit system /usr/local/cuda/lib)

#3
Posted 05/06/2012 11:22 PM   
Scroll To Top