Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How-to: OpenCL 1.2 on Intel HD Graphics (3. gen and newer) under Linux #53

Open
ppp2211 opened this issue Oct 28, 2017 · 1 comment
Open

Comments

@ppp2211
Copy link

ppp2211 commented Oct 28, 2017

Warning: a lot of text. TL;DR: Intel only provides OpenCL for Windows, there's an open source alternative for Linux but it doesn't always work due to OpenCL 2.0 being used by default, so compile it from source, disable CL2.0 and you're good to go.

Brief Intro

Integrated Intel HD Graphics support OpenCL 1.2 natively from Ivy Bridge onwards (3. gen Core CPUs). Broadwell and up (5. gen) also support OpenCL 2.0. Under Windows, they're supported directly through the driver provided by Intel.

However, Intel does not provide Linux OpenCL support for these chips. I suppose running OpenCL on these integrated GPUs is niche enough that nobody really bothered.

Edit: Apparently Intel provides OpenCL 1.2 + 2.0 drivers for 5. gen and newer CPUs, but it requires manually patching the Linux kernel (https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_driver). Arguably my solution is easier to install, as it's just a package, but official support is always good. If you're on 3. or 4. gen you don't have that option though.

Beignet

There is an open-source implementation of OpenCL for Intel GPUs called Beignet: https://www.freedesktop.org/wiki/Software/Beignet/
It is available for download as a package in most popular distros - definitely Ubuntu, Debian and Arch, but probably others, too.

"Great!" you might think to yourself - and correctly so - install that package and see what happens when you try to run test_opencl from the coursework files. If it works, you're in luck, so you can stop reading this now and go back to work.

Problems

Unfortunately, you may also find that it doesn't work. After I installed Beignet, running test_opencl gave me a very "friendly" error message:
drm_intel_gem_bo_context_exec() failed: No space left on device

If you're stubborn like me, and you really feel like getting this to work, after a few hours of banging your head you will realise that the problem has nothing to do with space left, it's not even memory related, and the error message is completely misleading.

So, why does this happen? In short - because of OpenCL 2.0.
The Beignet website claims that "as of Beignet 1.3.0, OpenCL 2.0 is supported, but disabled by default". This is, as far as I can tell, false - it is enabled by default, even on platforms that do not support it.

That causes either 1 or 2 problems, depending on your platform:

  1. OpenCL 2.0 is (I think) not backwards compatible with 1.2, so the coursework code doesn't work
  2. Intel 3. and 4. gen GPUs do not support OpenCL 2.0, but it is being used anyway for some reason (that's why it was crashing for me)

Solution

The solution is to compile Beignet from source (https://01.org/beignet/downloads) and explicitely disable OpenCL 2.0, rather than use the version from a repo.

The Beignet website (https://www.freedesktop.org/wiki/Software/Beignet/) has a rather well written guide on how to install it, so I won't bother giving a step-by-step instruction, as the only difference is the cmake step anyway.

Worthy of note is that while they recommend using LLVM 3.6 or 3.7, I have used LLVM 5.0 and had no issues. Just don't run it on some ancient LLVM and GCC and you should be fine. Make sure that you're not missing any prerequisites (all listed on the website), the only one I was missing was LLVM. Also don't forget to install OpenCL library headers if you haven't already. You may additonally want to install clinfo which can be used to display the status of OpenCL devices active on your machine.

The actual "fix" is to run
cmake ../ -DENABLE_OPENCL_20=0 -DCMAKE_BUILD_TYPE="Release"
instead of just cmake ../ as suggested in the tutorial on their website.

As you can probably tell, -DENABLE_OPENCL_20=0 disables OpenCL 2.0, whereas -DCMAKE_BUILD_TYPE="Release" disables debug messages which spam you with warnings otherwise.

The rest of the process iis unchanged from the official guide. After you make install (don't forget sudo) you should have a working OpenCL installation. If you then run clinfo (if you installed it, that is), you should see it listing an OpenCL 1.2 device:
Platform Version OpenCL 1.2 beignet 1.3

It's probably a good idea to also run the utests as recommended in the tutorial, where you should see 100% pass rates:
image

Running test_opencl should now give you:
image
Instead of the dreaded drm_intel_gem_bo_context_exec() failed: No space left on device for which Google has no answers available.

How fast is it

I wouldn't necessarily use it for production purposes as the chip, although functional, is pretty slow. But for prototyping it should be plenty enough. Would be nice if someone benchmarked a CPU software implementation, I can't be bothered at this point. Would be funny if it were faster than the iGPU though.

To quantify, I used Luxmark 3.1 to bench it against a GTX1080 in my desktop. Results:

  • GTX1080 - 15144 points
  • Intel HD4400 - 1416 points

So, 10-ish times slower. Not great, but also not too bad considering the entire laptop cost me less than half of what the 1080 did...

Anyway, I hope that it helps at least some people who are trying to do the same thing, as Intel GPUs are everywhere - it's just sometimes a bit hard to put them to use.

@ThunderMikey
Copy link

TL;DR: Intel only provides OpenCL for Windows,

It's now no longer true. See Intel's official repo

Just follow the release note, and you are ready to go.

One step extra for me is to install ocl-icd-opencl-dev on my Ubuntu 18.04 LTS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants