Skip to content

OpenCL Installation

PoCL on Nvidia Jetson

Purpose & Motivation

PoCL is a portable open source (MIT-licensed) implementation of the OpenCL standard. In addition to being an easily portable/layered multi-device open-source OpenCL implementation, a major goal of this project is improving interoperability of diversity of OpenCL-capable devices by integrating them to a single centrally orchestrated platform. Also one of the key goals is to enhance performance portability of OpenCL programs across device types utilizing runtime and compiler techniques.

PoCL currently supports various CPU architectures (x86, ARM, RISC-V), NVIDIA GPUs via libCUDA, Intel GPUs via Level Zero and TCE ASIPs (OpenASIP) at different feature coverage levels. It also supports a remote backend for distributed OpenCL execution. PoCL is also known to have multiple (private) adaptations in active production use.

PoCL uses Clang as an OpenCL C frontend and LLVM for kernel compiler implementation, and as a portability layer. Thus, if your desired target has an LLVM backend, it should be able to get OpenCL support easily by using PoCL.

Warning

Nvidia Jetson boards do not support natively OpenCL, thus it is mandatory to install PoCL to run OpenCL applications on them.

In this page we will focus on installing PoCL version 5. This version supports CUDA 16-bit floats. The release note details the supported feature.

Note

On "old" Jetson boards (TX2, Xavier NX, AGX Xavier & Nano), it is not possible to install recent PoCL version 5 because the OS is too old (Ubuntu 18.04) and it is complicated to install a recent version of the required Clang compiler (version 17). This is why on these specific boards we will install PoCL version 3. One of the main drawback is that there is no GPU 16-bit float support in this version :-(.

Note

We suppose that on the Orin Nano, NX & AGX, the Jetpack 5.2 is installed.

Install LLVM

Download ARM64 build and extract it:

export LLVM_VERSION=10
sudo apt install -y build-essential ocl-icd-libopencl1 cmake git pkg-config libclang-${LLVM_VERSION}-dev clang-${LLVM_VERSION} llvm-${LLVM_VERSION} make ninja-build ocl-icd-libopencl1 ocl-icd-dev ocl-icd-opencl-dev libhwloc-dev zlib1g zlib1g-dev clinfo dialog apt-utils libxml2-dev libclang-cpp${LLVM_VERSION}-dev libclang-cpp${LLVM_VERSION} llvm-${LLVM_VERSION}-dev libncurses5
cd /opt
sudo wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.1.0/clang+llvm-11.1.0-aarch64-linux-gnu.tar.xz
sudo tar -xvvf clang+llvm-11.1.0-aarch64-linux-gnu.tar.xz
sudo mv clang+llvm-11.1.0-aarch64-linux-gnu llvm-11.1.0
sudo rm clang+llvm-11.1.0-aarch64-linux-gnu.tar.xz
export LLVM_VERSION=12
sudo apt install -y build-essential ocl-icd-libopencl1 cmake git pkg-config libclang-${LLVM_VERSION}-dev clang-${LLVM_VERSION} llvm-${LLVM_VERSION} make ninja-build ocl-icd-libopencl1 ocl-icd-dev ocl-icd-opencl-dev libhwloc-dev zlib1g zlib1g-dev clinfo dialog apt-utils libxml2-dev libclang-cpp${LLVM_VERSION}-dev libclang-cpp${LLVM_VERSION} llvm-${LLVM_VERSION}-dev libncurses5
cd /opt
sudo wget https://github.com/llvm/llvm-project/releases/download/llvmorg-17.0.6/clang+llvm-17.0.6-aarch64-linux-gnu.tar.xz .
sudo tar -xvvf clang+llvm-17.0.6-aarch64-linux-gnu.tar.xz
sudo mv clang+llvm-17.0.6-aarch64-linux-gnu llvm-17.0.6
sudo rm clang+llvm-17.0.6-aarch64-linux-gnu.tar.xz

Note

On the Jetson TX2, the /opt folder is replaced by /data/opt. This is because the eMMC available space is low (~ 5 GB) and we preferred to install software on the SSD which is mounted in /data.

Compile and Install PoCL

Clone the repository, compile the code and install it:

cd ~/
mkdir softwares
cd softwares
git clone -b release_3_0 https://github.com/pocl/pocl.git pocl_3.0
cd pocl_3.0
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/pocl-3.0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-funroll-loops -march=native" -DCMAKE_C_FLAGS="-funroll-loops -march=native" -DWITH_LLVM_CONFIG=/opt/llvm-11.1.0/bin/llvm-config -DSTATIC_LLVM=ON -DENABLE_CUDA=ON ..
make -j6
sudo make install
sudo mkdir -p /etc/OpenCL/vendors/
sudo touch /etc/OpenCL/vendors/pocl.icd
echo "/opt/pocl-3.0/lib/libpocl.so" | sudo tee --append /etc/OpenCL/vendors/pocl.icd
cd ~/
mkdir softwares
cd softwares
git clone -b release_5_0 https://github.com/pocl/pocl.git pocl_5.0
cd pocl_5.0
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/pocl-5.0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-funroll-loops -march=native" -DCMAKE_C_FLAGS="-funroll-loops -march=native" -DWITH_LLVM_CONFIG=/opt/llvm-17.0.6/bin/llvm-config -DSTATIC_LLVM=ON -DENABLE_CUDA=ON .. -DLLC_HOST_CPU=cortex-a78
make -j6
sudo make install
sudo mkdir -p /etc/OpenCL/vendors/
sudo touch /etc/OpenCL/vendors/pocl.icd
echo "/opt/pocl-5.0/lib/libpocl.so" | sudo tee --append /etc/OpenCL/vendors/pocl.icd

Now OpenCL should be successfully installed on the system. You can check if it works with the following command:

clinfo

Warning

If clinfo is returning Number of platforms 0, it means that the current installation is not working :-(.

Info

On some boards, clinfo can show the following error message:

NvRmMemInitNvmap failed with Permission denied
This can be easily fixed by adding the current user the video group like this:
sudo usermod -a -G video [USER]

Sources

AMD Radeon GPUs

Download the Latest Drivers

First you need to download the latest amdgpu-install wrapper here: https://www.amd.com/en/support/linux-drivers.

On the Mercury EM780 running Ubuntu 24.04 LTS, we downloaded: Radeon™ Software for Linux® version 24.10.3 for Ubuntu 20.04.6 HWE.

Install

Install the AMD wrapper:

sudo apt install ./amdgpu-install_6.1.60103-1_all.deb 

Install the OpenCL ROCr driver:

amdgpu-install --no-dkms --usecase=opencl --opencl=rocr

After this command ROCr will be installed here: /opt/rocm/.

Install OpenCL headers and ICD:

sudo apt install opencl-headers ocl-icd-opencl-dev

Add the current user to the render group:

sudo usermod -a -G render $LOGNAME

Then reboot:

sudo reboot

Check if it works:

clinfo

Sources

clpeak Benchmark

cd ~/
mkdir workspace
cd workspace
git clone https://github.com/krrishnarraj/clpeak.git
cd clpeak
git submodule update --init --recursive --remote
mkdir build
cd build
cmake ..
make -j6
./clpeak