OpenCL on Intel HD / Iris graphics on Linux

Brian Kloppenborg OpenCL 17 Comments

Under Windows and Mac the Intel GPU drivers include OpenCL support; however, on Linux OpenCL on Intel GPUs is implemented through an open source project called Beignet (pronnounced like "ben-yay", a type of French pastry akin to a what we would call a "fritter" in English). Below I have written a step-by-step guide on how you can get Beignet running on an Ubuntu 14.10 system which has an Intel 3rd, 4th, or 5th generation Intel processor. Instructions for other variants of Linux will be similar, except for the commands to install the prerequisite packages.

There are several little caveats which need to be discussed up front. Foremost, the Beignet project supports the following hardware:

  • 3rd Generation Intel Core Processors
  • Intel “Bay Trail” platforms with Intel HD Graphics
  • 4th Generation Intel Core Processors (requires a kernel patch be applied for shared memory!)
  • 5th Generation Intel Core Processors "Broadwell".

There are also a few noteworthy issues of which you should be aware:

  • If your computer is running a Linux kernel in the 3.15 or 3.16 branch, you will need to disable some register whitelist functionality every time you reboot your system. This can be accomplished by running echo 0 > /sys/module/i915/parameters/enable_cmd_parser as root.
  • 4th Generation Intel Processors (i.e. i3/5/7-4xxx) require a kernel patch for shared/local memory to function.
  • There is no double precision support
  • OpenGL-OpenCL interop via cl_khr_gl_sharing is not supported

There are additional release notes that can be found on the Beignet project page.

Installing prerequisites

Note, if you are on a Ubuntu 14.04 system, you should install libclang-3.4-dev instead, then run update-alternatives to point llvm-link and llvm-as to the correct version. The latter can be accomplished using the following commands:
If you want to use the standard OpenCL ICD loader, you will also need to install these packages:
I would also recomment you install the clinfo program so that you can verify that your installation is successful:

Check out and compile Beignet

NOTE: There may be newer releases of Beinget. To find releases type  git branch -a on the console and pick the highest release version number.

During the CMake stage, ensure that the OCL ICD header file is installed, otherwise the library will not create an installable client driver. If everything went fine, go ahead and compile the source using

(Note, you can do make -jN with N > 1 to do a parallel build.)
Next we verify that Beignet is functioning correctly on your hardware by running unit tests. These can be found in the utest folder. The unit tests require some enviornmental variables be set prior to invocation:

If a significant fraction of the unit tests fail and you have a 3.15 or 3.16 kernel, you need to disable register whitelisting using a command similar to the following:

and try re-running the tests. Please note that this change is not permanent and you will need to re-run it if you reboot your system. Alternatively, you could add this command to a startup script. The Beignet release notes mention there is a kernel patch to fix this issue which you could backport if you so desired.

If most of the tests pass, but those that involve local memory (~20-30 of the tests) fail, you will need to apply the kernel patch listed below.

If all was well, install Beignet to your system:

You can see a list of installed software in the install_manifest.txt file in the build directory.

Verify Beignet is installed

In a terminal run the clinfo program. You should see something like this:

Take note that the Intel OpenCL driver is loaded for a GPU device using beignet. This indicates the Installable Client Driver (ICD) is correctly installed. Also note the extensions listed.

Applying the kernel patch to enable OpenCL shared local memory.

If you are using Beignet on a 4th generation Intel processor, you will need to apply a kernel patch to enable shared/local memory. This is a fairly lengthy process that will require at least 70 GB of hard disk space and perhaps an hour of compilation time if the build is executed in parallel.

In the next few paragraphs I'll walk you through how you can apply the kernel patch. I have based my instructions on the kernel compilation instructions for Ubuntu. Instructions for other variants of Linux will be significantly different.

Install prerequisites:

Make a working directory for the kernel somewhere and download the source

Next we see if we can automatically apply the patch. First download the patch:

Now cd into the kernel directory:

Check some details about the patch

Try automatically applying the patch:

If it automatically applies with no errors, just apply it:

If it did not work (as was the case on my system), the change is fairly simple. Open the drivers/gpu/drm/i915/i915_gem_execbuffer.c file in an editor:

In the i915_gem_do_execbuffer function, find the following code:

And add the line flags |= I915_DISPATCH_SECURE; as follows:

This was inserted on line 998 for me. Save the file. Now we need to compile and install the modified kernel.

Now we build the new kernel. Run the following commands from within the kernel source directory:

This will build some Debian packages and place them in the directory above the kernel source root.

After the kernel has compiled, install it:

(you might have to change the numeric kernel version to match what you compiled) Now add the kernel to the boot options:

Now go back and re-run the Beignet unit test framework from above. With any luck everything will work fine.

Facebooktwittergoogle_plusredditlinkedinmail