Tuesday, 17 May 2011

Intel's OpenCL on Ubuntu

Since I work with OpenCL a lot and yesterday I found out that Intel's OpenCL is now finally available for Linux, I thought I'd share a few words of how to get it to work on Ubuntu (even though Intel currently provides only a rpm package for RHEL and Suse).

First of all, I'm testing all of this on Lucid 64bit, but I suppose it'd work also on newer Ubuntu releases (though you need to be using 64bit version, cause the Intel package is for 64).

So let's get to it.

  1. First of all grab the rpm package from http://software.intel.com/en-us/articles/download-intel-opencl-sdk/.
  2. Install the rpm and alien packages (`sudo apt-get install rpm alien`).
  3. Convert the rpm package to deb using alien - `fakeroot alien --to-deb <intel's rpm package filename>`. The conversion spits some warnings, I wouldn't pay any attention to them.
  4. Install the newly created deb package. `sudo dpkg -i intel-ocl-sdk-suse+11.1_1.1-2_amd64.deb`
  5. One extra package you need to install for the library to work is libnuma. `sudo apt-get install libnuma1`
  6. Make sure the ICD is installed. `sudo echo "libintelocl.so" > /etc/OpenCL/vendors/intelocl64.icd`
  7. The package is nice and also installs OpenCL headers in /usr/include/CL. Also the main binary (libOpenCL.so) is installed in /usr/lib64 - if you don't have any other OpenCL platform installed on your system, I suggest moving it to /usr/lib (run `sudo ldconfig` afterwards), if you do have this library already (for example nvidia driver also contains it) just leave it there.
  8. Since the libraries are installed in non-standard location for Ubuntu (/usr/lib64/OpenCL/vendors/intel), you'll need to adjust your LD_LIBRARY_PATH. I usually do this using a script, but you can just run:
    export LD_LIBRARY_PATH=/usr/lib64/OpenCL/vendors/intel:$LD_LIBRARY_PATH
Running a OpenCL program that just lists available platforms should return now at least one platform. Or if you have multiple platforms including their ICDs installed you'd get something like:
There are 3 platforms available
PLATFORM_NAME: Intel(R) OpenCL
  VERSION: OpenCL 1.1 LINUX
  VENDOR: Intel(R) Corporation
  PROFILE: FULL_PROFILE
    DEVICE: Intel(R) Core(TM)2 Duo CPU     P7370  @ 2.00GHz
    MAX COMPUTE UNITS: 2
    DEVICE VERSION: OpenCL 1.1 
    DRIVER VERSION: 1.1
PLATFORM_NAME: ATI Stream
  VERSION: OpenCL 1.1 ATI-Stream-v2.3 (451)
  VENDOR: Advanced Micro Devices, Inc.
  PROFILE: FULL_PROFILE
    DEVICE: Intel(R) Core(TM)2 Duo CPU     P7370  @ 2.00GHz
    MAX COMPUTE UNITS: 2
    DEVICE VERSION: OpenCL 1.1 ATI-Stream-v2.3 (451)
    DRIVER VERSION: 2.0
PLATFORM_NAME: NVIDIA CUDA
  VERSION: OpenCL 1.0 CUDA 3.2.1
  VENDOR: NVIDIA Corporation
  PROFILE: FULL_PROFILE
    DEVICE: GeForce 9300M GS
    MAX COMPUTE UNITS: 1
    DEVICE VERSION: OpenCL 1.0 CUDA
    DRIVER VERSION: 260.19.29

Good luck implementing your OpenCL kernels. :)