Open Computing Language (OpenCL) is a language and framework for writing computationally intensive kernels that run accross heterogenious platforms, including GPUs, CPUs, and perhaps other more esoteric devices.
Intel provides an OpenCL implementation for Intel CPUs, but there's not a lot of instructions on how to get it set up. Here's what I did.
- Download the Intel® SDK for OpenCL* Applications XE 2013 from the Intel website, here http://software.intel.com/en-us/vcsource/tools/opencl-sdk-xe. The download is a tarball -- the one I got is called
intel_sdk_for_ocl_applications_2013_xe_sdk_3.0.67279_x64.tgz
- Unpack the tarball and cd into the new directory
$ tar -xzvf intel_sdk_for_ocl_applications_2013_xe_sdk_3.0.67279_x64.tgz
$ cd intel_sdk_for_ocl_applications_2013_xe_sdk_3.0.67279_x64
-
Look inside. There are a bunch of
.rpm
files. These are the default packages for redhat linux. We can install them on Ubuntu (a debian based distro) by converting them to.deb
files.a) If you don't have these packages alreafy, you'll need them for dealing with rpm files.
$ sudo apt-get install -y rpm alien libnuma1
b) Convert all of the
rpm
files intodeb
format, and then install them withdpkg
. You can do this by pasting the following commands into bash, or copying this as a script and then running it.#/bin/bash for f in *.rpm; do fakeroot alien --to-deb $f done for f in *.deb; do sudo dpkg -i $f done
-
Last, but not least, you need to install the so-called
icd
-file, which registers this OpenCL implementation, so that it's available in paralell to any other. I'm not sure why this isn't done by default (maybe it is if you install the rpms directly?), but it seems necessary. Theicd
files live at/etc/OpenCL/vendors/*.icd
and these files tell the ICD loader what OpenCL implementations (ICDs) are installed on your machine. There's one for each ICD. Each file is a one-line text file containing the name of the dynamic library (aka shared object, aka ".so" file) containing the implementation. The single line may either be the full absolute path or just the file name, in which case the dynamic linker must be able to find that file--perhaps with the help of setting the LD_LIBRARY_PATH environment variable. The names of the .icd files themselves are arbitrary, but they must have a file extension of .icd. To install the icd file, do
sudo ln -s /opt/intel/opencl-1.2-3.0.67279/etc/intel64.icd /etc/OpenCL/vendors/intel64.icd
Hint: if your OpenCL version number is more recent (I'm writing this as of August, 2013, then the installed path of the OpenCL implementation in /opt/intel/opencl-* might be different than the "1.2-3.0.67279" that I'm using.
5.If this is the only OpenCL implementation on your machine, you should install a symlink to libOpenCL.so into /usr/lib
, so that things can be linked up easily. If you already have the NVIDIA OpenCL platform (for your GPU) then this is not necessary -- installing the icd
file into the registry is enough to tell the system about your new OpenCL platform.
$ sudo ln -s /opt/intel/opencl-1.2-3.0.67279/lib64/libOpenCL.so /usr/lib/libOpenCL.so
$ sudo ldconfig
- Download the file
clDeviceQuery.cpp
from this gist. Its a small progam that reports all of the available OpenCL platforms on your machine, and all of their devices. - Compile
clDeviceQuery.cpp
withg++
, and run it. You'll need to have the OpenCL header files in your include path, andlibOpenCL.so
in your LD_LIBRARY_PATH. Note that you dont need the vendor-specific OpenCL implementation in your LD_LIBRARY_PATH necessarily. WhenlibOpenCL.so
is loaded, it uses the ICD registry to find all of the vendor implementations.
$ g++ -o clDeviceQuery -I/opt/intel/opencl-1.2-3.0.67279/include clDeviceQuery.cpp -lOpenCL
$ ./clDeviceQuery
On my machine, with both the Intel CPU OpenCL and the NVIDIA GPU OpenCL platforms, I get the following output
clDeviceQuery Starting...
2 OpenCL Platforms found
CL_PLATFORM_NAME: Intel(R) OpenCL
CL_PLATFORM_VERSION: OpenCL 1.2 LINUX
OpenCL Device Info:
1 devices found supporting OpenCL on: Intel(R) OpenCL
----------------------------------
Device Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
---------------------------------
CL_DEVICE_NAME: Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
CL_DEVICE_VENDOR: Intel(R) Corporation
CL_DRIVER_VERSION: 1.2
CL_DEVICE_TYPE: CL_DEVICE_TYPE_CPU
CL_DEVICE_MAX_COMPUTE_UNITS: 8
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: 3
CL_DEVICE_MAX_WORK_ITEM_SIZES: 1024 / 1024 / 1024
CL_DEVICE_MAX_WORK_GROUP_SIZE: 1024
CL_DEVICE_MAX_CLOCK_FREQUENCY: 3400 MHz
CL_DEVICE_ADDRESS_BITS: 64
CL_DEVICE_MAX_MEM_ALLOC_SIZE: 2994 MByte
CL_DEVICE_GLOBAL_MEM_SIZE: 11979 MByte
CL_DEVICE_ERROR_CORRECTION_SUPPORT: no
CL_DEVICE_LOCAL_MEM_TYPE: global
CL_DEVICE_LOCAL_MEM_SIZE: 32 KByte
CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: 128 KByte
CL_DEVICE_QUEUE_PROPERTIES: CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
CL_DEVICE_QUEUE_PROPERTIES: CL_QUEUE_PROFILING_ENABLE
CL_DEVICE_IMAGE_SUPPORT: 1
CL_DEVICE_MAX_READ_IMAGE_ARGS: 480
CL_DEVICE_MAX_WRITE_IMAGE_ARGS: 480
CL_DEVICE_IMAGE <dim> 2D_MAX_WIDTH 16384
2D_MAX_HEIGHT 16384
3D_MAX_WIDTH 2048
3D_MAX_HEIGHT 2048
3D_MAX_DEPTH 2048
CL_DEVICE_PREFERRED_VECTOR_WIDTH_<t> CHAR 1, SHORT 1, INT 1, FLOAT 1, DOUBLE 1
clDeviceQuery, Platform Name = Intel(R) OpenCL, Platform Version = OpenCL 1.2 LINUX, NumDevs = 1, Device = Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
CL_PLATFORM_NAME: NVIDIA CUDA
CL_PLATFORM_VERSION: OpenCL 1.1 CUDA 4.2.1
OpenCL Device Info:
1 devices found supporting OpenCL on: NVIDIA CUDA
----------------------------------
Device GeForce GTX 660
---------------------------------
CL_DEVICE_NAME: GeForce GTX 660
CL_DEVICE_VENDOR: NVIDIA Corporation
CL_DRIVER_VERSION: 310.14
CL_DEVICE_TYPE: CL_DEVICE_TYPE_GPU
CL_DEVICE_MAX_COMPUTE_UNITS: 6
CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: 3
CL_DEVICE_MAX_WORK_ITEM_SIZES: 1024 / 1024 / 64
CL_DEVICE_MAX_WORK_GROUP_SIZE: 1024
CL_DEVICE_MAX_CLOCK_FREQUENCY: 888 MHz
CL_DEVICE_ADDRESS_BITS: 32
CL_DEVICE_MAX_MEM_ALLOC_SIZE: 383 MByte
CL_DEVICE_GLOBAL_MEM_SIZE: 1535 MByte
CL_DEVICE_ERROR_CORRECTION_SUPPORT: no
CL_DEVICE_LOCAL_MEM_TYPE: local
CL_DEVICE_LOCAL_MEM_SIZE: 48 KByte
CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: 64 KByte
CL_DEVICE_QUEUE_PROPERTIES: CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE
CL_DEVICE_QUEUE_PROPERTIES: CL_QUEUE_PROFILING_ENABLE
CL_DEVICE_IMAGE_SUPPORT: 1
CL_DEVICE_MAX_READ_IMAGE_ARGS: 256
CL_DEVICE_MAX_WRITE_IMAGE_ARGS: 16
CL_DEVICE_IMAGE <dim> 2D_MAX_WIDTH 32768
2D_MAX_HEIGHT 32768
3D_MAX_WIDTH 4096
3D_MAX_HEIGHT 4096
3D_MAX_DEPTH 4096
CL_DEVICE_PREFERRED_VECTOR_WIDTH_<t> CHAR 1, SHORT 1, INT 1, FLOAT 1, DOUBLE 1
clDeviceQuery, Platform Name = Intel(R) OpenCL, Platform Version = OpenCL 1.2 LINUX, NumDevs = 1, Device = Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
NVIDIA CUDA, Platform Version = OpenCL 1.1 CUDA 4.2.1, NumDevs = 1, Device = GeForce GTX 660
System Info:
Local Time/Date = 18:33:46, 08/22/2013
CPU Name: Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
# of CPU processors: 8
Linux version 3.5.0-36-generic (buildd@roseapple) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #57~precise1-Ubuntu SMP Thu Jun 20 18:21:09 UTC 2013
TEST PASSED
worked in 2015 on Ubuntu 14.04 for /opt/intel/opencl-1.2-4.5.0.8 (checked with pyopencl)
from https://software.intel.com/en-us/articles/opencl-drivers#ubuntu64
downloaded OpenCL™ Runtime 14.2 for Intel® CPU and Intel® Xeon Phi™ coprocessors for Linux* (64-bit)
the file on the link: opencl_runtime_14.2_x64_4.5.0.8.tgz
shasum 5.84 on ubuntu 14.04
from help:
"When verifying SHA-512/224 or SHA-512/256 checksums, indicate the
algorithm explicitly using the -a option,"
" -a, --algorithm 1 (default), 224, 256, 384, 512, 512224, 512256"
"The sums are computed as described in FIPS-180-4."
$ shasum opencl_runtime_14.2_x64_4.5.0.8.tgz
ebc9fef1830f39def94546142cfaf31b99aa6675 opencl_runtime_14.2_x64_4.5.0.8.tgz
unpacked
resulting into directory pset_opencl_runtime_14.1_x64_4.5.0.8/
(yes, 14.1)
aliened the rpms, installed, symlinked the icd
had already installed AMD's SDK, so didn't link the .so in the lib
also, other guides (http://wiki.tiker.net/OpenCLHowTo) say to install icd loader -- did not do that