Hi,
I have a quick question regarding OpenCL and mex files. Mex files are type of files that are used in Matlab to interface your C/CPP code to Matlab. I know it is not a Matlab forum but I thought may be some of you might have already tried doing it so would be kind enough to share your experiences.
Suppose I write a gateway function to interface a cpp code that is using some OpenCL calls. Then would I be able to run the mex file without any problem given that Matlab part is not using OpenCL? In other words does gateway function work as a isolator between CPP world and Matlab world?
thanks,
newbie
Originally posted by: richeek.arya Hi,
Suppose I write a gateway function to interface a cpp code that is using some OpenCL calls. Then would I be able to run the mex file without any problem given that Matlab part is not using OpenCL?
You can run without any problem. I am able to port MatrixMulImage and MonteCarloAsian using mex files and called from Matlab.
Originally posted by: genaganna Originally posted by: richeek.arya
You can run without any problem. I am able to port MatrixMulImage and MonteCarloAsian using mex files and called from Matlab.
Thanks for your reply. Is there any catch, any limitations in doing that?
Hi genaganna,
How did you compile from Matlab. I am using Matlab 2010a and Visual Studio 2010 Professional. When I try to compile using following command:
mex -g -I'C:\Users\Richeek\Documents\ATI \Stream\samples\opencl\cl\app\GPU_LSD C:\Program Files (x86)\ATI Stream\include\' template.cpp
I am getting the following output (with the error):
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
cl : Command line error D8003 : missing source filename
C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'template.cpp' failed.
Any idea??
regards,
newbie
Please read following
1. How to compile .CPP file from Matlab. a. Set up mex compiler from Matlab. i. Open command window ii. Type "mex -help". You should see help message from mex otherwise make sure your Matlab binaries are in PATH. iii. Select C++ compiler available on your system a. Type "mex -setup". It will display following message Please choose your compiler for building external interface (MEX) files: Would you like mex to locate installed compilers
/n? b. Type "y" then it will display list of compiler and will ask you to select compiler I got following on my system Select a compiler: [1] Intel C++ 11.1 (with Microsoft Visual C++ 2008 SP1 linker) in G:\Intel\Compiler\11.1\054\ [2] Microsoft Visual C++ 2008 SP1 in C:\Program Files (x86)\Microsoft Visual Studio 9.0 [0] None Compiler: c. Type "n" where n is integer. It will display compiler information and asks to verify. I got following message after typing integer 2 Please verify your choices: Compiler: Microsoft Visual C++ 2008 SP1 Location: C:\Program Files (x86)\Microsoft Visual Studio 9.0 Are these correct /n? d. Type "y" if it is right compiler otherwise do setup again from step a. e. Now mex can compiler cpp files. b. Set CPP compiler options a. Give options directly to mex. b. Add required things to mexopts.bat(Available at C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2010a\mexopts.bat in my case) mexopts.bat file is copied by mex while setting up mex compiler. Add following to compile any OpenCL API code. i. Add %AMDAPPSDKROOT%\include; to INCLUDE ii. Add /LIBPATH:"%AMDAPPSDKROOT%\lib\x86_64" OpenCL.lib to LINKFLAGS.(x86_64 is because my Matlab is 64 bit Matlab) c. Add path of .cpp file File-> set path c. Compile CPP file mex -v CLMonteCarloAsian.cpp 2.Known issues of Matlab. 1. Using std::cout will not work as expected in C++ MEX-files. This is because cout is expecting to use a display that is not MATLAB. To workaround this problem, use mexPrintf or printf instead. 3.References 1. http://www.mathworks.com/support/tech-notes/1600/1605.html#C_compiling
Thanks a lot genaganna!!!
It is working now.