Borrar filtros
Borrar filtros

Failed to complile MEX-Functions Containing CUDA Code

1 visualización (últimos 30 días)
Shaojun
Shaojun el 16 de Dic. de 2014
Respondida: Jan Barowski el 25 de Feb. de 2015
I am trying to compile the MATLAB provided example file mexGPUExample.cu following:
The "Set Up for MEX-File Compilation part" was fine. I copied the mex_CUDA_glnxa64.xml file to the current folder and run setenv command.
Then I start to compile mexGPUExample.cu by executing
mex -largeArrayDims mexGPUExample.cu
After it run for a few seconds it got the error message:
Building with 'nvcc'.
Error using mex
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(atexit.oS): In function
`atexit': (.text+0x12): undefined reference to `__cxa_atexit'
collect2: error: ld returned 1 exit status
My Machine is Ubuntu 14.04 with gcc 4.8.2 and g++ 4.8.2 The output of gpuDevice is attach in the file.
In order to compatible with mex compile requirement(matlab only support gcc-4.7.x), I set the system default compiler as gcc 4.7 and g++ 4.7 use the method described below:
How to change the default GCC compiler in Ubuntu?
and my output of gpuDevice is: CUDADevice with properties:
Name: 'GeForce GTX 650'
Index: 1
ComputeCapability: '3.0'
SupportsDouble: 1
DriverVersion: 6.5000
ToolkitVersion: 6
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 1.0734e+09
AvailableMemory: 490971136
MultiprocessorCount: 2
ClockRateKHz: 1110500
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1
When I searching for the solutions I only found 2 posts waiting for answer desperately. Lots of thanks to any one who can give a hand. >"<
  3 comentarios
Shaojun
Shaojun el 16 de Dic. de 2014
Yes my matlab version is 2014b the output is:
Verbose mode is on.
... Looking for compiler 'nvcc' ...
... Looking for environment variable 'MW_NVCC_PATH' ...No.
... Executing command 'which nvcc' ...Yes ('/usr/local/cuda-6.5/bin/nvcc').
... Executing command 'which g++' ...Yes ('/usr/bin/g++').
... Executing command 'g++ -print-file-name=libstdc++.so' ...Yes ('/usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so').
Found installed compiler 'nvcc'.
Options file details
-------------------------------------------------------------------
Compiler location: /usr/local/cuda-6.5/bin/nvcc
Options file: /home/shaojun/projects/voice/mex_CUDA_glnxa64.xml
CMDLINE1 : /usr/local/cuda-6.5/bin/nvcc -c --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I"/home/shaojun/tools/MATLAB2014b/extern/include" -I"/home/shaojun/tools/MATLAB2014b/simulink/include" -I"/home/shaojun/tools/MATLAB2014b/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_50,code=\"sm_50,compute_50\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG /home/shaojun/projects/voice/mexGPUExample.cu -o /tmp/mex_6677493866400559_14758/mexGPUExample.o
CMDLINE2 : /usr/bin/g++ -pthread -Wl,--no-undefined -shared -O -Wl,--version-script,"/home/shaojun/tools/MATLAB2014b/extern/lib/glnxa64/mexFunction.map" /tmp/mex_6677493866400559_14758/mexGPUExample.o -Wl,-rpath-link,/home/shaojun/tools/MATLAB2014b/bin/glnxa64 -L"/home/shaojun/tools/MATLAB2014b/bin/glnxa64" -lmx -lmex -lmat -lm -lmwgpu /home/shaojun/tools/MATLAB2014b/bin/glnxa64/libcudart.so.6.0 -o mexGPUExample.mexa64
CMDLINE3 : rm -f /tmp/mex_6677493866400559_14758/mexGPUExample.o
CXX : /usr/local/cuda-6.5/bin/nvcc
DEFINES : --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
NVCCFLAGS : -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_50,code=\"sm_50,compute_50\" $NVCC_FLAGS
CXXFLAGS : --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread
INCLUDE : -I"/home/shaojun/tools/MATLAB2014b/extern/include" -I"/home/shaojun/tools/MATLAB2014b/simulink/include" -I"/home/shaojun/tools/MATLAB2014b/toolbox/distcomp/gpu/extern/include/"
CXXOPTIMFLAGS : -O -DNDEBUG
CXXDEBUGFLAGS : -g
LDXX : /usr/bin/g++
LDFLAGS : -pthread -Wl,--no-undefined
LDTYPE : -shared
LINKEXPORT : -Wl,--version-script,"/home/shaojun/tools/MATLAB2014b/extern/lib/glnxa64/mexFunction.map"
LINKLIBS : -Wl,-rpath-link,/home/shaojun/tools/MATLAB2014b/bin/glnxa64 -L"/home/shaojun/tools/MATLAB2014b/bin/glnxa64" -lmx -lmex -lmat -lm -lmwgpu /home/shaojun/tools/MATLAB2014b/bin/glnxa64/libcudart.so.6.0
LDOPTIMFLAGS : -O
LDDEBUGFLAGS : -g
OBJEXT : .o
LDEXT : .mexa64
NVCC : /usr/local/cuda-6.5/bin/nvcc
GCC : /usr/bin/g++
CPPLIB_DIR : /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so
MATLABROOT : /home/shaojun/tools/MATLAB2014b
ARCH : glnxa64
SRC : /home/shaojun/projects/voice/mexGPUExample.cu
OBJ : /tmp/mex_6677493866400559_14758/mexGPUExample.o
OBJS : /tmp/mex_6677493866400559_14758/mexGPUExample.o
SRCROOT : /home/shaojun/projects/voice/mexGPUExample
DEF : /tmp/mex_6677493866400559_14758/mexGPUExample.def
EXP : mexGPUExample.exp
LIB : mexGPUExample.lib
EXE : mexGPUExample.mexa64
ILK : mexGPUExample.ilk
MANIFEST : mexGPUExample.mexa64.manifest
TEMPNAME : mexGPUExample
EXEDIR :
EXENAME : mexGPUExample
OPTIM : -O -DNDEBUG
LINKOPTIM : -O
-------------------------------------------------------------------
Building with 'nvcc'.
/usr/local/cuda-6.5/bin/nvcc -c --compiler-options=-D_GNU_SOURCE,-DMATLAB_MEX_FILE -I"/home/shaojun/tools/MATLAB2014b/extern/include" -I"/home/shaojun/tools/MATLAB2014b/simulink/include" -I"/home/shaojun/tools/MATLAB2014b/toolbox/distcomp/gpu/extern/include/" -gencode=arch=compute_20,code=sm_20 -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_50,code=\"sm_50,compute_50\" $NVCC_FLAGS --compiler-options=-ansi,-fexceptions,-fPIC,-fno-omit-frame-pointer,-pthread -O -DNDEBUG /home/shaojun/projects/voice/mexGPUExample.cu -o /tmp/mex_6677493866400559_14758/mexGPUExample.o
/usr/bin/g++ -pthread -Wl,--no-undefined -shared -O -Wl,--version-script,"/home/shaojun/tools/MATLAB2014b/extern/lib/glnxa64/mexFunction.map" /tmp/mex_6677493866400559_14758/mexGPUExample.o -Wl,-rpath-link,/home/shaojun/tools/MATLAB2014b/bin/glnxa64 -L"/home/shaojun/tools/MATLAB2014b/bin/glnxa64" -lmx -lmex -lmat -lm -lmwgpu /home/shaojun/tools/MATLAB2014b/bin/glnxa64/libcudart.so.6.0 -o mexGPUExample.mexa64
Error using mex
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(atexit.oS): In function
`atexit':
(.text+0x12): undefined reference to `__cxa_atexit'
collect2: error: ld returned 1 exit status
Joss Knight
Joss Knight el 22 de Dic. de 2014
What is the output of !/usr/bin/g++ --version?

