gpuDevice() toolkit version always 5.5

前端 未结 2 1633
清酒与你
清酒与你 2021-02-09 22:23

No matter how I reinstall the CUDA driver and toolkit, when typing gpuDevice(), it always show s:

CUDADevice with properties:

                      Name: \'Quad         


        
相关标签:
2条回答
  • 2021-02-09 22:41

    I do not see why this question gets down vote. This is the first question that I had in mind when I try to use CUDA in MEX.

    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,

    1. The installed cuda version is different from MATLAB cuda since they have their own library
    2. To trick it to load the new library, you might need to use install_name_tool to change the library link
    3. 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

    1. Go to /Applications/MATLAB_R2014a.app/bin/maci64(MAC) or MATLAB_ROOT/bin/glxna64(LINUX)
    2. 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?

    3. 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

    0 讨论(0)
  • 2021-02-09 22:44

    You can also use CUDA 6.5 with matlab under Windows. The tricky part is, you need to compile the mex files under Visual Studio rather than inside matlab. There are numerous tutorials introducing how to compile mex under VS so there is no need to repeat here. You need only to create a NVIDIA cuda project with .cu as the source, and follow the standard procedures to compile mex.

    0 讨论(0)
提交回复
热议问题