简体   繁体   中英

Problems compiling CUDA with MEX in Matlab2014a

I am trying to compile a CUDA program using MEX within Matlab2014a and can't get it to work. I installed the newest CUDA toolbox (6.5) and driver (340.62) and the samples work correctly, so I guess it is correctly installed.

I also installed MS Visual Studio 2012 Professional and Matlab 2014a.

I followed the exact description in the Matlab Help in "GPU Computing -> Examples and How To -> Run MEX-Functions Containing CUDA Code". My CUDA file ends with .cu (so I am trying to compile Matlab's standard example mexGPUExample.cu, but I get the same error with other .cu files), the mex_CUDA_win64.xml is in the same folder, the environment variable MW_NVCC_PATH is set correctly in the user variables and just to be sure I also called "setenv('MW_NVCC_PATH,...)" in Matlab.

If I try to compile a CUDA example with

mex -largeArrayDims mexGPUExample.cu

I get the following error:

cl : Command line warning D9024 : unrecognized source file type 'mexGPUExample.cu', object file assumed 
cl : Command line warning D9027 : source file 'mexGPUExample.cu' ignored 
cl : Command line warning D9021 : no action performed 

D:\PROGRAMS\MATLAB~1\BIN\MEX.PL: Error: Compile of 'mexGPUExample.cu' failed. 

Unable to complete successfully.

I also tried to set the compiler correctly using

mex -setup

and chose the MS Visual Studio Compiler.

The code itself works because I tested it on other systems.

I have no idea what I am doing wrong. Any help is appreciated.

Matlab only supports CUDA 5.5 on R2014a, so your CUDA 6.5 by default cannot compile mex files under Matlab. Matlab R2014a supports VS 2012 now, but you need to verify you have VS 64-bit compiler if your Matlab is 64-bit. You can compile a normal .mex file with .cpp source file, (lots of these files under matlabroot/extern folder) to see whether Matlab works well with your VS.

Note that Matlab has a lag in supporting the latest compilers, both VS/gcc and Cuda. It is always good choice to check the compiler requirement by Matlab, before using the latest compilers.

Also check whether your Cuda kit and graphics drivers are correctly installed and work seamlessly with VS. You can compile and run some .cu files under the VS environment.

If you have finished all above and changed to the correct version of compilers, follow the instructions on matheworks website to compile the mexGPUExample file. If my memory is correct, you need to set environment variables and copy the XML file to the .mex file path. Then it should work.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM