2

I recently purchased a Dell Inspiron 3000 series laptop with an Intel i5 7th generation processor. The machine came preloaded with Windows 8 but being an Ubuntu loyalist, I installed Ubuntu 16.04 on it.

I need to work with OpenCL on my laptop for which I have followed the procedure listed out in this thread (OpenCL On ubuntu 16.04, Intel Sandy Bridge CPU) and have installed PyOpenCL (incidentally, this thread worked perfectly for my workstation at work where I have a Xeon machine)

I used the following python script (https://github.com/benshope/PyOpenCL-Tutorial/blob/master/010_introspection.py) to obtain this output on my laptop:

============================================================
OpenCL Platforms and Devices
============================================================
Platform - Name:  Intel Gen OCL Driver
Platform - Vendor:  Intel
Platform - Version:  OpenCL 1.2 beignet 1.1.1
Platform - Profile:  FULL_PROFILE
beignet-opencl-icd: no supported GPU found, this is probably the wrong opencl-icd package for this hardware
(If you have multiple ICDs installed and OpenCL works, you can ignore this message)

The same script on my workstation gives me:

============================================================
Platform - Name:  Intel(R) OpenCL
Platform - Vendor:  Intel(R) Corporation
Platform - Version:  OpenCL 2.0 LINUX
Platform - Profile:  FULL_PROFILE
--------------------------------------------------------
Device - Name:  Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz
Device - Type:  CPU
Device - Max Clock Speed:  2200 Mhz
Device - Compute Units:  24
Device - Local Memory:  32 KB
Device - Constant Memory:  128 KB
Device - Global Memory: 31 GB
Device - Max Buffer/Image Size: 8013 MB
Device - Max Work Group Size: 8192

lspci gives me:

lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Device 5916 (rev 02)

(On a possibly unrelated note, I also installed a graphics driver on my laptop which was not the case when I first tried installing OpenCL)

Basically, I'm unable to figure out which OpenCL format would be suitable for my hardware.

Any advice would be really great :)

2

Ok so I figured it out. Also, it was NOT rocket-science :/

The link (OpenCL On ubuntu 16.04, Intel Sandy Bridge CPU) I followed earlier was perfect since I was working on a Xeon machine. It would not have worked (big surprise!) on my Laptop since it obviously isn't a Xeon machine.

I needed to use the sdk for linux which is available after filling out the form. Once the form is filled out you get redirected to a page where you can choose the product and the version and download either a .gz file or a .tgz file. The .tgz is for the Yocto OS but during installation you can run it without any loss of generalization for Ubuntu 16.04.

The installation is fairly simple since there is an extremely handy executable install.sh shell script to use.

The general steps to follow are:

  1. extract the folder

    tar -xzvf intel_sdk_for_opencl_2017_yocto_7.0.0.2567_x64.tgz
    
  2. run the shell script

    ./install.sh
    
  3. follow the instructions

The output of the python script then shows:

============================================================
OpenCL Platforms and Devices
============================================================
Platform - Name:  Intel Gen OCL Driver
Platform - Vendor:  Intel
Platform - Version:  OpenCL 1.2 beignet 1.1.1
Platform - Profile:  FULL_PROFILE
beignet-opencl-icd: no supported GPU found, this is probably the wrong opencl-icd package for this hardware
(If you have multiple ICDs installed and OpenCL works, you can ignore this message)
============================================================
Platform - Name:  Experimental OpenCL 2.1 CPU Only Platform
Platform - Vendor:  Intel(R) Corporation
Platform - Version:  OpenCL 2.1 LINUX
Platform - Profile:  FULL_PROFILE
    --------------------------------------------------------
    Device - Name:  Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
    Device - Type:  CPU
    Device - Max Clock Speed:  2500 Mhz
    Device - Compute Units:  4
    Device - Local Memory:  32 KB
    Device - Constant Memory:  128 KB
    Device - Global Memory: 8 GB
    Device - Max Buffer/Image Size: 1962 MB
    Device - Max Work Group Size: 8192
============================================================
Platform - Name:  Intel(R) OpenCL
Platform - Vendor:  Intel(R) Corporation
Platform - Version:  OpenCL 2.0 
Platform - Profile:  FULL_PROFILE
    --------------------------------------------------------
    Device - Name:  Intel(R) HD Graphics
    Device - Type:  GPU
    Device - Max Clock Speed:  1000 Mhz
    Device - Compute Units:  23
    Device - Local Memory:  64 KB
    Device - Constant Memory:  3209904 KB
    Device - Global Memory: 6 GB
    Device - Max Buffer/Image Size: 3135 MB
    Device - Max Work Group Size: 256
    --------------------------------------------------------
    Device - Name:  Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
    Device - Type:  CPU
    Device - Max Clock Speed:  2500 Mhz
    Device - Compute Units:  4
    Device - Local Memory:  32 KB
    Device - Constant Memory:  128 KB
    Device - Global Memory: 8 GB
    Device - Max Buffer/Image Size: 1962 MB
    Device - Max Work Group Size: 8192
