User Tools

Site Tools


install_opencl

OpenCL Install for Linux

OpenCL (Open Computing Language) is for multiprocessor/parallel computing. It is often used for running paralleled code on a GPU.

Intel Architecture (incomplete)

bash$ sudo apt-get install beignet clinfo ocl-icd-opencl-dev opencl-headers ocl-icd-libopencl1
bash$ sudo apt-get install beignet-opencl-icd 

NVidia Architecture (incomplete)

If you have an Nvidia graphics card. I assume you have already install the nvidia graphics card driver. If so, then you need to add the OpenCL development and the nvidia-modprobe packages.

I had nvidia version 304 installed when I started. It seems you need at least nvidia version 331 (nvidia-331 package) to have the needed uvm module available for OpenCL. I updated my driver to the latest which appears to be nvidia-346-updates. I also installed the related packages for opencl and uvm.

bash$ sudo apt-get install nvidia-346-updates nvidia-346-updates-dev nvidia-opencl-icd-346-updates nvidia-346-updates-uvm nvidia-opencl-icd-346-updates
bash$ sudo apt-get install nvidia-opencl-dev nvidia-modprobe  

See if the nvidia_uvm module is loaded. Since it was not listed below, I will load the module manually.

arwillis@visionlab16-pc:~$ lsmod  | grep nv
nvidia               8379750  57 
drm                   303102  2 nvidia
arwillis@visionlab16-pc:~$ ls /dev/nv*
/dev/nvidia0  /dev/nvidiactl

Load the nvidia-uvm module manually. The needed /dev/nvidia-uvm device is then created.

bash$ sudo modprobe nvidia-uvm
arwillis@visionlab16-pc:~$ ls /dev/nv*
/dev/nvidia0  /dev/nvidiactl  /dev/nvidia-uvm

I also want to play with CUDA for GPU programming so I installed the CUDA development files.

bash$ sudo apt-get install nvidia-cuda-dev

For OpenCL, I was consistently having compilation problems with “cannot find -lOpenCL”. The linker couldn't find the OpenCL libraries!

arwillis@visionlab16-pc:~/OpenCL/tools-master$ gcc -std=gnu99 -ocl-demo cl-demo.c cl-helper.c -L/usr/lib/i386-gnu -L/usr/lib/x86_64-linux-gnu/libOpenCL.so.1 -lrt -lOpenCL
/usr/bin/ld: cannot find -lOpenCL
collect2: error: ld returned 1 exit status

But they were right here!

arwillis@visionlab16-pc:~/OpenCL/tools-master$ locate libOpenCL
/usr/lib/i386-linux-gnu/libOpenCL.so.1
/usr/lib/i386-linux-gnu/libOpenCL.so.1.0
/usr/lib/i386-linux-gnu/libOpenCL.so.1.0.0
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0

Turns out that the library's root shared link “libOpenCL.so” was missing. I created a symbolic link to point from this file to the existing files from the nvidia package.

arwillis@visionlab16-pc:~/OpenCL/tools-master$ cd /usr/lib/x86_64-linux-gnu/
arwillis@visionlab16-pc:/usr/lib/x86_64-linux-gnu$ sudo ln -s libOpenCL.so.1 libOpenCL.so

For building 32-bit OpenCL program one would need to do the same in the /usr/lib/i386-linux-gnu directory.

arwillis@visionlab16-pc:/usr/lib/x86_64-linux-gnu$ cd /usr/lib/i386-linux-gnu/
arwillis@visionlab16-pc:/usr/lib/i386-linux-gnu$ sudo ln -s libOpenCL.so.1 libOpenCL.so

Then things started to finally work! Strange but clinfo, when working returns the response below.

arwillis@visionlab16-pc:/usr/lib/i386-linux-gnu$ clinfo
clinfo: /usr/lib/x86_64-linux-gnu/libOpenCL.so.1: no version information available (required by clinfo)
E: -30

To test OpenCL you might want to install darktable and run it as follows:

