OpenCL and MEX-FILES ERROR - matlab

I am constantly running across a problem for a week. I don't know what the issue could be. Hope you could help me. Thank you in advance.
So here is brief description of the issue.
I am trying to use OpenCL and Mex code. The Mex part of the code reads a matlab .dat file and the opencl part of code further runs the code on Intel CPU as of now, though future plan would be to run it on a GPU. The Intel PLatform is being detected on just a normal OPENCL code ( without mex)(platforms 1,Devices 1). But on using the OPenCL with Mex, OpenCl fails to recognize the Intel Platform ( platforms found 0 , error :1001).
Just by including the MEX part of the code the number of platforms shown is zero. I am using matlab Compile runtime (MCR) to compile the mex files.
make :
mpicxx -fPIC -L/opt/intel/opencl-1.2-4.4.0.117/lib64 -L/usr/local/MATLAB/MATLAB_Compiler_Runtime/v83/bin/glnxa64 test.cpp -o test -lOpenCL -I/usr/include/CL -lmat -lmx -lmex -I/usr/local/MATLAB/MATLAB_Compiler_Runtime/v83/extern/include -Wl,-rpath,/opt/intel/opencl-1.2-4.4.0.117/lib64,-rpath,/usr/local/MATLAB/MATLAB_Compiler_Runtime/v83/bin/glnxa64
Is there some problem with the way I am linking the files?

Most probably what happens is the following. MATLAB ships with some version of tbb (Intel Threading Building Blocks) library and this version is older than the one required by Intel OpenCL CPU runtime. When you run standalone OpenCL application the correct version of TBB is loaded (the one that comes with OpenCL runtime), but when MATLAB starts it loads its own version of TBB.
So, one solution would be to use LD_PRELOAD before starting MATLAB, like so:
$ LD_PRELOAD=/opt/intel/opencl-1.2-4.4.0.117/lib64/libtbb.so matlab

Same Problem here:
Any C/C++ Program not running as a MEX module will see the Intel OpenCL Platform AND the Nvidia OpenCL Platform. But while inside a MEX module only the Nvidia OpenCL Platform will show up.
Using the same Intel OpenCL release ( 4.4.0.117 ) in combination with Matlab R2012b on openSUSE 2012.2. I assume you are using Matlab 2014a.
The same problem exists when using the inofficial Matlab OpenCL Toolbox:
wiki
download
To replicate:
unzip, fix path for OpenCL headers and libOpenCL in make.m
run matlab and go to directory with make.m, then type:
make
opencl_info = opencl()
opencl_info.platforms
Edit:
Yuri is right, as soon as you preload the correct libtbb.so it works.
You could also replace the libtbb.so in your $MATLABROOT/bin/glnxa64/libtbb.so.2 with a link to the current one from the Intel OpenCL Runtime.

Related

CMake Error at HW1_generated_student_func.cu [duplicate]

I'm currently trying to compile Darknet on the latest CUDA toolkit which is version 11.1. I have a GPU capable of running CUDA version 5 which is a GeForce 940M. However, while rebuilding darknet using the latest CUDA toolkit, it said
nvcc fatal : Unsupported GPU architecture 'compute_30'
compute_30 is for version 3, how can it fail while my GPU can run version 5
Is it possible that my code detected my intel graphics card instead of my Nvidia GPU? if that's the case, is it possible to change its detection?
Support for compute_30 has been removed for versions after CUDA 10.2. So if you are using nvcc make sure to use this flag to target the correct architecture in the build system for darknet
-gencode=arch=compute_50,code=sm_50
You may also need to use this one to avoid a warning of architectures are deprecated.
-Wno-deprecated-gpu-targets
I added the following:
makefiletemp = open('Makefile','r+')
list_of_lines = makefiletemp.readlines()
list_of_lines[15] = list_of_lines[14]
list_of_lines[16] = "ARCH= -gencode arch=compute_35,code=sm_35 \\\n"
makefiletemp = open('Makefile','w')
makefiletemp.writelines(list_of_lines)
makefiletemp.close()
right before the
#Compile Darknet
!make
command. That seemed to work!

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

cplex would not run on matlab due to invalid mex-file

I'm trying to use cplex on matlab but I'm getting the following error:
Error using cplexlp (line 256)
Invalid MEX-file 'C:\Program
Files\IBM\ILOG\CPLEX_Studio1271\cplex\matlab\x64_win64\cplexlink1271.mexw64': The specified
procedure could not be found.
Error in cplex_example (line 12)
[x,fval,exitflag,output] = cplexlp(f,A,b,Aeq,beq,lb,ub,options);
I have already added the paths as follows:
addpath ('C:\Program Files\IBM\ILOG\CPLEX_Studio1271\cplex\matlab\x64_win64')
addpath('C:\Program Files\IBM\ILOG\CPLEX_Studio1271\cplex\examples\src\matlab')
savepath
My laptop runs on Windows 10 64-bit, my matlab is R2013a 64-bit and cplex is cplex 12.7.1 win-x86-64.
I saw an answer to a similar question and they said it must be checked by dependency walker. Dependency walker showed that a whole bunch of API-MS-WIN-CORE, EVENTING, SECURITY, SERVICE, EXT-MS-WIN-GDI etc. dll files where missing.
I looked at a few posts implying that these are included in Visual C++ Redistributable packages, so I installed all editions of Microsoft Visual C++ Redistributable (both x86 and x64 just to be sure).
But I still have the problem. What am I missing here? Any help would be greatly appreciated.
MATLAB R2013a is not supported with CPLEX 12.7.1 (see the detailed system requirements). You'll either have to use a newer version of MATLAB or an older version of CPLEX.

