Get started with CUDA in Matlab - matlab

Hey there,
I need to get started to Cuda in Matlab. As I need additional functions than provided from matlab, I need to write my own c++ code, e.g. I want to run my program on 1..N GPU-processors and compare the results to calculate the speedup, which is not supported by Matlab itself (as Matlab always optimizes itself to use all processors).
Now I wonder how to get started best. I already read a lot of papers, but I still wonder for example, what those files are all about:
.cu
.cubin
.ptx
.mex
So which way do I need to go? Writing my code to a .cu file and than compiling it (which tool to use?
My computer is:
Q9550 with GTX460,
Win7 x64,
Matlab R2010b x64,
Visual Express C++ 2008 (free -> 32bit version),
Cuda Toolkit 3.2 (64bit),
Latest Nvidia Driver and GPU Programming SDK 3.2.16_win_64
How to get on? When I try to open one of the examples out of the GPU Programming SDK, e.g. the file vectorAdd_vc90.vcproj ouf ot C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\src\vectorAdd
I get
"The following XML parsing-error occured:
File: C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\src\vectorAdd\vectorAdd_vc90.vcproj
Row: 22
Column: 4
Fehlermeldung:
The user build-file "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\VCProjectDefaults\NvCudaRuntimeApi.rules" wasnt found or couldn't be loaded
The file "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\src\vectorAdd\vectorAdd_vc90.vcproj" couldn't be loaded"
When I just open the vectorAdd.cu I don't find any way to compile it to run it in Matlab. Perhaps it would also be possible to just work completely without Visual Studio, so that I write my code in Notepad++ for example and compile it myself?
Thanks a lot in advance guys!

If you have access to Parallel Computing Toolbox, you can use the GPU directly using GPUArrays. You can also more easily integrate your own hand-written CUDA code using the parallel.gpu.CUDAKernel object

If the parallel toolbox isn't available, you can still use the mexFunction capability to use the GPU's
http://www.mathworks.com.au/help/distcomp/create-and-run-mex-files-containing-cuda-code.html
I dont think this is available for earlier versions than 2013a. In this case, you can write the mexfunction entry point and include the cuda function calls to pass the memory to and from the device
http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/

Related

Missing file .mex error on a newer matlab version

I have a .mex code that properly works on Matlab 2012b (32bit).
However, I would like to make it work also on Matlab 2019b (64bit).
When I run it in Matlab 2019, even though the directory is introduced in the path, the error that I get is:
Missing file directm.mex
Have somebody encountered this kind of problem?
Specifically, the toolbox is "forcefeedback toolbox"
https://de.mathworks.com/matlabcentral/fileexchange/4939-force-feedback-toolbox-for-matlab-simulink
Many thanks!
Your MEX-file is a 32-bit binary. You cannot combine it with a 64-bit binary (the newer MATLAB program). The only way to get this to work is to recompile the MEX-file with the newer MATLAB. Unfortunately it looks like this File Exchange submission doesn't come with the sources to the MEX-file. So you are, unfortunately, out of luck.

Compile standalone Matlab guide program for Windows using Ubuntu

I'm using Matlab R2016a. I'm following this video to compile my Matlab guide program as standalone application. However I can only see options to compile it for a Linux platform. Is it also possible to compile it for Windows using the Linux version of Matlab?
Sadly, at present, the answer to your question is no. In Matlab you cannot achieve cross compilation of executables. The Matlab Compiler is strictly tied to the machine environment.
The basic rule is that in order to build an executable that can run under operating system X, it must be compiler under operating system X.
Therefore, you need to install the Matlab Compiler on a Windows machine to create an executable that can run under Windows. On the top of that, Windows represents a special case in which you have to consider the difference between 32 and 64 bit versions. For more infos, read these threads:
https://it.mathworks.com/matlabcentral/answers/4649-deploy-for-windows-32-bit-from-a-64-bit-computer
https://it.mathworks.com/matlabcentral/answers/217297-32-bit-exe-compilation-using-matlab-64-installed
https://it.mathworks.com/matlabcentral/answers/60904-compile-executable-for-64-bit-system

looking for MCR7.9 (for MATLAB R2008b

My m file was compiled by MATLAB R2008b. When I distributed it to others, their PC seem to lack certain DLL (mclmcrrt79.dll). Thus, I was looking for MCR7.9 but couldn't find any official copy. I did find some on the web: MCR7.9 download but am not sure whether it is safe to be installed. Is it OK to use this copy or is there any official MCR7.9 available?
Since R2012a, the MCR for each version of MATLAB has been available as a download from MathWorks.
Versions of the MCR prior to R2012a are not distributed in the same way by MathWorks, and should be distributed by the developer of the application along with the compiled component directly to end users. If you are the developer, you should distribute it along with the component - specifically, you should send them the MCR installer (you have this - it's in \toolbox\compiler\deploy\<ARCH>, where <ARCH> is your platform).
In fact, in R2012a there was a license-related change: for versions prior to that, you're not actually allowed to make the MCR (or the installer) available as public download (so the people who are making it available at the SourceForge site you link to are, strictly speaking, in breach of the license).
One other confusion may be causing you difficulty: R2008b is MATLAB version 7.7. MATLAB version 7.9 is R2009b. You need to make sure that you use the right version of the MCR for the version of MATLAB you used to compile.
For reference, I solved the problem related to "My Own Exception: Fatal error finding symbol mxCalcSingleSubscript_700 in D:\XYZ\libmx.dll Error:" It was done by sending libmx.dll to the user. The file is stored at \MATLAB\bin\win32\

How to start SVM training on MATLAB

I have a set of facial features that i have obtained and would like to classify using SVM. I intend to use libsvm package and use MATLAB to carry out the training.I have already read up on SVM by watching the Stanford lecture. But I am not sure how to use libsvm to start.. Need some guidance...
In matlab you can link your matlab code with some programs implemented in c. This a called a mex-file.
However you need to compile them, to make it work.
You can read the readme file to know how to compile them:
Installation
On Unix systems, we recommend using GNU g++ as your compiler and type
'make' to build 'svmtrain.mexglx' and 'svmpredict.mexglx'. Note that
we assume your MATLAB is installed in '/usr/local/matlab', if not,
please change MATLABDIR in Makefile.
Example:
linux> make
To use Octave, type 'make octave':
Example: linux> make octave
On Windows systems, pre-built binary files are already in the
directory `..\windows', so no need to conduct installation. Now we
include both 32bit binary files and 64bit binary files, but in future
releases, we will provide binary files only for 64bit MATLAB on
Windows. If you have modified the sources and would like to re-build
the package, type 'mex -setup' in MATLAB to choose a compiler for mex
first. Then type 'make' to start the installation.
Example:
matlab> mex -setup
(ps: MATLAB will show the following messages to setup default compiler.)
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
1 Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio
[0] None
Compiler: 1
Please verify your choices:
Compiler: Microsoft Visual C/C++ 7.1
Location: C:\Program Files\Microsoft Visual Studio
Are these correct?([y]/n): y
matlab> make
For list of supported/compatible compilers for MATLAB, please check
the following page:
http://www.mathworks.com/support/compilers/current_release/

How to install a compiler on Windows? (For a Matlab program)

I have downloaded this code;
http://www.cs.sfu.ca/%7Emori/research/superpixels/superpixels64.tar.gz
In the readme file, it says;
Run mex -largeArrayDims on *.c in yu_imncut directory
-largeArrayDims is needed for 64bit architectures (thanks to Richard Lowe for providing fixes for 64bit MATLAB)
Obtain mfm-pb boundary detector code from
http://www.cs.berkeley.edu/projects/vision/grouping/segbench/
Change path names in sp_demo.m and pbWrapper.m
Get a fast processor and lots of RAM
Run sp_demo.m
I tried to do the mex -.. one but it told me that I don't have any compiler. How can I fix this? Can you please help me with this? I am using 64 bit Windows 7
As far as I know GCC for Windows is not supported by Matlab. Visual Studio Express Editions will work, but 2010 may require a patch dependent on the version of Matlab you are running (http://www.mathworks.com/support/compilers/R2011a/win32.html). This page lists all supported compilers for Matlab.
Here's a link to GCC for windows
http://gcc.gnu.org/install/specific.html#windows