As @Robert mentioned, you have to use the same cuda version but not necessarily if you use simple trick (I'm using CUDA 6.0 and MATLAB CUDA version is 5.0). To make it work, you do not need the complicated procedure, nor the mex
for compiling all .cu
files and copying the xml file ( as in Link) to the directory to compile. Type simply the following two lines in the matlab command,
!nvcc -O3 -DNDEBUG -c mexGPUExample.cu -Xcompiler -fPIC -I/MATLAB_ROOT/extern/include -I/MATLAB_ROOT/toolbox/distcomp/gpu/extern/include;
mex mexGPUExample.o -L/usr/local/cuda-6.0/lib64 -L/MATLAB_ROOT/bin/glnxa64 -lcudart -lcufft -lmwgpu
Then it will magically work even if your ToolkitVersion mismatches. (Change /MATLAB_ROOT to your matlab root path)
Why MATLAB CUDA Toolkit version is different from System CUDA version?
Regarding your question, the installed CUDA version is not the same CUDA that MATLAB use.
If you go to
/matlabroot/bin/maci64 (OS X)
/matlabroot/bin/glnxa64 (unix variant)
depending on your os,
you can see the [dynamic linking library, shared library]
libcudart.5.5.[dylib, so]
libcublas.5.5.[dylib, so]
libcufft.5.5.[dylib, so]
These are the libraries that MATLAB uses. To make matlab to use system libraries, follow the instructions below. (MAC only)
In sum,
- The installed cuda version is different from MATLAB cuda since they have their own library
- To trick it to load the new library, you might need to use
install_name_tool
to change the library link
- Anyway you don't need it to have same version.
EDIT : How to make MATLAB to use System CUDA Library (OS X)
Make MATLAB to use System CUDA library, The default MATLAB CUDA library version is 5.5 and if you want to use the up-to-date library, read the following
Go to /Applications/MATLAB_R2014a.app/bin/maci64
(MAC) or MATLAB_ROOT/bin/glxna64
(LINUX)
See the library dependencies of libmwgpu.[dylib, so]
this is the entry library that is loaded when you use CUDA
The result would look like
dnab404675:maci64 user$ otool -L libmwgpu.dylib
libmwgpu.dylib:
@rpath/libmwgpu.dylib (compatibility version 0.0.0, current version 0.0.0)
.... Some Libraries
@rpath/libcublas.5.5.dylib (compatibility version 5.5.0, current version 5.5.20)
@rpath/libcudart.5.5.dylib (compatibility version 5.5.0, current version 5.5.20)
@rpath/libcufft.5.5.dylib (compatibility version 5.5.0, current version 5.5.20)
... and more
Our goal is to modify the library dependency of `cublas`, `cudart`, `cufft` to
> /usr/local/cuda/lib/libcublas.dylib (compatibility version 5.5.0, current version 5.5.20)
/usr/local/cuda/lib/libcudart.dylib (compatibility version 5.5.0, current version 5.5.20)
/usr/local/cuda/lib/libcufft.dylib (compatibility version 5.5.0, current version 5.5.20)
Note that if you type gpuDevice, it will still show it as toolkit version 5. But it loads the new version. So how we do that?
Simply type
sudo install_name_tool -change @rpath/libcufft.5.5.dylib /usr/local/cuda/lib/libcufft.dylib libmwgpu.dylib
sudo install_name_tool -change @rpath/libcudart.5.5.dylib /usr/local/cuda/lib/libcudart.dylib libmwgpu.dylib
sudo install_name_tool -change @rpath/libcublas.5.5.dylib /usr/local/cuda/lib/libcublas.dylib libmwgpu.dylib
I still don't know how to change the shared library path in Linux. Probably have to use hexadecimal editor such as HT From Stackoverflow Answer