Matlab mex can not build but gcc can

I'm new to Matlab and was trying to build a C file. The code gets compiled fine with gcc (4.8.4 in 64-bit Ubuntu). But when I try to build with mex, it shows following error:
error: exponent has no digits
I'm not sure what I'm doing wrong. The error is in this file. Complete error log is here.
When I compile the code using gcc, there are no errors. I do not provide any special arguments to gcc. To my knowledge, mex is using gcc so I do not understand why mex is failing to build the code.
I've little knowledge of C programming and any help is highly appreciated!
Edit:
To clarify more, I've got the source in two files:
File 1 has the C code with a main function, and uses functions from this
file (which mex can not build).
File 2 has the C code of the S-Function which call's File 1's main function. File 2 has an include statement to include File 1.
When I said I can build using gcc, I just built File 1 with this command: gcc file1.c -o file1. I think not building File 2 with gcc has no impact here in my question, as only File 1 uses those functions from the file which mex can not build.
I used this command from Matlab mex file2.c to build and got the error.
For C code, you probably need to enable GNU extensions for C99 (-std=gnu99). As described in my previous post on enabling C99, to pass this to mex:
mex -v -largeArrayDims CFLAGS="\$CFLAGS -std=gnu99" mexSouce.c
The reason the default does not work is because mex likes to choose the ANSI standard, which is often not the newest.

which configuration option is used by Mex to compile using matlab?

say, if choose mexopts.sh as the configuration files for mex,
then how does mex decide which option listed in the mexopts.sh is used for compiling?
for example, using 32bit matlab on 64bit mac os x:
mexopts.sh looks like:
,,maci
........
,,maci64
......
Then, maci or maci64 is used when compiling?
What commands or way can I do in order to compile 32bit lib instead of 64bit lib?
Further explanation of my process and the error message I got :
I am using mac os x 10.8 (64bit) with matlab R2010a (32bit) to produce a binary mex-file.
The Xcode is 4.6 version, I installed Command Line Tools on my machine. Then I downloaded the patch from matlab for 2011 and 2012 version anyway. (if I don't install the patch, I got a lot of link errors saying some header files are missing).
After I installed the patch ( I believe it changes my mexopts.sh file), when I run mex a.cpp, I got error message saying that /Applications/MATLAB_R2010a.app/bin/maci64 cannot be found. Of course, it cannot find the maci64 folder, it is 32bit, there is only maci folder.
So Anyone knows what I should do in order to make matlab look for maci folder instead of maci64 folder? Thanks a lot!
MATLAB does not support cross compilation of MEX files. So your 32-bit MATLAB installation should be producing 32-bit MEX files even though the OS is 64-bit.
Also, from the article I've linked
Further, beginning with R2010b, a 32-bit version of MATLAB is no longer produced for the Mac.
If you're running R2010b or later, your MATLAB is not 32-bit anyway.
To see what switches the MEX script is invoking the compiler with, use the -v option.
You can also use the file tool to check whether the generated binary is 32 or 64-bit.
As its been explained, MATLAB produces MEX files of the same bit-ness as itself, not that of the OS. This is true at least on Windows with recent MATLAB versions, where you can have either 32-bit or 64-bit MATLAB running on 64-bit Windows. Other platforms are moving towards 64-bit versions only.
Here is another way to get the configured mex switches:
>> cc = mex.getCompilerConfigurations
>> cc.Details
In my case I get:
>> cc = mex.getCompilerConfigurations
cc =
CompilerConfiguration with properties:
Name: 'Microsoft Visual C++ 2010'
Manufacturer: 'Microsoft'
Language: 'C++'
Version: '10.0'
Location: 'C:\Program Files\Microsoft Visual Studio 10.0'
Details: [1x1 mex.CompilerConfigurationDetails]
LinkerName: 'Microsoft Visual C++ 2010'
LinkerVersion: '10.0'
>> cc.Details
ans =
CompilerConfigurationDetails with properties:
CompilerExecutable: 'cl'
CompilerFlags: [1x115 char]
OptimizationFlags: '/O2 /Oy- /DNDEBUG'
DebugFlags: '/Z7'
LinkerExecutable: 'link'
LinkerFlags: [1x327 char]
LinkerOptimizationFlags: ''
LinkerDebugFlags: '/debug /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"'
To answer my own question, just for those who may be interested in it,
I checked the contents of mexopts.sh and modified the part for maci (specifically set ARCH=i386) , then compile. The error message is gone.