Install OpenCL on DietPi OS X96 MAX+

Muhammad Yunus
3 min readSep 12, 2021

--

The X96 MAX+ tv box is affordable option for playing with Linux compare to the Raspberry Pi 4 in term off price and specification. X96 MAX+ come with Gigabit Ethernet and USB3, 2.4G+5.8GHz Dual Wifi, BT4.1, 4GB RAM DDR4, with Amlogic S905X3 64-bit Quad-Core ARM® Cortex™ A55 processor and Mali-G31™ MP2 GPU.

In this stories, I want to show you how to build & install OpenCL on DietPi OS which run on top of X96 MAX+.

OpenCL (Open Computing Language) is a framework for writing programs that execute across heterogeneous platforms consisting of central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), field-programmable gate arrays (FPGAs) and other processors or hardware accelerators. [Wikipedia]

Since there is no official Linux Driver and OpenCL Implementation for Mali-G31™ GPU from ARM, we can’t run OpenCL on this X96 MAX+. Luckily, there is several opensource OpenCL implementation that can help us to solve this issue. One of the options is PoCL (Portable Computing Language).

PoCL (Portable Computing Language)

PoCL is a portable open source (MIT-licensed) implementation of the OpenCL standard (1.2 with some 2.0 features supported). In addition to being an easily portable multi-device (truely heterogeneous) 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. [PoCL Page]

We need to understand, even we use PoCL as opensource implementation OpenCL to run on X96 MAX+, it’s more implemented on CPU (other option is use CUDA/HSA/TCE as a backend — experimental). That means we still can’t take advantage of the Mali-G31™ MP2 GPU. So for this reason, we will compile PoCL for X96 MAX+ CPU (ARM Cortex-A55).

Prerequisites

  • Flash X96 MAX+ with DietPi OS. Refer to this tutorial to flash X96 MAX+ with Armbian OS and update that version to DietPi OS.

Dependencies Library

  • Because PoCL use clang+llvm for compilation, we will use Clang+LLVM 11 for this, execute to set LLVM version,
LLVM_VERSION=11
  • Install dependency libraries,
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

Download & Build PoCL 1.7

  • Download PoCL 1.7 source from github,
cd ~
git clone --single-branch --branch release_1_7 https://github.com/pocl/pocl.git
cd pocl
mkdir build
cd build
  • Configure & Build,
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/pocl/ -DLLC_TRIPLE=aarch64-unknown-linux-gnu -DLLC_HOST_CPU=cortex-a55 ..make 
sudo make install
build process
  • Create pocl.icd file in /etc/OpenCL/vendors/ path,
mkdir -p /etc/OpenCL/vendors/
cd /etc/OpenCL/vendors/
sudo nano pocl.icd
  • Paste the following path,
/usr/local/pocl/lib/libpocl.so
  • Exit and save pocl.icd file.
  • If there is another .icd file inside /etc/OpenCL/vendors/ directory, like armocl.icd or mali.icd, better delete it by this command,
sudo rm -rf /etc/OpenCL/vendors/armocl.icd
sudo rm -rf /etc/OpenCL/vendors/mali.icd

Installation Test

  • Run clinfo ,
clinfo
  • Result should look like this,
  • Create small C program to query device info, called it with query_device_info.c,
  • Compile it using gcc + ocl-icd loader,
gcc query_device_info.c -o query_device_info `pkg-config --libs --cflags OpenCL`
  • Then run the compiled binary,
./query_device_info
  • Output should look like this,
1. Device: pthread-cortex-a55
1.1 Hardware version: OpenCL 1.2 pocl HSTR: pthread-aarch64-unknown-linux-gnu-cortex-a55
1.2 Software version: 1.7
1.3 OpenCL C version: OpenCL C 1.2 pocl
1.4 Parallel compute units: 4

Source :

--

--

Muhammad Yunus

IoT Engineer, Software Developer & Machine Learning Enthusiast