Undefined reference error when using mexcuda ubuntu - matlab

Ive installed matlab,gcc and CUDA toolkit on ubuntu .to use mexcuda .
but when i compile i get the following errors and i cant find any references on them anywhere .
Error using mex
/tmp/mex_42185702054896_15548/testmem04.o: In function `mexFunction':
tmpxft_00003e3a_00000000-5_testmem04.compute_70.cudafe1.cpp:(.text+0x152): undefined reference
to `__cudaPushCallConfiguration'
/tmp/mex_42185702054896_15548/testmem04.o: In function `__device_stub__Z9MulKernelPhPi(unsigned
char*, int*)':
tmpxft_00003e3a_00000000-5_testmem04.compute_70.cudafe1.cpp:(.text+0x35e): undefined reference
to `__cudaPopCallConfiguration'
collect2: error: ld returned 1 exit status
please note that when i first installed matlab, cuda 10 (my current version) was not supported by it , ive encountered the same thing when i installed matlab on windows , and fixed it by commenting a line in file "nvcc_g++.xml" and it works . when i did this in ubuntu matlab,matlab now detects the nvcc compiler but i get the previous error .
i realize "undefined reference errors " are linker errors , what should i do here ? i tried linking to cuda library but it didnt work .

For mexcuda, it is crucial that you match the CUDA toolkit to the version shipping with your installation of MATLAB (and Parallel Computing Toolbox). This is because Parallel Computing Toolbox ships a selection of libraries from the CUDA toolkit, and expects to be able to link against them. If you use the wrong version of the CUDA toolkit, all sorts of things can go wrong.
To check the appropriate version of the CUDA toolkit, look at the CUDA ToolkitVersion Version showing in the output from gpuDevice.
(Note that it is only the toolkit version that needs to match with MATLAB & PCT - it's almost always fine to get the latest driver).
For more details, see my answer https://uk.mathworks.com/matlabcentral/answers/432360-after-uninstalling-cuda-toolkit-still-matlab-responds-for-gpudevice over there on MATLAB Answers.

Related

Installing openCV on MATLAB with mex and MinGW64

I'm trying to install OpenCV on MATLAB2015b using mexopencv. I have downloaded and successfully installed MATLAB support for MinGW-w64 C/C++ Compiler add-on in MATLAB. This is MATLAB's suggested compiler when I type mex -setup. However, when I run mexopencv.make in MATLAB, I get the following error:
Error using mexopencv.make>pkg_config (line 333)
OpenCV library path not found: D:\opencv\build\x64\mingw\lib
Error in mexopencv.make>mex_options (line 265)
[cv_cflags, cv_libs] = pkg_config(opts);
Error in mexopencv.make (line 82)
mex_flags = mex_options(opts);
I have already added mexopencv-master directory to my MATLAB's Path. And I have already checked that I have downloaded the correct version of opencv for mexopencv (which is 3.4.1 as of now).
I don't know why \build\x64\mingw\lib\ doesn't exist. I have seen different tutorials but most of them use Microsoft Visual Studio 2013/2015 C++ to compile mexopencv. How can I compile OpenCV with MinGW-w64 on my own? Or is there another github package that I should've downloaded instead of this one?
I have tried to uninstall my current version of Visual Studio and install the 2013 version to use its C/C++ compiler. However, MATLAB doesn't recognize this compiler when I issue mex -setup.
Any help is appreciated. Also, I cannot use MATLAB's computer vision toolkit because I want to use a function that is not supported by it (Namely, the probabilistic Hough transform).

Matlab 2013 rapid accelerator fails after update (Debian 7 to Debian 8)

I have a simulink model created with Matlab 2013, which was working fine in the rapid accelerator mode on Debian 7 machine.
However, after an update to Debian 8 (and Matlab 2013) the simulation fails with a compilation warning and an error:
Warning:
matlab Warning: You are using gcc version 4.9.2 The version currently supported with MEX is 4.4.x. For a list of currently supported compilers see:...
Fatal error:
matlab 2013 /usr/bin/ld: cannot find -lstdc++collect2: error: ld returned 1 exit statusmex: link of ' "TestModel_sfun.mexa64"' failed.gmake Error 1
A related post is here, which is also a failure at the link step. However the solution, which for me is to install the package libstdc++-4.8-dev did not help, so something else seems to be missing.
Solution: install the build-essential package.
Turns out a colleague had the same problem earlier.

use library (gcc) in matlab and error with compile of mex

I am using Mac OSX (yosemite V 10.10.1) and running MATLAB 2014a on it.
I wanted to use SPAM library (sparse modeling software by J. Mairal) on MATLAB and for that I have to install XCode6.1 (that has gcc). First I type in command window mex -setup and result is shown below:
mex -setup
MEX configured to use 'Xcode with Clang' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
So after that I run the compile.m file in SPAM library and suddenly I saw an error that was:
add_flag =
-mmacosx-version-min=10.6
Warning: Directory already exists.
> In compile at 144
compilation of: -I./linalg/ -I./decomp/ -I./prox/ -I./dictLearn/ dictLearn/mex/mexArchetypalAnalysis.cpp
Building with 'Xcode Clang++'.
clang: warning: argument unused during compilation: '-fopenmp'
Error using mex
ld: warning: directory not found for option '-L/usr/lib/gcc/x86_64-linux-gnu/4.8/'
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in compile (line 439)
mex(args{:});
I don't understand what to do. please help me!
It appears that the actual error is occurring at the point of linking with precompiled libraries. The 2 issues are as follows:
The compile code apparently included in the compile.m file looks like it is intended to compile with gcc (it is trying to include files installed by GCC, possibly even linux-specific ones, are you sure that it's an OSX-compatible toolbox?), and yet the error strongly suggests that you are in fact using clang to compile it - you will either need to change the compiler (easy) or rewrite compile.m (not so easy).
One of the libraries that the code needs to have installed in order to be properly linked hasn't been found. On OSX I think this file should be called libgomp.dylib (any mac afficionados want to confirm this?). If you have it on your computer, then it's not in a directory that clang is looking in. You can confirm the library is installed by running find / | grep libgomp.dylib from the terminal - if it is there, you can add it into the compiler argument in compile.m using the -I /DIRECTORY_HOLDING_LIBRARY syntax.
It is entirely possible that fixing 1. will also remediate 2. - I have never tried using SPAM

GPUmat doesn't work in my matlab

I want to use GPU in matlab, so I installed CUDA toolkit(cuda_6.0.37), downloaded GPUmat 0.28 version. Of course my pc has geforce 850m. I clicked 'GPUstart', and it seems working and type the 'GPUmatSystemCheck', it says CUBLAS, CUFFT, CUDART installed, but there is warning 'GPUmat and SYSTEM architecture are different.'. My pc is 64 bit. Type the GPUsingle(1) on the command window, it says
'Warning: The following error was caught while executing 'GPUtype'
class destructor: Undefined function 'GPUtypeDelete' for input
arguments of type 'double'. Undefined function
'mxNumericArrayToGPUtypePtr' for input arguments of type
'GPUsingle'.'.
What should I do next? What am I missing?
I suppose you installed the newest version of GPUmat, which is a 32 bit version, and hence there is the warning. Maybe it would help to download an older version of GPUmat, which is made for 64 bit systems. I tried it myself and at least I don't get the warning anymore. Instead I have the problem that some DLL files are not found (Invalid MEX-file
'..\GPUmat\win64\bin\GPUfullInfo.mexw64': not found). You could still give it a try and see if it works for you.

Executing cuda program through Eclipse is giving error

I am using eclipse to execute a cuda program. I have downloaded a CUDA PLUGIN for
eclipse. When I execute sample cuda program given by plugin its fine but when I try
to execute any other program I am getting error undefined reference to main...
make
Building target: Add_cuda
Invoking: NVCC Linker
nvcc -L/export/trainee3/dinesh/cuda5.0/lib64 -o "Add_cuda" ./mycuda.o -lcudart
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
I found in stackoverflow that some times we get this problem because of system startup file
I used flag -nostartfiles but it is not working in my case..
I have included lib64 and include path in c++ build.
So any suggestion to over come this problem....
We've been over this already.
Use nsight eclipse edition instead.
If you have cuda 5.0 or 5.5 installed, just type nsight in a terminal session.
If you really want to use that Eclipse CUDA plugin (which is no longer supported, I don't believe), then start with the C++ sample project, which you agree now and back then would work. Then modify the source code in that project. Don't create your own project.
Install CUDA 5. It comes with Nsight Eclipse version. Very Elegant to use. NV Visual profiler is integrated with Nsight. Syntax highlighting and debug mode are very easy to use.