arwillis@visionlab16-pc:~/OpenCL/tools-master$ darktable -d opencl
[opencl_init] opencl related configuration options:
[opencl_init] 
[opencl_init] opencl: 1
[opencl_init] opencl_library: ''
[opencl_init] opencl_memory_requirement: 768
[opencl_init] opencl_memory_headroom: 300
[opencl_init] opencl_device_priority: '*/!0,*/*/*'
[opencl_init] opencl_size_roundup: 16
[opencl_init] opencl_async_pixelpipe: 0
[opencl_init] opencl_synch_cache: 0
[opencl_init] opencl_number_event_handles: 25
[opencl_init] opencl_micro_nap: 1000
[opencl_init] opencl_use_pinned_memory: 0
[opencl_init] opencl_use_cpu_devices: 0
[opencl_init] opencl_avoid_atomics: 0
[opencl_init] opencl_omit_whitebalance: 0
[opencl_init] 
[opencl_init] trying to load opencl library: '<system default>'
[opencl_init] opencl library 'libOpenCL' found on your system and loaded
[opencl_init] found 1 platform
[opencl_init] found 1 device
[opencl_init] device 0 `GeForce GTX 460' has sm_20 support.
[opencl_init] discarding device 0 `GeForce GTX 460' due to insufficient global memory (767MB).
[opencl_init] no suitable devices found.
[opencl_init] FINALLY: opencl is NOT AVAILABLE on this system.

Note: darktable found the opencl card but decided not to use it for some reason.

One can also try to use OpenCL for GPU acceleration of 3D rendering as provided by blender. To test OpenCL and blender you must install blender. Then run blender from the command line as follows:

bash$ CYCLES_OPENCL_TEST=true blender

The go to File→User Preferences→System and look under the “Compute Device:” options in the bottom left of the preferences. “OpenCL” should be a selectable button if it is available. When you click on it, it will show your OpenCL computing devices which are available for use by the Cycles rendering engine integrated with Blender.

A good resource to test is here: http://wiki.tiker.net/OpenCLHowTo (see the last “Testing” section) Some of the text there is reproduced here:

bash$ curl https://codeload.github.com/hpc12/tools/tar.gz/master | tar xvfz -
bash$ cd tools-master
bash$ make  # <-- this is where I had the OpenCL linking problems and needed the symlinks above
bash$ ./print-devices
platform 0: vendor 'NVIDIA Corporation'
  device 0: 'GeForce GTX 460'
arwillis@visionlab16-pc:~/OpenCL/tools-master$ ./cl-demo 1000000 10
Choose platform:
[0] NVIDIA Corporation
Enter choice: 0
Choose device:
[0] GeForce GTX 460
Enter choice: 0
---------------------------------------------------------------------
NAME: GeForce GTX 460
VENDOR: NVIDIA Corporation
PROFILE: FULL_PROFILE
VERSION: OpenCL 1.1 CUDA
EXTENSIONS: cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts  cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 
DRIVER_VERSION: 346.82

Type: GPU 
EXECUTION_CAPABILITIES: Kernel 
GLOBAL_MEM_CACHE_TYPE: Read-Write (2)
CL_DEVICE_LOCAL_MEM_TYPE: Local (1)
SINGLE_FP_CONFIG: 0x3f
QUEUE_PROPERTIES: 0x3

