How to Check OpenCL support in GPU on Linux / Ubuntu

By | May 26, 2023

OpenCL is a general purpose computing api that is designed to be hardware accelerated with a supporting gpu and driver. On Linux this api is supported by all major gpu vendors including nvidia, intel and amd.

In this quick tutorial we take a look at how to check if your system support opencl api (with hardware acceleration). You should be having a gpu (discrete or integrated) along with the correct drivers installed for opencl to work.

clinfo command

On this system we have a Nvidia RTX 3060 Mobile GPU with Nvidia drivers v.525 installed. OpenCL support can be verified using the clinfo command.

The -l option lists out all devices supporting OpenCL.

$ clinfo -l
Platform #0: NVIDIA CUDA
 `-- Device #0: NVIDIA GeForce RTX 3060 Laptop GPU

For more detailed information use the following command with grep filtering.

clinfo -a | grep -i 'name\|vendor\|version\|profile'


silver@ubuntussd:~$ clinfo -a | grep -i 'name\|vendor\|version\|profile'
  Platform Name                                   NVIDIA CUDA
  Platform Vendor                                 NVIDIA Corporation
  Platform Version                                OpenCL 3.0 CUDA 12.0.151
  Platform Profile                                FULL_PROFILE
  Platform Extensions with Version                cl_khr_global_int32_base_atomics                                 0x400000 (1.0.0)
  Platform Numeric Version                        0xc00000 (3.0.0)
  Platform Name                                   NVIDIA CUDA
  Device Name                                     NVIDIA GeForce RTX 3060 Laptop GPU
  Device Vendor                                   NVIDIA Corporation
  Device Vendor ID                                0x10de
  Device Version                                  OpenCL 3.0 CUDA
  Device Numeric Version                          0xc00000 (3.0.0)
  Driver Version                                  525.105.17
  Device OpenCL C Version                         OpenCL C 1.2 
  Device OpenCL C all versions                    OpenCL C                                                         0x400000 (1.0.0)
  Device Profile                                  FULL_PROFILE
    IL version                                    (n/a)
    ILs with version                              (n/a)
  Built-in kernels with version                   (n/a)
  Device Extensions with Version                  cl_khr_global_int32_base_atomics                                 0x400000 (1.0.0)
  ICD loader Name                                 OpenCL ICD Loader
  ICD loader Vendor                               OCL Icd free software
  ICD loader Version                              2.3.1
  ICD loader Profile                              OpenCL 3.0

No Support: The clinfo command would simply show 0 platforms, when there are no OpenCL supporting gpu or gpu drivers available.

$ clinfo
Number of platforms                               0

Intel Integrated Graphics

Intel igpus can provide OpenCL support via the Neo drivers. The drivers can be installed with the following package:

sudo apt install intel-opencl-icd
$ clinfo -l
Platform #0: Intel(R) OpenCL HD Graphics
 `-- Device #0: Intel(R) HD Graphics 630 [0x5912]

Earlier intel igpus could support opencl via the Beignet library, but it is no longer under active development and not available in the repositories.


AMD Gpus do not provide opencl support via the amdgpu driver installed by default. AMD has released the latest drivers with opencl support which can be downloaded from this url:

However the .deb packages have installation problems with broken dependencies on Ubuntu 23.04

sudo dpkg -i libffi7_3.3-6_amd64.deb 

sudo dpkg -i libffi7_3.3-6_i386.deb 

sudo gdebi amdgpu-install_5.4.50405-1_all.deb
$ sudo amdgpu-install 
[sudo] password for silver: 
Hit:1 lunar InRelease                           
Hit:2 lunar InRelease        
Get:3 lunar-updates InRelease [109 kB]       
Get:4 lunar-backports InRelease [99.8 kB]       
Hit:5 focal InRelease     
Hit:6 focal InRelease
Get:7 lunar-security InRelease [109 kB]
Get:8 lunar-updates/main amd64 Packages [103 kB]
Get:9 lunar-updates/main i386 Packages [79.4 kB]
Get:10 lunar-updates/universe i386 Packages [35.4 kB]
Get:11 lunar-updates/universe amd64 Packages [53.6 kB]
Fetched 589 kB in 3s (191 kB/s)                           
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
linux-headers-6.2.0-20-generic is already the newest version (6.2.0-20.20).
linux-headers-6.2.0-20-generic set to manually installed.
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 xserver-xorg-amdgpu-video-amdgpu : Depends: xorg-video-abi-24 but it is not installable
E: Unable to correct problems, you have held broken packages.

The package depends on xorg-video-abi-24 which is not installable.

Testing and Benchmarks

To benchmark the OpenCL performance there is a tool called IndigoBench that runs rendering tests using the OpenCL api and provides a cumulative score as a relative indicator of the performance.

We ran the tests on our gaming laptop with Nvidia RTX 3060 gpu

IndigoBench on Asus Tuf A17 - Kubuntu 23.10

