How to fix OpenCL no platform errors
This guide explains what to do when an OpenCL application fails to work. Most often, this happens because the application can’t find an available computing device, typically the GPU.
Check GPU drivers
Assume we have a server running Ubuntu 22.04 with an NVIDIA® GPU that supports OpenCL. Our first step is to verify if the GPU driver is installed correctly. The simplest method to check this is by using the monitoring utility:
nvidia-smi
If you encounter an error, first install the GPU driver. You can do this by following the Install NVIDIA® drivers in Linux instructions. If you see a table listing all video cards, carefully check which driver version is installed and which version of NVIDIA® CUDA® is present in the system.
Modern video card driver versions typically start with 5, such as 535.XXX. If you encounter a version starting with 4 (e.g. 4XX.XXX), it indicates that your driver needs updating. The same principle applies to CUDA® - current versions begin with 12, like 12.6. If you’re running an older version, update to the latest one using the Install CUDA® toolkit in Linux guide.
Let’s verify if the environment variables include the path to the compiler executable files:
nvcc --version
If everything is OK, you’ll receive the output of the available compiler version. This means that any application you run will have access to the compiler without needing to specify the full path. If the system reports that NVIDIA® CUDA® is absent on the server, but nvidia-smi utility shows an installed version, you need to add the path to the environment variables. This can be done in two ways: temporarily or permanently.
For a temporary solution, you only need two commands. Here’s an example using CUDA® 12.6 installed on the server:
export LD_LIBRARY_PATH=/usr/local/cuda-12.6/lib64\
${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export PATH=/usr/local/cuda-12.6/bin${PATH:+:${PATH}}
To verify the changes, try displaying the NVCC version again. If the environment variables were set correctly, the error should be resolved. For a permanent solution, add both of the above variables to the /etc/environment file:
sudo nano /etc/environment
Next, add the LD_LIBRARY_PATH variable and complete the PATH variable:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/local/cuda-12.6/bin"
LD_LIBRARY_PATH="/usr/local/cuda-12.6/lib64"
Save the file by pressing Ctrl + O, then exit the editor with Ctrl + X. After rebooting, the NVCC call command will function properly.
Check OpenCL availability
Let’s take a look at OpenCL, a framework for developing applications optimized for parallel computing. GPU drivers implement support for this framework, and the application’s performance depends on them.
To check if a server is ready to work with OpenCL, you can install a small diagnostic utility called clinfo:
sudo apt -y install clinfo
Run it and examine the brief output. We’ll focus on two key aspects: the number of platforms and the number of available devices:
clinfo | grep Number
When the system is ready to work with OpenCL, the output will appear as follows:
Number of platforms 1 Number of devices 2 Number of async copy engines 2 Number of async copy engines 2
In OpenCL terminology, “platform” refers to the type of available computing devices. This can be a CPU, GPU, or even an FPGA. In our example, we ran the command on a server with two NVIDIA® RTX™ 3090 graphic cards, which yielded these values. Essentially, we have two computing devices belonging to one type (GPU).
If the “Number of platforms” column shows 0, it indicates that the operating system isn’t ready to run OpenCL applications. In this case, check if the appropriate drivers are installed on the system. If issues persist, try completely removing the GPU drivers, rebooting the server, and then reinstalling them.
Check OpenCL libraries
It also makes sense to check for the presence of the necessary OpenCL libraries:
ldconfig -p | grep -i opencl
When the libraries are installed correctly, the output should look something like this:
libnvidia-opencl.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libnvidia-opencl.so.1 libnvidia-opencl.so.1 (libc6) => /lib/i386-linux-gnu/libnvidia-opencl.so.1 libOpenCL.so.1 (libc6,x86-64) => /usr/local/cuda/targets/x86_64-linux/lib/libOpenCL.so.1 libOpenCL.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libOpenCL.so.1 libOpenCL.so (libc6,x86-64) => /usr/local/cuda/targets/x86_64-linux/lib/libOpenCL.so libOpenCL.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libOpenCL.so
If the system lacks these libraries, you can install them manually:
sudo apt install ocl-icd-opencl-dev && sudo apt install opencl-headers
Downgrade
In Ubuntu 22.04, some GPU models may experience complete OpenCL inaccessibility, even after reinstalling all drivers and the CUDA® toolkit. The best solution for this issue is to downgrade to the previous version of the operating system, along with downgrading the drivers and CUDA®.
For example, if you’re using the Tesla® V100 accelerator (introduced in 2017), it’s advisable to choose Ubuntu 20.04 instead of Ubuntu 22.04. Pair this with the 535.183.01 driver and CUDA® 12.2. This combination ensures that most OpenCL-based applications will function correctly.
In some cases, you may not need to change the operating system version. However, you’ll need to downgrade the versions of the driver and CUDA® instead.
See also:
Updated: 28.03.2025
Published: 23.09.2024