How to set up OpenCL in Linux
To use OpenCL, you need three things: libOpenCL.so — the «ICD loader» : This library dispatches your OpenCL calls to OpenCL implementations. It is what you link into your OpenCL-using program (or into PyOpenCL, as the case may be). Individual implementations are called ICDs («Installable Client Drivers»).
/etc/OpenCL/vendors/*.icd — the «ICD registry» : 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 .
One or more OpenCL implementations — the «ICDs» : These are dynamic libraries pointed to by the .icd files, plus perhaps a few supporting files. They may reside anywhere on your file system. You can (and likely want to) have more than one installed.
Each implementation typically ships all of these components. They will tend to step on each other’s feet if you’re not careful. Avoiding such accidents is what this guide is about.
Installation
This page had gotten seriously outdated over time, so I’ve removed most of the content.
- See the PyOpenCL install instructions if you just want to get going with PyOpenCL with minimal fuss, or
- see from someone at Intel for more up-to-date instructions and troubleshooting tips.
Install OpenCL Drivers On Ubuntu¶
Note This tutorial is using the OpenCL driver version that we tested. We recommend installing the latest OpenCL packages supported for your OS.
cd neo wget https://github.com/intel/compute-runtime/releases/download/19.07.12410/intel-gmmlib_18.4.1_amd64.deb wget https://github.com/intel/compute-runtime/releases/download/19.07.12410/intel-igc-core_18.50.1270_amd64.deb wget https://github.com/intel/compute-runtime/releases/download/19.07.12410/intel-igc-opencl_18.50.1270_amd64.deb wget https://github.com/intel/compute-runtime/releases/download/19.07.12410/intel-opencl_19.07.12410_amd64.deb wget https://github.com/intel/compute-runtime/releases/download/19.07.12410/intel-ocloc_19.07.12410_amd64.deb
Execute the following command to get a synthetic summary about all OpenCL platforms on the system and the devices they expose:
sudo add-apt-repository ppa:graphics-drivers/ppa
This will provide info on the current long-lived branch release: `nvidia-xxx`
sudo apt update sudo apt install nvidia-driver-xxx
sudo apt update sudo apt install nvidia-driver-xxx
sudo apt update sudo apt install nvidia-xxx
Execute the following command to get a synthetic summary about all OpenCL platforms on the system and the devices they expose:
Radeon no longer supports SPIR on some GPUs, please verify that your GPU drivers support SPIR to be compatible with Zivid Software.
Open a terminal window by pressing Ctrl + Alt + T keys on the keyboard. Create a temporary folder and navigate to it:
wget --referer http://support.amd.com https://drivers.amd.com/drivers/linux/amdgpu-pro-20.45-1188099-ubuntu-20.04.tar.xz
tar -Jxvf amdgpu-pro-20.45-1188099-ubuntu-20.04.tar.xz cd amdgpu-pro-20.45-1188099-ubuntu-20.04
For Linux Kernel version 5.8 (Ubuntu LTS HWE stacks), download Radeon Software 20.50 for Linux 20.04:
wget --referer http://support.amd.com https://drivers.amd.com/drivers/linux/amdgpu-pro-20.50-1234664-ubuntu-20.04.tar.xz
tar -Jxvf amdgpu-pro-20.50-1234664-ubuntu-20.04.tar.xz cd amdgpu-pro-20.50-1234664-ubuntu-20.04
wget --referer http://support.amd.com https://drivers.amd.com/drivers/linux/amdgpu-pro-18.50-725072-ubuntu-18.04.tar.xz
tar -Jxvf amdgpu-pro-18.50-725072-ubuntu-18.04.tar.xz cd amdgpu-pro-18.50-725072-ubuntu-18.04
Warning Zivid no longer supports AMD on Ubuntu 16.04 (AMD dropped support for Ubuntu 16.04 as of Radeon Software 18.50 for Linux).
wget --referer http://support.amd.com https://drivers.amd.com/drivers/linux/amdgpu-pro-18.40-673869-ubuntu-16.04.tar.xz
tar -Jxvf amdgpu-pro-18.40-673869-ubuntu-16.04.tar.xz cd amdgpu-pro-18.40-673869-ubuntu-16.04
./amdgpu-pro-install --opencl=pal
Open a terminal window by pressing Ctrl + Alt + T keys on the keyboard. Execute the following command to get a synthetic summary about all OpenCL platforms on the system and the devices they expose:
If clinfo doesn’t print anything, you might have to add your user to group Video . If your system does not boot up after installing the OpenCL driver, click System Boot Error After AMD OpenCL Drivers Installation .
© Copyright Copyright 2015-2021 (C) Zivid AS.
Links
How to compile OpenCL on Ubuntu?
Question: What is needed headers and drivers are needed and where would I get them for compiling open CL on ubuntu using gcc/g++? Info: for a while now I’ve been stumbling around trying to figure out how to install open CL on my desktop and if possible my netbook. There are a couple tutorials out there that I’ve tried but none seem to work. Also, they all just give a step by step with out really explaining why for the what, or even worse they are specific to a particular IDE so you have to learn the IDE to be able to do anything. So I have an NVIDA GX465 in my desktop and integrated graphics in my netbook. my priority is of course my desktop, the netbook is just a convenience for development purposes(both run ubuntu 11.04 and will be running 11.10 as soon as it comes out). Can some one spell out for me what exactly is needed to get it so I can actually compile code and have it run. and if you could also explain what each piece does so that I can understand it’s importance.
4 Answers 4
To compile and run OpenCL code under Linux, you’ll need four things:
1) An NVIDIA Driver which supports OpenCL. The drivers packaged with Ubuntu are somewhat old, but they should still work just fine. Unless you have explicit need for current drivers, you should stick with the ones packaged with Ubuntu. To be clear, these are the same drivers installed through the restricted drivers manager. OpenCL libaries are shipped with driver, so to just run OpenCL programs driver should be enough.
2) The CUDA toolkit. This includes the headers necessary to compile OpenCL code. Install this to the default location.
3) The GPU Computing SDK (optional). This includes various NVIDIA specific support tools, as well as OpenCL code samples.
4) OpenCL C++ bindings (optional). Strangely, they are not included with CUDA Toolkit, but in case you use C++, they could make your code much more redable. You can download them from http://www.khronos.org/registry/cl/api/1.1/cl.hpp, and just put it in /usr/local/cuda/include/CL an you desktop.
Once these are installed, you’ll need to perform a few more steps to be able to compile and run OpenCL outside of the NVIDIA SDK.
1) The CUDA toolkit will have included the OpenCL headers (Listed at http://www.khronos.org/registry/cl/), likely they are in the directory /usr/local/cuda/include/CL. To make these headers available system wide, you should link this directory into /usr/include/, such that they may be accessed as /usr/include/CL/[headerfilename]. Instead of creating a symlink, you could add /usr/local/cuda/include to your C_INCLUDE_PATH and CPLUS_INCLUDE_PATH environment variables, but this would last for only currest session.
2) Make sure that the OpenCL library (libOpenCL.so) is present in /usr/lib. This should have been put in place by the driver, so you shouldn’t have to do anything.
You’re ready to write code. Make sure to include CL/cl.h (or CL/cl.hpp if you’d like to use C++ version of API) in any C(++) program which makes OpenCL API calls. When you compile, make sure to link against the OpenCL library (pass gcc the -lOpenCL flag).
As far as your netbook, integrated graphics don’t generally support OpenCL. In theory, AMD’s APP Acceleration supports running OpenCL on the CPU, but it’s not clear that it actually works.