Need support to run OpenCL application on TX2 board

Hello Colleagues,

I’ve trying to run OpenCL application on TX2 board. It fails on:

clGetPlatformIDs(16, platforms, (unsigned *) &nPlatforms);

I’ve also tried with sample application:

int main(void) {
	unsigned err;
	unsigned numPlatforms=0;

	err = clGetPlatformIDs(0, NULL,&numPlatforms);
	if (CL_SUCCESS == err)
	    printf("\nDetected OpenCL platforms: %d", numPlatforms);
	else
	    printf("\nError calling clGetPlatformIDs. Error code: %d", err);

	getchar();
	return 0;
}

and it produce eroor: -1001

Error calling clGetPlatformIDs. Error code: -1001

open_cl_test (9.1 KB)

Could you please guide me. how to solve / avoid this issue ?

Thank you.

This is quite old now, but you may have a look to Can the Xavier run OpenCL applications? - #15 by Honey_Patouceul as a starting point with OpenCv.

1 Like

I’be built according to instruction above, but have same error with pocl internal example:

dev@ubuntu:~/pocl-1.6/build/examples/EinsteinToolkit$ ./EinsteinToolkit
EinsteinToolkit test
Reading sources...
Initialise...
-1001 <- clGetPlatformIDs -> 0
-1001 <- clGetPlatformIDs -> 0
No OpenCL platforms found
Could not create OpenCL context for selected device type
OpenCL device name: 
OpenCL platform name: 
OpenCL platform vendor:

Can you help to solve this issue ?

Not sure I can really help, but :

  • First be aware that some people experimented and shared like I did, but as far I understand, OpenCL support with Jetson would be less than from a desktop NVIDIA GPU (Jetsons have iGPU with different drivers so far). So be aware that it may not be the safest way for your project if you have short deadline.

  • Did you install clinfo and opencl-icd ? I have a script that I used at that time for building with XavierNX. Have a look to it, but don’t run it as such, it is old, mostly untested, and was for XavierNX. At step 2, you would use branch 2.0 in the following script (probably no need to build LLVM for A57 cores, assuming Denver cores are isolated).

build_pocl old script just for reading, probably wrong and obsolete
TOP_DIR=./pocl
mkdir -p $TOP_DIR
cd $TOP_DIR

###############################################################
# 1. Install pre-requisite packages
###############################################################
sudo apt update
sudo apt install -y build-essential cmake pkg-config
sudo apt install -y libtinfo-dev libltdl-dev zlib1g-dev
sudo apt install -y libhwloc-dev libglew-dev libedit-dev
sudo apt install -y ocl-icd-opencl-dev ocl-icd-dev opencl-headers clinfo
sudo apt install -y ocl-icd-libopencl1

# For userspace instrumentation if needed
#sudo apt install -y liblttng-ust-dev

sudo apt install -y libopenmpi-dev 

###############################################################
# 2.0 Just install llvm release for your distribution.
# For Xavier llvm-11 has support for carmel CPU architecture so 
# switch to another way.
###############################################################
#sudo apt install clang clang-format clang-tidy clang-tools libclang-dev


###############################################################
# Or 2.1 Install LLVM11-Aarch64 binary release
###############################################################
#mkdir -p llvm-11_tmp
#cd llvm-11_tmp
#wget -c --show-progress https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-aarch64-linux-gnu.tar.xz  
# Thanks to @janrinze for these install steps
#tar xf clang+llvm-11.0.0-aarch64-linux-gnu.tar.xz
#sudo mkdir -p /usr/lib/llvm-11/
#sudo mv clang+llvm-11.0.0-aarch64-linux-gnu/* /usr/lib/llvm-11/
#cd ..
# Clean up
#rm -rf llvm-11_tmp

###############################################################
# Or 2.2 Natively build LLVM11 from sources. 
# This will be huge size build (better use a big external disk
# with 50GB free) and huge build time.
###############################################################

###############################################################
# 2.2.1 Install first a CMake version not below 3.13.4
###############################################################
mkdir -p cmake-3.19.1
sudo apt install -y curl-devel zlib-devel apt-transport-https
cd cmake-3.19.1
wget -c --show-progress https://github.com/Kitware/CMake/releases/download/v3.19.1/cmake-3.19.1.tar.gz
tar xvf cmake-3.19.1.tar.gz
mkdir cmake-3.19.1-build
cd mkdir cmake-3.19.1-build
cmake -DCMAKE_USE_OPENSSL=OFF ../cmake-3.19.1
# If you want to build cmake-gui against Qt5
#cmake -DCMAKE_USE_OPENSSL=OFF -DBUILD_QtDialog=ON -DQT_QMAKE_EXECUTABLE=/usr/lib/qt5/bin/qmake ../cmake-3.19.1
make -j $(nproc)
#make test
sudo make install
cmake --version
cd ..
cd ..

