How can I avoid this error when creating a MEX file? "Error: Link of 'mexGPUexample.mex64' failed."

3 views (last 30 days)
Edward
Edward on 30 Dec 2013
Commented: Joss Knight on 14 Jan 2014
Hi all,
I am trying to compile the "mexGPUexample.cu" code according to the directions here: http://www.mathworks.com/help/distcomp/run-mex-functions-containing-cuda-code.html
I've followed the steps (changed environment variables, etc.) but when try to compile, I get the following:
>> mex mexGPUexample.cu
C:\PROGRA~1\MATLAB\R2013B\BIN\MEX.PL: Error: Link of 'mexGPUexample.mexw64' failed.
Unable to complete successfully.
Is there a problem with space characters in a path name somewhere? I'm running 64-bit Windows 7 with MATLAB R2013b and CUDA 5.5 with the MS Visual Studio 2012 Pro C compiler.
Any help is appreciated! Here is the verbose output:
>> mex -v mexGPUexample.cu
***************************************************************************
Warning: Neither -compatibleArrayDims nor -largeArrayDims is selected.
Using -compatibleArrayDims. In the future, MATLAB will require
the use of -largeArrayDims and remove the -compatibleArrayDims
option. For more information, see:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html
****************************************************************************
-> Default options filename found in C:\Users\e293911\Documents\MATLAB\Misc
----------------------------------------------------------------
-> Options file = C:\Users\e293911\Documents\MATLAB\Misc\mexopts.bat
MATLAB = C:\Program Files\MATLAB\R2013b
-> COMPILER = nvcc
-> Compiler flags:
COMPFLAGS = -gencode=arch=compute_13,code=sm_13 -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=\"sm_30,compute_30\" -c --compiler-options=/GR,/W3,/EHs,/D_CRT_SECURE_NO_DEPRECATE,/D_SCL_SECURE_NO_DEPRECATE,/D_SECURE_SCL=0,/DMATLAB_MEX_FILE,/nologo,/MD
OPTIMFLAGS = --compiler-options=/O2,/Oy-,/DNDEBUG
DEBUGFLAGS = --compiler-options=/Z7
arguments =
Name switch =
-> Pre-linking commands =
-> LINKER = link
-> Link directives:
LINKFLAGS = /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib gpu.lib cudart.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\ASP_2_~1\AppData\Local\Temp\mex_KtFoIb\templib.x" /MAP:"mexGPUexample.mexw64.map"
LINKDEBUGFLAGS = /debug /PDB:"mexGPUexample.mexw64.pdb"
LINKFLAGSPOST =
Name directive = /out:"mexGPUexample.mexw64"
File link directive =
Lib. link directive =
Rsp file indicator = @
-> Resource Compiler = rc /fo "mexversion.res"
-> Resource Linker =
----------------------------------------------------------------
--> nvcc -gencode=arch=compute_13,code=sm_13 -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=\"sm_30,compute_30\" -c --compiler-options=/GR,/W3,/EHs,/D_CRT_SECURE_NO_DEPRECATE,/D_SCL_SECURE_NO_DEPRECATE,/D_SECURE_SCL=0,/DMATLAB_MEX_FILE,/nologo,/MD -I"C:\Program Files\MATLAB\R2013b\extern\include" -I"C:\Program Files\MATLAB\R2013b\simulink\include" --compiler-options=/O2,/Oy-,/DNDEBUG -DMX_COMPAT_32 mexGPUexample.cu
Contents of C:\Users\ASP_2_~1\AppData\Local\Temp\mex_KtFoIb\mex_tmp.rsp:
mexGPUexample.obj
--> link /out:"mexGPUexample.mexw64" /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib gpu.lib cudart.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\ASP_2_~1\AppData\Local\Temp\mex_KtFoIb\templib.x" /MAP:"mexGPUexample.mexw64.map" @C:\Users\ASP_2_~1\AppData\Local\Temp\mex_KtFoIb\mex_tmp.rsp
C:\PROGRA~1\MATLAB\R2013B\BIN\MEX.PL: Error: Link of 'mexGPUexample.mexw64' failed.
Unable to complete successfully.
  7 Comments
Walter Roberson
Walter Roberson on 30 Dec 2013
It appears that it should have been /VERBOSE
My guess is that it is not going to help.
I wonder if maybe the wrong LINK program is being used, but I do not really know how to check that in MS Windows.

Sign in to comment.

Accepted Answer

James Lebak
James Lebak on 3 Jan 2014
Hi Edward,
You stated you were using CUDA 5.5 and VS 2012. When you build MEX files for the GPU, you must use the same version of the CUDA toolkit that was used to build the MATLAB GPU support. In the case of R2013b, that means CUDA 5.0. You can find out which CUDA toolkit version was used to build MATLAB from the gpuDevice command:
>> d=gpuDevice;d.ToolkitVersion
ans =
5
In addition, the MEX files that ship with R2013b are written for VS2010, as VS2012 was not officially supported by the CUDA 5.0 toolkit. If you have access to CUDA 5.0 and VS 2010 I would recommend trying that tool chain. If you are on maintenance and have access to the R2014a prerelease, you could also try compiling the code with that version of MATLAB, as it is written for CUDA 5.5.
  2 Comments
Joss Knight
Joss Knight on 14 Jan 2014
You can easily maintain both versions of CUDA for your purposes, you just need to manage your CUDA_PATH environment variable. Similarly, you wouldn't have any trouble installing VS2010 and VS2012 alongside each other, if you couldn't get VS2012 to play ball with CUDA 5.0.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!