IndigoBench on Asus Tuf A17 - Kubuntu 23.10

Check this article:

How to Benchmark GPU Performance with IndigoBench on Ubuntu / Linux

If the system has no gpu, then indigobench with use cpu based rendering with software emulation of opencl, which will be far slower than gpu accelerated computations.

When forcing the --gpuonly option on a system where there is no gpu support available, indigobench will simply be not able to start

acerlight@acerlight-laptop:~/IndigoBenchmark_v4.4.15$ ./indigo_benchmark --gpuonly
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Error initialising OpenCL: clGetPlatformIDs failed: CL_PLATFORM_NOT_FOUND_KHR

ICD - Installable Client Driver

The details of the icd drivers are stored in the directory: /etc/OpenCL/vendors. To learn more about OpenCL implementation on Linux check out this guide on github here.

The directory contains files ending in ".icd" extension and they contain driver file location. The opencl icd loader will load the appropriate one to provide hardware accelerated opencl support.

1. Desktop system with only Intel integrated graphics:

$ ls -la /etc/OpenCL/vendors
total 16
drwxr-xr-x 2 root root 4096 May 25 19:48 .
drwxr-xr-x 3 root root 4096 Aug 29  2020 ..
-rw-r--r-- 1 root root   52 Jan 10 20:19 intel.icd
-rw-r--r-- 1 root root   22 May  3  2020 nvidia.icd
$ cat /etc/OpenCL/vendors/intel.icd 

The above file is the actual driver that provides opencl support for intel igpus. Every gpu has its own separate driver file.

2. Laptop: Dedicated Nvidia RTX 3060 + AMD Radeon Vega iGPU

Lets take a look at another system with discrete nvidia gpu and integrated amd gpu.

silver@ubuntussd:~$ ls -l /etc/OpenCL/vendors/
total 4
-rw-r--r-- 1 root root 22 Mar 27 23:37 nvidia.icd
silver@ubuntussd:~$ cat /etc/OpenCL/vendors/nvidia.icd

The nvidia opencl drivers come from the following packages:

$ apt-file search
libnvidia-compute-390: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-450-server: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-470: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-470-server: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-510: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-515: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-515-server: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-525: /usr/lib/x86_64-linux-gnu/
libnvidia-compute-525-server: /usr/lib/x86_64-linux-gnu/

On this system we have the libnvidia-compute-525 package installed.

3. Laptop with Intel Iris Xe (Integrated GPU on i5-1135G7)

This is another system with integrated intel gpu and running ubuntu 22.10. Intel Opencl support is enabled by installing the driver package:

sudo apt install intel-opencl-icd
$ clinfo -l
Platform #0: Intel(R) OpenCL HD Graphics
 `-- Device #0: Intel(R) Iris(R) Xe Graphics [0x9a49]

The icd files look like this:

$ ls -la /etc/OpenCL/vendors/
total 12
drwxr-xr-x 2 root root 4096 May 26 15:00 .
drwxr-xr-x 3 root root 4096 May 26 15:00 ..
-rw-r--r-- 1 root root   52 Oct  4  2022 intel.icd
$ cat /etc/OpenCL/vendors/intel.icd 

Possible Errors

If you have multiple icd loaders installed you might get the following error:

Error initialising OpenCL: clGetDeviceIDs failed

I got this error, after installing mesa-opencl-icd package and then running indigobench. It seems to be a cpu only platform that cannot detect gpus at all.

silver@ubuntussd:~/IndigoBenchmark_v4.4.15$ ./indigo_benchmark 
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Error initialising OpenCL: clGetDeviceIDs failed

The solution is to remove the package

sudo apt remove mesa-opencl-icd

PyOpenCL Python Code Example

Here is a simple piece of python code that uses pyopencl module to check for opencl supporting devices and lists them out.

# get this package with command:  sudo apt install python3-pyopencl

import pyopencl as cl

# get platforms
plat = cl.get_platforms()
list_cl_devices = plat[0].get_devices()

print ("Available OpenCL Devices:")
#print (list_cl_devices)

for device in list_cl_devices:
    print ('---')
    print('Vendor=' + device.get_info(cl.device_info.VENDOR))
    print('Name=' + device.get_info(cl.device_info.NAME))
    print('Driver Version=' + device.get_info(cl.device_info.DRIVER_VERSION))
    #print('Platform=' + device.get_info(cl.device_info.PLATFORM))

    print ('---')
$ python3 
Available OpenCL Devices:
Vendor=NVIDIA Corporation
Name=NVIDIA GeForce RTX 3060 Laptop GPU
Driver Version=525.105.17
$ python3 
Available OpenCL Devices:
Vendor=Intel(R) Corporation
Name=Intel(R) Iris(R) Xe Graphics [0x9a49]
Driver Version=1.0.0
About Silver Moon

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected].

Leave a Reply

Your email address will not be published. Required fields are marked *