# Clean up
#rm -rf cmake-3.19.1


###############################################################
# 2.2.2 With XavierNX, 8GB RAM may not be enough, so add 8GB 
# of temporary swap. 
###############################################################
fallocate -l 8G swapfile
chmod 600 swapfile
mkswap swapfile
sudo swapon swapfile

###############################################################
# 2.2.3 Install LLVM11 sources, configure, build and install 
###############################################################
mkdir llvm-11
cd llvm-11
wget -c --show-progress https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/llvm-project-11.0.0.tar.xz
tar xvf llvm-project-11.0.0.tar.xz

# Patch according to https://reviews.llvm.org/D80791
cd llvm-project-11.0.0
patch -p1 < ../aarch64-note-gnu-property.patch
cd ..

mkdir llvm-project-11.0.0-build
cd llvm-project-11.0.0-build
/usr/local/bin/cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_TARGETS_TO_BUILD="AArch64;NVPTX" -DCLANG_OPENMP_NVPTX_DEFAULT_ARCH=sm_72 -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DLLVM_PARALLEL_COMPILE_JOBS=6 -DLLVM_PARALLEL_LINK_JOBS=3 -DCMAKE_INSTALL_PREFIX=/usr/local/llvm-11 ../llvm-project-11.0.0/llvm

# This will take hours... consider nightly building.
cmake --build .
sudo cmake --install .
cd ..
cd ..
# Clean up
# rm -rf llvm-11

# if built as shared libs
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/llvm-11/lib

###############################################################
# 2.2.4 On NX, 8GB swap may not be needed any longer, clean up
###############################################################
sudo swapoff swapfile
sudo rm -f swapfile


###############################################################
# At this point we have llvm available
###############################################################


###############################################################
# 3. Prepare OCL ICD: https://www.khronos.org/news/permalink/opencl-installable-client-driver-icd-loader
# clinfo may look at /etc/OpenCL/vendors for ICDs
# This and the additional OCL install steps below may not be mandatory 
# if you supply env variable OCL_ICD_VENDORS. 
# see: https://www.systutorials.com/docs/linux/man/7-libOpenCL/
# YMMV.
###############################################################
sudo mkdir -p /etc/OpenCL
sudo mkdir -p /etc/OpenCL/vendors


###############################################################
# 4. Build POCL
###############################################################
mkdir pocl
cd pocl

# Get sources
git clone https://github.com/pocl/pocl.git
cd pocl
git branch -a
# Might you want to checkout a given branch rather than master, do it here
#git checkout release_1_3
cd ..

# Build
mkdir pocl-build
cd pocl-build
# For Xavier
/usr/local/bin/cmake -DCMAKE_BUILD_TYPE=Release -DLLC_HOST_CPU=carmel -DWITH_LLVM_CONFIG=/usr/lib/llvm-11/bin/llvm-config -DLLVM_ALL_TARGETS="AArch64;NVPTX" -DSTATIC_LLVM=ON -DENABLE_ICD=1 -DENABLE_CUDA=1 ../pocl
/usr/local/bin/cmake --build . --config Release
# This may raise some warnings... see below

# Test
# some tests may fail (with REGEXP failing...many format errors..)
#make test

# All 68 CUDA tests pass
#../pocl/tools/scripts/run_cuda_tests 


# Install
sudo cmake --install .

# Update pocl.icd
sudo rm -f /etc/OpenCL/vendors/pocl.icd
sudo ln -s /usr/local/etc/OpenCL/vendors/pocl.icd /etc/OpenCL/vendors/pocl.icd

cd ..
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/pocl

###############################################################
# 5. Show CL info
###############################################################
clinfo


###############################################################
# 6. Bench with clpeak
###############################################################
mkdir clpeak

# Get sources
git clone https://github.com/krrishnarraj/clpeak.git
cd clpeak
git submodule update --init --recursive --remote
cd ..

# Build
mkdir clpeak-build
cd clpeak-build
cmake ../clpeak
cmake --build .

# Run bench

# This would segfault when trying Xavier device
# https://github.com/pocl/pocl/issues/853#issuecomment-696367623
# ./clpeak

# Test only with basic device
POCL_DEVICES=basic ./clpeak

# Test only with pthreads device
POCL_DEVICES=pthread ./clpeak

# Test only with CUDA device
POCL_DEVICES=CUDA ./clpeak

cd ..

###############################################################
# 7. Try other testsuites or benchmarks
###############################################################

