How to install opencl-toolbox 0.17 (Jan 2011) for matlab:
http://code.google.com/p/opencl-toolbox/
in Matlab 2011a under Windows 7 64 bits.
The goal of opencl-toolbox is to provide an opensource toolkit that provides seamless integration of Matlab with OpenCL.
MATLAB® is a high-level language and interactive environment for numerical computation, visualization, and programming.
Open Computing Language (OpenCL) is a framework for writing programs that execute across heterogeneous platforms consisting of central processing unit (CPUs), graphics processing unit (GPUs), and other processors (wikipedia dixit).
In this case, the three elements will allow you to use the tremendous processing capacity of an OpenCL capable graphics card from Matlab.
This can speed up some calculations a factor of ten or more due to the fact that your GPU can have about a thousand ALUs working on parallel (!). Your CPU have at most 16 ALUs: much more less!
Sometimes the achievement is less, sometimes is more, depending on algorithms, memory accesses and other factors.
- Windows 7 64 bits
AMD APP SDK v2.7
Matlab 2011a
opencl-toolbox for matlab
* Previous packages installation:
AMD Catalyst Display Driver
AMD APP SDK v2.7
.NET Framework version 4
Windows SDK 7.1 1
graphics card ATI HD 6770
It’s really an ATI HD 5770 with very little fw modifications:
- 40nm 850 GHz core (800:40:16),
- 1024 MiB 1200 MHz DDR5, 1360 GFLOPS,
- 12.59 GFLOPS/W
- TDP: 18 W idle, 108 W max
Note that GFLOPS values are theoretical maximums: it is just the product of core frequency by the number of cores (ATI’s unified shaders) by two (as the cores can make two operations per cycle over the same data, on ideal conditions, in order to hide the memory access/core frequency great difference).
In this case: 850 MHz * 800 * 2 = 1360 GFLOPS = 1.36 TFLOPS (!)
This value will never be reached in a program, most frequently because data must be retrieved from memory, and this step is much slower than core frequency. There are intermediate caches, but nevertheless data will be typically as massive as the expected data processing speed.
Windows 7 64 bits
AMD APP SDK v2.7
This is the package from AMD (which owns ATI) that installs necessary libraries and headers for programming with OpenCL.
Matlab 2011a
package opencl-toolbox for matlab
which is not a stable package from Matlab, but a libre one.
* PREVIOUS PACKAGES INSTALLATION
Installation of AMD APP SDK v2.7
This is the package from AMD (which owns ATI) that install necessary libraries and headers for programming with OpenCL.
http://developer.amd.com/sdks/amdappsdk/downloads/pages/default.aspx
- AMD-APP-SDK-v2.7-Windows-64.exe (148 MB )
- Microsoft® Windows Vista® and Microsoft® Windows® 7
- 05/18/2012 64-bit AMD APP SDK built for 64-bit
This could be necessary to previously install AMD Catalyst™ Display Driver:
http://support.amd.com/us/gpudownload/windows/Pages/radeonaiw_vista64.aspx
- Catalyst Software Suite 145.5 MB
- 12.8 8/15/2012
- Description:
- Package contains the following graphics drivers and dependent/required software for the products specified in the current version’s official release notes for the 64 bit version of Windows Vista and Windows 7:
- Display Driver
- OpenCL(tm) Driver
- AMD Integrated Driver
- Catalyst Control Center
Installation of a C compiler supported by Matlab 2011a:
Matlab does not provide a C compiler, which is necessary in order to use “mex” matlab function to compile opencl-toolbox.
The list of supported C compilers is provided here:
http://www.mathworks.es/support/compilers/R2011a/win64.html
From the listed compilers I’ve chosen the free option:
- Microsoft Visual C++ 2010 Express and Windows SDK 7.1 1
- Available at no charge
and more exactly: Windows SDK 7.1 1
Windows SDK 7.1 1 can be downloaded here:
http://www.microsoft.com/en-us/download/details.aspx?id=8279
The package requires the previous installation of the .NET Framework version 4, or it will not install de compilers, which is the key option that we’re looking for.
Note that it is not enough the .Net Client Framework.
So first install the .NET Framework version 4 from here:
http://www.microsoft.com/en-us/download/details.aspx?id=17851
Now, install Windows SDK 7.1, and be sure to select the option “Compilers” during the process.
The process is described here:
http://code.google.com/p/opencl-toolbox/wiki/Install_Guide
Nevertheless, it’s tested with Matlab 2010 and OpenCL 1.1, and some things have changed since then.
First of all, decompress the toolbox under in Matlab root directory (usually C:\Program Files\MATLAB\R2011a), under directory “toolbox” (it’s the easiest path, though any other path is possible).
http://code.google.com/p/opencl-toolbox/downloads/detail?name=opencl-toolbox-0.17.zip&can=2&q=
Now, in opencl-toolbox directory there’s a file called “make.m”.
Open it with your favourite text editor, and change this two values:
opencl_include_dir = 'C:\Program Files (x86)\AMD APP\include';
opencl_lib_dir = 'C:\Program Files (x86)\AMD APP\lib\x86_64';
Save it.
Now, as it is programmed for OpenCL 1.1, we have to modify the code in order to load the correct functions from opencl.h, so open
- src/openclcmd.cpp
and insert this as line 29: it’s just a new line before all the “#include” lines it has:
#define CL_USE_DEPRECATED_OPENCL_1_1_APIS // in order to correctly find some old opencl.h functions
Save it.
Now open MATLAB.
“cd” to the opencl-toolbox directory, tipically:
cd 'C:\Program Files\MATLAB\R2011a\toolbox\opencl-toolbox'
and type:
make
Everything should be fine now, and you’d end up with a new file in that directory called:
openclcmd.mexw64
If you get this error:
Error: Could not find the compiler "cl" on the DOS path.
Use mex -setup to configure your environment properly.
You’ll have to configure mex to use the proper compiler: type:
mex -setup
And select the option
[7] Microsoft Visual C++ 2010 Express
It may not find the correct path…
In this case this error is shown:
Warning: The default location for Microsoft Visual C++ 2010 Express compiler is:
"C:\Program Files\Microsoft Visual Studio 10.0"
but either that directory does not exist or the configuration
is invalid.
and you’ll have to indicate “n” when asked to use the default path, and insert instead the correct one:
C:\Program Files (x86)\Microsoft Visual Studio 10.0
After correctly compiling opencl-toolbox with “make”, select in MATLAB menus:
File / Set Path…
and with button “Add Folder…” add the folder of opencl-toobox, tipically:
C:\Program Files\MATLAB\R2011a\toolbox\opencl-toolbox
Now that the toolbox is compiled and the path added, we can test it with:
test_openclcmd;
which should show something like:
platforms =profile: ‘FULL_PROFILE’ name: ‘AMD Accelerated Parallel Processing’ vendor: ‘Advanced Micro Devices, Inc.’ version: ‘OpenCL 1.2 AMD-APP (938.1)’ extensions: ‘cl_khr_icd cl_amd_event_callback cl_amd_offline_devices cl_khr_d3d10_sharing’ devices: [2×1 struct] ans = 2×1 struct array with fields: profile name vendor version driver extensions max_compute_units max_work_item_dimensions max_work_group_size max_work_item_sizes preferred_vector_width_char preferred_vector_width_short preferred_vector_width_int preferred_vector_width_long preferred_vector_width_float preferred_Vector_width_double max_clock_frequency address_bits max_read_image_args max_write_image_args max_mem_alloc_size image2d_max_width image2d_max_height image3d_max_width image3d_max_height image3d_max_depth image_support max_parameter_size max_samplers mem_base_addr_align min_data_type_align_size global_mem_cacheline_size global_mem_cache_size global_mem_size max_constant_buffer_size max_constant_args local_mem_size error_correction_support profiling_timer_resolution endian_little available compiler_available rA = 1 2 3 4 5 6 7 8 9 rB = 1 2 3 4 5 6 7 8 9 rC = 2 4 6 8 10 12 14 16 18 |
and:
test_openclmatlab;
which should show something like:
ans =
1 2 3 4 5 6 7 8 9 10 ans = 21 22 23 24 25 26 27 28 29 30 ans = 0.3000 0.6000 0.9000 1.2000 1.5000 1.8000 2.1000 2.4000 2.7000 3.0000 ans = 3 4 5 6 7 8 9 10 11 12 values = 22 24 26 28 30 32 34 36 38 40 ans = 1 2 3 4 5 6 7 8 9 10 ans = 11 12 13 14 15 16 17 18 19 20 values = 12 14 16 18 20 22 24 26 28 30 |
thanks a lot works like a charm! on my laptop with a puny hd 4330.
I did not have to install Windows SDK since I have Visual studio 2010 installed.
you’re welcome :)