VENDOR_ID: 4318
MAX_COMPUTE_UNITS: 7
MAX_WORK_ITEM_DIMENSIONS: 3
MAX_WORK_GROUP_SIZE: 1024
PREFERRED_VECTOR_WIDTH_CHAR: 1
PREFERRED_VECTOR_WIDTH_SHORT: 1
PREFERRED_VECTOR_WIDTH_INT: 1
PREFERRED_VECTOR_WIDTH_LONG: 1
PREFERRED_VECTOR_WIDTH_FLOAT: 1
PREFERRED_VECTOR_WIDTH_DOUBLE: 1
MAX_CLOCK_FREQUENCY: 1440
ADDRESS_BITS: 32
MAX_MEM_ALLOC_SIZE: 201113600
IMAGE_SUPPORT: 1
MAX_READ_IMAGE_ARGS: 128
MAX_WRITE_IMAGE_ARGS: 8
IMAGE2D_MAX_WIDTH: 32768
IMAGE2D_MAX_HEIGHT: 32768
IMAGE3D_MAX_WIDTH: 2048
IMAGE3D_MAX_HEIGHT: 2048
IMAGE3D_MAX_DEPTH: 2048
MAX_SAMPLERS: 16
MAX_PARAMETER_SIZE: 4352
MEM_BASE_ADDR_ALIGN: 4096
MIN_DATA_TYPE_ALIGN_SIZE: 128
GLOBAL_MEM_CACHELINE_SIZE: 128
GLOBAL_MEM_CACHE_SIZE: 114688
GLOBAL_MEM_SIZE: 804454400
MAX_CONSTANT_BUFFER_SIZE: 65536
MAX_CONSTANT_ARGS: 9
LOCAL_MEM_SIZE: 49151
ERROR_CORRECTION_SUPPORT: 0
PROFILING_TIMER_RESOLUTION: 1000
ENDIAN_LITTLE: 1
AVAILABLE: 1
COMPILER_AVAILABLE: 1
MAX_WORK_GROUP_SIZES: 1024 1024 64 
---------------------------------------------------------------------
*** Kernel compilation resulted in non-empty log message.
*** Set environment variable CL_HELPER_PRINT_COMPILER_OUTPUT=1 to see more.
*** NOTE: this may include compiler warnings and other important messages
***   about your code.
*** Set CL_HELPER_NO_COMPILER_OUTPUT_NAG=1 to disable this message.
0.000490 s
24.487002 GB/s
GOOD
arwillis@visionlab16-pc:~/OpenCL/tools-master$ 

It works!

Arm7hf

Download the OpenCL SDK for the Mali GPU here:

http://malideveloper.arm.com/resources/sdks/mali-opencl-sdk/

On the Odroid decompress the tar.gz:

bash$ tar xzvf Mali_OpenCL_SDK_v1.1.0.0a36a7_Linux.tgz

The code appears set to be cross-compiled. I had to change the file platform.mk in the root folder.

# This confidential and proprietary software may be used only as
# authorised by a licensing agreement from ARM Limited
#   (C) COPYRIGHT 2013 ARM Limited
#       ALL RIGHTS RESERVED
# The entire notice above must be reproduced on all authorised
# copies and copies may only be made to the extent permitted
# by a licensing agreement from ARM Limited.

#CC:=arm-none-linux-gnueabi-g++
#AR=arm-none-linux-gnueabi-ar
CC:=g++
AR=ar

# Test to see if the platform is Windows (it's Windows if the shell has the .exe extention).
ifeq (.exe, $(suffix $(SHELL)))
	RM:=del /f
	CONCATENATE:=&
	MKDIR:=mkdir
	CP:=copy
else
	RM:=rm -f
	CONCATENATE:=;
	MKDIR:=mkdir -p
	CP:=cp
endif	

After doing this one can compile the OpenCL stub library and the common libraries. Here's my console session compiling these libraries:

odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0$ ls
common  docs  include  lib  Mali_OpenCL_SDK_v1.1.0_Documentation.html  platform.mk  samples
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0$ cd lib/
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/lib$ ls
Makefile  opencl_stubs.c
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/lib$ make
g++ -fpic -shared -I../include/ -o libOpenCL.so opencl_stubs.c
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/lib$ cd ..
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0$ cd common/
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/common$ ls
common.cpp  common.h  image.cpp  image.h  Makefile
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/common$ make
g++ -c -Wall -I../include -Iinclude common.cpp -o common.o
g++ -c -Wall -I../include -Iinclude image.cpp -o image.o
ar rcs  libCommon.a common.o image.o
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/common$