1

I realise after spending over 16 hours getting OpenCL to work on Windows and Linux, that OpenCL On ubuntu 16.04, Intel Sandy Bridge CPU is the closest to get it working.

What didn't work for me was from the installation of drivers, and configuration, after which I tried from some more places. Yeah, the versions were different. I took that into consideration wherever possible. But, then, it was my first time installing libraries and linking. So, I hope this helps any newbies like me. I have only covered the part on Intel GPUs

Getting OpenCL to work

sudo apt install clinfo ocl-icd-opencl-dev opencl-headers

Check the output of clinfo

clinfo | grep "GPU"

to check if GPU is included. If there's no line like

Device Type                            GPU

in the output, then, GPU does not yet support OpenCL. In that case, try installing beignet-opencl-icd, mesa-opencl-icd, etc - may be, one at a time. Keep checking the output of clinfo after each. If it includes the above line, you are done.

Installing Intel OpenCL Drivers

If that doesn't work, install the opencl drivers of intel from https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_driver. The automatic install requires a ton of time and space. There is an alternate method though. Unzip the archive. Install alien, if you don't already have: sudo apt install alien

cd into the unzipped folder, and run

sudo alien -i *.rpm

Check the output of “clinfo” again. It should have a GPU. clinfo | grep “GPU”

At this point, you'd have a working implementation of OpenCL.

However, while trying out examples (from here), I found that most examples work with Intel's libraries (see below), some don't work with the libraries installed with the distribution (installed above). (I guess, this is because of the different openCL versions involved.)

Install Intel's OpenCL SDK

Install the Intel OpenCL SDK for Linux (after registering for free) with them, from here Intel OpenCL SDK for Linux. Just run the installer script - no need to work on the parts of making it work with Eclipse and all. You may need to

sudo apt install dkms

At this point, you should have all the things ready.

If you are a newbie (like me)

Know the process of compilation of C programs: firstly, object files are generated, then these are linked. See https://stackoverflow.com/questions/31179452/what-exactly-is-in-a-o-a-so-file.

In an IDE (I don't know about the terminal), there are two parts to dealing with libraries. First is including the path to the header files. Second is including the library files in the project.

I am using CodeBlocks. So, the reason Linux is loved is because, the very first command of this answer sent the files to their intended places. The header files are in the /usr/include directory, under 'CL' folder. The library (in my case) is under /usr/lib/x86_64-linux-gnu, named 'libOpenCL.so'. You don't need to do anything further to use them. You can just start coding -

#include<CL/cl.h>

In case of the Intel OpenCL SDK, the header files are under /opt/intel/opencl-sdk/include; while the library files are under After installing, check the contents of /opt/intel/opencl for the contents. These too have the libraries. However, one of the library-files gave me a syntax error (libclang.so). The Intel OpenCL SDK is to be downloaded mainly for the header files in: /opt/intel/opencl-sdk/lib64 - only the .so ones. (I found the libclang.so file to be giving a syntax error. Check while running the program.)

In case of CodeBlocks, to use these Intel's files - the non-default ones - Create a new project. Right click the project in the manager-subwindow. Go to “Build options”. Select the Project name in the left pane – thus, the settings will be applied for both Release and Debug versions. In Linker settings -> link libraries, click “Add”. Here, add the libraries (not the header files; all the .so ones): at /opt/intel/opencl-sdk/lib64. In Search directories tab, under ‘compiler’, add /opt/intel/opencl/include (or wherever your header files are).

In case of Eclipse, first, install the CDT. Then, after creating the project, under Project -> Properties -> C/C++ Build -> Settings -> Tool Settings, (1) under GCC C++ Compiler, includes, add the header files directory. (2) under GCC C++ Linker, in the Libraries section, add OpenCL and in the lower part, in the Library Path section, add the path. In my case, to get it working, I required, /opt/intel/opencl/include in the first part and /opt/intel/opencl/SDK/lib64 in the second part. The default as in the case of Codeblocks didn't work. Perhaps, its due to the versions, or I haven't tried properly - Eclipse is new to me.

Done.

The following should run and compile: https://github.com/bgaster/opencl-book-samples/blob/master/src/Chapter_3/OpenCLInfo/OpenCLInfo.cpp

Credits: Internet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.