Hope it helps, but not sure I can further help.

1 Like

Thank you very much for support!

I’m able to install and run OpenCL:

$ clinfo -l
Platform #0: Portable Computing Language
 +-- Device #0: pthread-cortex-a57
 `-- Device #1: NVIDIA Tegra X2
$ poclcc -l
LIST OF DEVICES:
0:
  Vendor:   ARM
    Name:   pthread-cortex-a57
 Version:   OpenCL 1.2 PoCL HSTR: pthread-aarch64-unknown-linux-gnu-cortex-a57
1:
  Vendor:   NVIDIA Corporation
    Name:   NVIDIA Tegra X2
 Version:   OpenCL 1.2 PoCL HSTR: CUDA-sm_62

But unfortunately target application failed to compile required code:

20230907 10:16:54 NVIDIA Tegra X2-1 2882023 OpenCL args "-DEXP=2882023u -DWIDTH=256u -DSMALL_HEIGHT=256u -DMIDDLE=2u -DWEIGHT_STEP=0.0041360428406734713 -DIWEIGHT_STEP=-0.004119006453520699 -DIWEIGHTS={0,-0.0082210466928772531,-0.016374507777028039,-0.024460938876897462,-0.032480891049116126,-0.040434910820052336,-0.048323540223055607,-0.056147316835393993,} -DFWEIGHTS={0,0.0082891925317268283,0.016647095776281692,0.025074279289992216,0.03357131735034808,0.042138788995135644,0.050777278061896969,0.059487373227715891,}  -cl-std=CL2.0 -cl-finite-math-only "
6 errors generated.
20230907 10:16:55 NVIDIA Tegra X2-1 2882023 ASM compilation failed, retrying compilation using NO_ASM
6 errors generated.
20230907 10:16:57 NVIDIA Tegra X2-1 2882023 OpenCL compilation error -11 (args -DEXP=2882023u -DWIDTH=256u -DSMALL_HEIGHT=256u -DMIDDLE=2u -DWEIGHT_STEP=0.0041360428406734713 -DIWEIGHT_STEP=-0.004119006453520699 -DIWEIGHTS={0,-0.0082210466928772531,-0.016374507777028039,-0.024460938876897462,-0.032480891049116126,-0.040434910820052336,-0.048323540223055607,-0.056147316835393993,} -DFWEIGHTS={0,0.0082891925317268283,0.016647095776281692,0.025074279289992216,0.03357131735034808,0.042138788995135644,0.050777278061896969,0.059487373227715891,}  -cl-std=CL2.0 -cl-finite-math-only  -DNO_ASM=1)
20230907 10:16:57 NVIDIA Tegra X2-1 2882023 error: /home/dev/.cache/pocl/kcache/tempfile_I2Vdg4.cl:2186:14: casting '__global u32 *' (aka '__global unsigned int *') to type '__private atomic_uint *' (aka '__private _Atomic(unsigned int) *') changes address space of pointer
error: /home/dev/.cache/pocl/kcache/tempfile_I2Vdg4.cl:2195:20: casting '__global u32 *' (aka '__global unsigned int *') to type '__private atomic_uint *' (aka '__private _Atomic(unsigned int) *') changes address space of pointer
error: /home/dev/.cache/pocl/kcache/tempfile_I2Vdg4.cl:2285:14: casting '__global u32 *' (aka '__global unsigned int *') to type '__private atomic_uint *' (aka '__private _Atomic(unsigned int) *') changes address space of pointer
error: /home/dev/.cache/pocl/kcache/tempfile_I2Vdg4.cl:2294:20: casting '__global u32 *' (aka '__global unsigned int *') to type '__private atomic_uint *' (aka '__private _Atomic(unsigned int) *') changes address space of pointer
error: /home/dev/.cache/pocl/kcache/tempfile_I2Vdg4.cl:2333:40: passing 'const __global Word2 *restrict __private' (aka 'const __global int2 *restrict __private') to parameter of type 'const __private Word2 *' (aka 'const __private int2 *') changes address space of pointer
error: /home/dev/.cache/pocl/kcache/tempfile_I2Vdg4.cl:2338:40: passing 'const __global Word2 *restrict __private' (aka 'const __global int2 *restrict __private') to parameter of type 'const __private Word2 *' (aka 'const __private int2 *') changes address space of pointer
Device NVIDIA Tegra X2 failed to build the program

20230907 10:16:57 NVIDIA Tegra X2-1  Exception gpu_error: BUILD_PROGRAM_FAILURE clBuildProgram at src/clwrap.cpp:250 build

May be i need open new topic for compilation issue.

Thank you and best regards.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.