The OpenCL setup isn't present on the arm in any logical way so I had to create the appropriate plumbing to connect the Mali OpenCL driver to the linux OpenCL stubs. This routing of function invokations to the appropriate GPU/GPU Driver is done through /etc/OpenCL/vendors/XXXX.icd files. In the .icd file a reference to the OpenCL driver library is provided.

 
odroid@odroid:/etc$ locate libOpenCL
/usr/lib/arm-linux-gnueabihf/libOpenCL.so
/usr/lib/arm-linux-gnueabihf/libOpenCL.so.1
/usr/lib/arm-linux-gnueabihf/libOpenCL.so.1.0.0
/usr/lib/arm-linux-gnueabihf/mali-egl/libOpenCL.so
/usr/share/doc/ocl-icd-libopencl1/html/libOpenCL.html
/usr/share/man/man7/libOpenCL.7.gz
/usr/share/man/man7/libOpenCL.so.7.gz
odroid@odroid:/$ cd /etc
odroid@odroid:/etc$ sudo mkdir OpenCL
odroid@odroid:/etc$ cd OpenCL
odroid@odroid:/etc/OpenCL$ ls -al /usr/lib/arm-linux-gnueabihf/libOpenCL.so*
lrwxrwxrwx 1 root root    18 Mar 15  2014 /usr/lib/arm-linux-gnueabihf/libOpenCL.so -> libOpenCL.so.1.0.0
lrwxrwxrwx 1 root root    18 Mar 15  2014 /usr/lib/arm-linux-gnueabihf/libOpenCL.so.1 -> libOpenCL.so.1.0.0
-rw-r--r-- 1 root root 22120 Mar 15  2014 /usr/lib/arm-linux-gnueabihf/libOpenCL.so.1.0.0
odroid@odroid:/etc/OpenCL$ export LD_LIBRARY_PATH=/usr/lib/arm-linux-gnueabihf/mali-egl:$LD_LIBRARY_PATH
odroid@odroid:/etc/OpenCL$ clinfo 
I: ICD loader reports no usable platforms
odroid@odroid:/etc/OpenCL$ sudo mkdir vendors
odroid@odroid:/etc/OpenCL$ cd vendors/
odroid@odroid:/etc/OpenCL/vendors$ sudo vi arm7hf.icd
odroid@odroid:/etc/OpenCL/vendors$ clinfo
I: ICD loader reports no usable platforms
odroid@odroid:/etc/OpenCL/vendors$ more arm7hf.icd 
/usr/lib/arm-linux-gnueabihf/mali-egl/libOpenCL.so
odroid@odroid:/etc/OpenCL/vendors$ sudo vi arm7hf.icd
odroid@odroid:/etc/OpenCL/vendors$ clinfo 
E: -30

The “E: -30” is, surprisingly enough, an indication that OpenCL is actually working. Let's verify by running one of the provided OpenCL sample programs that comes in the Mali SDK.

odroid@odroid:~$ cd OpenCL/
odroid@odroid:~/OpenCL$ ls
DUI0538F_mali_t600_opencl_dg.pdf  Mali_OpenCL_SDK_v1.1.0
odroid@odroid:~/OpenCL$ cd Mali_OpenCL_SDK_v1.1.0/
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0$ ls
common  docs  include  lib  Mali_OpenCL_SDK_v1.1.0_Documentation.html  platform.mk  samples
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0$ cd samples/
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/samples$ sl
bash: sl: command not found
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/samples$ ls
64_bit_integer  fir_float  hello_world_c  hello_world_opencl  hello_world_vector  image_scaling  mandelbrot  sgemm  sobel  sobel_no_vectors  template
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/samples$ cd hello_world_opencl/
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/samples/hello_world_opencl$ ls
assets  hello_world_opencl  hello_world_opencl.cpp  hello_world_opencl.o  Makefile
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/samples/hello_world_opencl$ make
cd ../../lib ; make libOpenCL.so
make[1]: Entering directory `/home/odroid/OpenCL/Mali_OpenCL_SDK_v1.1.0/lib'
make[1]: `libOpenCL.so' is up to date.
make[1]: Leaving directory `/home/odroid/OpenCL/Mali_OpenCL_SDK_v1.1.0/lib'
cd ../../common/ ; make libCommon.a
make[1]: Entering directory `/home/odroid/OpenCL/Mali_OpenCL_SDK_v1.1.0/common'
make[1]: `libCommon.a' is up to date.
make[1]: Leaving directory `/home/odroid/OpenCL/Mali_OpenCL_SDK_v1.1.0/common'
g++ hello_world_opencl.o -o hello_world_opencl -L../../lib -L../../common -lOpenCL -lCommon
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/samples/hello_world_opencl$ ./hello_world_opencl 
Profiling information:
Queued time: 	0.188ms
Wait time: 	5.84603ms
Run time: 	2.05365ms
odroid@odroid:~/OpenCL/Mali_OpenCL_SDK_v1.1.0/samples/hello_world_opencl$ 

Hurray! OpenCL is working according to these results. Now — how do we use it???

install_opencl.txt · Last modified: 2015/08/31 14:13 by arwillis