Build and Install OpenCL on Jetson Nano

Muhammad Yunus
2 min readSep 19, 2021

--

Previously we are successfully build and install OpenCL in Jetson TK1 and X96 MAX+ via PoCL with CPU backend. PoCL it self more implemented on CPU or other option is using other supported backend like CUDA for NVIDIA GPU or HSA for AMD APU. Now, I want to build PoCL 1.7 with CUDA backend enable on Jetson Nano.

General Information

Board   : Jetson Nano (B01)
Arc : aarch64
OS : Ubuntu 18.04 LTS
Jetpack : 4.5 (L4T 32.5)
Kernel : GNU/Linux 4.9.201-tegra
CUDA : 10.2 (cuDNN 8.0)
GCC : 7.5.0 (G++ 7.5.0)

Installation

  • Because PoCL use clang+llvm for compilation, we will use Clang+LLVM 10 for this, execute to set LLVM version,
LLVM_VERSION=10
  • 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
  • Update October 22, 2022 : also support pocl release_3_0 .
  • Update December 17, 2022 : error compiling for pocl release_3_1 .
  • Configure & Build,
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/pocl/ -DENABLE_CUDA=ON ..make 
sudo make install
  • 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.

Installation Test

  • Run clinfo ,
clinfo
  • Result should look like this,
  • We can see there are two kernel device detected. CPU (ARM Cortex A57 ) and GPU (NVIDIA Tegra X1).
  • 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-a57
1.1 Hardware version: OpenCL 1.2 pocl HSTR: pthread-aarch64-unknown-linux-gnu-cortex-a57
1.2 Software version: 1.7
1.3 OpenCL C version: OpenCL C 1.2 pocl
1.4 Parallel compute units: 4
2. Device: NVIDIA Tegra X1
2.1 Hardware version: OpenCL 1.2 pocl HSTR: CUDA-sm_53
2.2 Software version: 1.7
2.3 OpenCL C version: OpenCL C 1.2 pocl
2.4 Parallel compute units: 1

Source :

--

--

Muhammad Yunus
Muhammad Yunus

Written by Muhammad Yunus

IoT Engineer, Software Developer & Machine Learning Enthusiast