Iniciar sesión para comentar.

Respuesta aceptada

Joss Knight
Joss Knight el 22 de Dic. de 2014
The problem appears to be that you're using a more recent version of the CUDA Toolkit than is supported by MATLAB. You are using version 6.5, whereas R2014b only supports version 6.0. You are therefore using an incompatible version of nvcc.
Make sure you've got CUDA 6.0 installed, then set MW_NVCC_PATH to point to it:
>> setenv MW_NVCC_PATH /usr/local/cuda-6.0/bin
Then try again.
  1 comentario
Samarth
Samarth el 5 de Feb. de 2015
Thanks for your suggestion. I installed CUDA 6.0 and modified MW_NVCC_PATH, but the error persists. Do you have any more ideas?
Thanks!

Iniciar sesión para comentar.

Más respuestas (2)

Kai
Kai el 17 de Feb. de 2015
I met withe exactly the same problem. Did you finally figure out a solution?
Thanks in advance!

Jan Barowski
Jan Barowski el 25 de Feb. de 2015
I got the same error using Matlab 2015 Prerelease on Ubuntu 14.04 with CUDA 6.5 and g++4.8. Thanks to Matlab support we figured out, that manually linking does the trick. Here is my compile script for the matlab mex/gpu example:
myArch = computer('arch'); pathToOpts = fullfile(matlabroot, ... 'toolbox', 'distcomp', 'gpu', ... 'extern', 'src', 'mex', myArch,'gcc',... ['mex_CUDA_' myArch '.xml']); copyfile(pathToOpts,'.','f')
mex -v -largeArrayDims mexGPUExample.cu -lstdc++ -lc
Hope this helps!

Categorías

Más información sobre MATLAB Compiler en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by