Libraries – can’t have enough

If you read different types of manuals how to compile OpenCL software on Linux, then you can get dizzy of all the LD-parameters. Also when installing the SDKs from AMD, Intel and NVIDIA, you get different locations for libraries, header-files, etc. Now GPGPU is old-fashioned and we go for heterogeneous programming, the chances get higher you will have more SDKs on your machine. Also if you want to keep it the way you have, reading this article gives you insight in what the design is after it all. Note that Intel’s drivers don’t give OpenCL support for their GPUs, but CPUs only.

As my mother said when I was young: “actually cleaning up is very simple”. I’m busy creating a PPA for this, but that will take some more time.

First the idea. For developers OpenCL consists of 5 parts:

  • GPUs-only: drivers with OpenCL-support
  • The OpenCL header-files
  • Vendor specific libraries (needed when using -lOpenCL)
  • libOpenCL.so -> a special driver
  • An installable client driver

Currently GPU-drivers are always OpenCL-capable, so you only need to secure 4 steps. These are discussed below.

Please note that in recent 64-bit distributions there is not lib64, but only ‘lib’ and ‘lib32′. If that is the case for you, you can use the commands that are mentioned with 32-bit.

Header-files

update: A new package “opencl-headers” installs exactly these files for you.

No more export CPPFLAGS=”-I/some_directory/opencl_sdk/include” at last! All SDKs provide the OpenCL 1.1 header-files originated from Khronos (or should).

We only need to put all headers found from the Khronos-webpage in /usr/include/CL/:

cd /usr/include

sudo mkdir CL

cd CL

sudo wget http://www.khronos.org/registry/cl/api/1.2/cl_d3d10.h \
http://www.khronos.org/registry/cl/api/1.2/cl_d3d11.h \
http://www.khronos.org/registry/cl/api/1.2/cl_dx9_media_sharing.h \
http://www.khronos.org/registry/cl/api/1.2/cl_ext.h \
http://www.khronos.org/registry/cl/api/1.2/cl_gl_ext.h \
http://www.khronos.org/registry/cl/api/1.2/cl_gl.h \
http://www.khronos.org/registry/cl/api/1.2/cl.h \
http://www.khronos.org/registry/cl/api/1.2/cl_platform.h \
http://www.khronos.org/registry/cl/api/1.2/opencl.h \
http://www.khronos.org/registry/cl/api/1.2/cl.hpp ;

If you are on mobile, also get EGL:

sudo wget http://www.khronos.org/registry/cl/api/1.2/cl_egl.h

If you want 1.1 headers, do the following:

cd /usr/include

sudo mkdir CL

cd CL

sudo wget http://www.khronos.org/registry/cl/api/1.1/cl_d3d10.h \
http://www.khronos.org/registry/cl/api/1.1/cl_ext.h \
http://www.khronos.org/registry/cl/api/1.1/cl_gl_ext.h \
http://www.khronos.org/registry/cl/api/1.1/cl_gl.h \
http://www.khronos.org/registry/cl/api/1.1/cl.h \
http://www.khronos.org/registry/cl/api/1.1/cl_platform.h \
http://www.khronos.org/registry/cl/api/1.1/opencl.h \
http://www.khronos.org/registry/cl/api/1.1/cl.hpp ;

sudo wget http://www.khronos.org/registry/cl/api/1.1/cl_egl.h

Now you can be sure you have the correct header-files.

Libaries

All vendors have their favourite spot to put their libraries; but actually a “just put your coat where you find a spot” is not the best to do. According to the best answer on stackoverflow, the libraries should be in /usr/local/lib, but since these are shared libraries, Intel has found a good location: /usr/lib/OpenCL/vendors/. There was some discussion about “vendors”, but think of various wrapper-libaries, IBM’s OpenCL Common Runtime, and such. So I agree with their choice.

Intel

update: Intel recently has completely changed the drivers for Linux. They now install in /opt/intel. Best is to copy all files from /opt/intel/opencl-1.2-x.x.xxxxxx to /usr/lib/OpenCL/vendors/intel to keep it orderly. If you choose not to, replace /usr/lib/OpenCL/vendors/intel with /opt/intel/opencl-1.2-x.x.xxxxxx.

The provided rpm can be converted to deb and then works if libnuma1 is installed:

apt-get install libnuma1
alien *.deb
dpkg -i *.deb

Though they’ve put their libraries at a nice spot, they made a little mistake. They put their libOpenCL.so in /usr/lib or /usr/lib64, instead of using a symbolic link. Below I discuss separately all around libOpenCL.so, since this is an important library. You need to copy it to the right directory. For 64 bit:

sudo cp /usr/lib64/libOpenCL.so /usr/lib64/OpenCL/vendors/intel/

For 32 bit systems:

sudo cp /usr/lib/libOpenCL.so /usr/lib/OpenCL/vendors/intel

It is very possible that if you installed another OpenCL SDK later, the library is lost. Not a real problem as explained later, but then you know.

To make the libraries available, I created opencl-vendor-intel.conf in /etc/ld.so.conf.d with the content (64 bit):

echo "/usr/lib64/OpenCL/vendors/intel" > /etc/ld.so.conf.d/opencl-vendor-intel.conf

In case you need to have 32-bit libraries too, you can add the location at the end of that file. And for 32 bit systems:

echo "/usr/lib/OpenCL/vendors/intel" > /etc/ld.so.conf.d/opencl-vendor-intel.conf

Then run

ldconfig

to start to using the new LD-location.

AMD

Edit: as suggested by Steffen Moeller in the comments, installing the deb-files in http://wiki.debian.org/ATIStream is easier. Just check if the files are at the right place.

The AMD APP Installer let’s you choose where you want to put the SDK. Just put it somewhere you want the SDK to be. Go to the root of the AMD-APP-SDK and move the lib-directory to /usr/lib(64)/OpenCL/vendors/, for 64 bit systems:

mkdir -p /usr/lib64/OpenCL/vendors/amd/
mv lib/x86_64/* /usr/lib64/OpenCL/vendors/amd/

And for 32 bit systems:

mkdir -p /usr/lib/OpenCL/vendors/amd/
mv lib/x86/* /usr/lib/OpenCL/vendors/amd/

Then we need to add them to ld-config. For 64 bit:

echo "/usr/lib64/OpenCL/vendors/amd" > /etc/ld.so.conf.d/opencl-vendor-amd.conf

And for 32 bit systems:

echo "/usr/lib/OpenCL/vendors/amd" > /etc/ld.so.conf.d/opencl-vendor-amd.conf

Then run

ldconfig

NVIDIA

This is somewhat hard. You probably want to use CUDA too, so for that reason we leave the libraries in/usr/local/cuda/lib/ to avoid breaking software. Of course I prefer them to be tidied up under /usr/lib(64)/OpenCL/vendors/ but it is no use to make a symbolic link. Installer can be found here.

Then we need to add them to ld-config, if you haven’t done that. For 64 bit:

echo "/usr/local/cuda/lib64" > /etc/ld.so.conf.d/opencl-vendor-nvidia.conf
echo "/usr/local/cuda/lib" >> /etc/ld.so.conf.d/opencl-vendor-nvidia.conf

For 32 bit:

echo "/usr/local/cuda/lib" > /etc/ld.so.conf.d/opencl-vendor-nvidia.conf

Then run

ldconfig

LibOpenCL.so

This library handles the selecting of the platforms (the vendors) and providing the correct libraries to the software needing the functionality. It is located under /usr/lib or /usr/lib64. You need to select which vendor you want to use. I personally think this driver should be open sourced and not from a specific vendor. Pick one (first line 64, second 32) out of these 6. But… from my own experience both AMD and Intel give you versions that work best with all 3 platforms, so I suggest you go for one of these.

Khronos open source

Get the “OpenCL 1.2 Installable Client Driver (ICD) Loader” from http://www.khronos.org/registry/cl/ and make the project (needs cmake). In the bin-directory there will be libOpenCL.so.1.2. Remove all files startting with libOpenCL.so* and copy libOpenCL.so.1.2 to /usr/lib/.

sudo ln -s /usr/lib64/libOpenCL.so /usr/lib64/libOpenCL.so.1.2
sudo ln -s /usr/lib/libOpenCL.so /usr/lib/libOpenCL.so.1.2

I use this myself. Will add the binaries later.

AMD

sudo ln -s /usr/lib64/OpenCL/vendors/amd/libOpenCL.so /usr/lib64/libOpenCL.so.1.2
sudo ln -s /usr/lib/OpenCL/vendors/amd/libOpenCL.so /usr/lib/libOpenCL.so.1.2

NVIDIA

Strongly discouraged to use this libOpenCL-library!

sudo ln -s /usr/local/cuda/lib64/libOpenCL.so /usr/lib64/libOpenCL.so.1.1
sudo ln -s /usr/local/cuda/lib/libOpenCL.so /usr/lib/libOpenCL.so.1.1

Intel

sudo ln -s /usr/lib64/OpenCL/vendors/intel/libOpenCL.so /usr/lib64/libOpenCL.so.1.2
sudo ln -s /usr/lib/OpenCL/vendors/intel/libOpenCL.so /usr/lib/libOpenCL.so.1.2

Then we add libOpenCL.so.1, libOpenCL.so.1.0 and libOpenCL.so:

sudo ln -s /usr/lib64/libOpenCL.so.1.2 /usr/lib64/libOpenCL.so.1
sudo ln -s /usr/lib64/libOpenCL.so.1 /usr/lib64/libOpenCL.so
sudo ln -s /usr/lib/libOpenCL.so.1.2 /usr/lib/libOpenCL.so.1
sudo ln -s /usr/lib/libOpenCL.so.1 /usr/lib/libOpenCL.so

As libOpenCL.so.1.2 is/should be backwards compatible with libOpenCL.so.1.0 and libOpenCL.so.1.1, you can choose to make those symbolic links too. Only do this when you have wrongly linked software – link to libOpenCL.so.1 in your own software.

Be sure to link to libOpenCL.so.1.1 if you chose to use NVidia’s library.

Installable Client Drivers

important: If you have chosen to leave the files in the original locations and skipped most of this tutorial, be sure to put the whole path and not only the filename in the icd-files.

If you list the platforms available, you actually list the ICDs. If you have written your own compiler, then you can easily add it without interfering with others. Like you can access an Intel CPU via both the AMD-ICD and Intel-ICD.

In /etc/OpenCL/vendor/ all ICDs need to be put. You’ll find them already here, or you have to create them. This is how they are provided now, but I omitted the library-location (which was in nvidia.icd), since it still gives errors if the ldconfig-steps where not done correctly.

sudo echo "libatiocl64.so" > /etc/OpenCL/vendors/atiocl64.icd
sudo echo "libatiocl32.so" > /etc/OpenCL/vendors/atiocl32.icdsudo echo "libintelocl.so" > /etc/OpenCL/vendors/intelocl.icdsudo echo "libcuda.so" > /etc/OpenCL/vendors/nvidia.icd

You can pick any name for the icd-files. AMD might replace ‘ati’ by ‘amd’ in their libraries, so if it stops working when updating, you know where to look.

Back to programming

When compiling a C or C++ program, you can keep your makefile simple. When the PPA with all this gets available, I’ll let you know via Twitter, Facebook. Tweet or like, if you support this blog!

Install OpenCL on Debian, Ubuntu and Mint orderly相关推荐

  1. How to install sougoupinyin on Debian/Ubuntu.

    #apt--get remove fcitx* && apt autoremove ###防止过多依赖包的干扰#apt-get update#apt-get fcitx im-conf ...

  2. Debian/Ubuntu/Kali 如何安装 Spotify 音乐白嫖神器

      How to install Spotify on Debian/Ubuntu/Kali Linux    可能有小伙伴不了解,什么是Spotify?博主照搬维基百科来做 简要介绍:    Spo ...

  3. Linux: debian/ubuntu下安装和使用Java 11

    Linux: debian/ubuntu下安装和使用Java 11 只需6行命令: su - echo "deb http://ppa.launchpad.net/linuxuprising ...

  4. N5105 软路由安装 ESXi 7 直通核显给 Debian / Ubuntu 虚拟机通过 Docker 实现 jellyfin 硬件转码视频文件(硬解/编码)

    摘要 在ESXi 7.0u3e里直通N5105的核显给虚拟机Debian 11/Ubuntu 22.04(更新到5.18内核),再套用Docker镜像nyanmisaka/jellyfin (10.8 ...

  5. debian/ubuntu 上安装和使用 Emacs

    直接进行安装: sudo apt update sudo apt install emacs 在debian 9上安装的版本是emacs24,在ubuntu 18.04上安装的版本是emacs25,目 ...

  6. Debian/Ubuntu/Centos下编译安装RocksDB

    参考:rocksdb/INSTALL.md at master · facebook/rocksdb 注意:gcc版本至少要4.8,安装教程:在CentOS/Debian/Ubuntu上编译安装最新版 ...

  7. 在CentOS/Debian/Ubuntu上编译安装最新版 GCC 8 , cmake 3 和ninja

    CentOS不像Debian/Ubuntu,不能直接从官方库中安装最新版的gcc/g++,只能源码编译安装. gcc下载地址:Index of /gnu/gcc 我选择了最新版本 gcc-8.3.0, ...

  8. ClickHouse系列教程一:Debian/Ubuntu 下ClickHouse的安装和使用

    ClickHouse系列教程: ClickHouse系列教程 ClickHouse是一个真正面向列的DBMS.数据按列存储,并在执行数组(向量或列块)期间存储.只要有可能,就会在数组上调度操作,而不是 ...

  9. LLVM系列文章1: Debian/Ubuntu 安装和使用 LLVM

    文章目录 1.添加更新源 2.添加签名 3.安装 4.测试和使用 1.添加更新源 注意:Debian/Ubuntu 系统自带的更新源里的LLVM版本过旧,是 llvm-6.0,没有更新的版本 如果你的 ...

最新文章

  1. Java的基本数据类型
  2. 游戏运行时报0xc000007b错的解决办法
  3. bucket sort count sort
  4. Windows Mobile 6 中为开发人员提供的新功能(1)
  5. 新年巨献!祝所有朋友新一年闪闪发光
  6. Greenplum【环境搭建 04】使用GPKafka实现Kafka数据导入Greenplum数据库(扩展安装文件网盘分享)
  7. 《cocos2d-x手机游戏开发实战》直播课程第一期介绍
  8. Oracle迁移索引
  9. http强缓存在firefox和chrome之间的差异
  10. linux如何安装django
  11. BZOJ1050 [HAOI2006]旅行comf
  12. 输出 系统 环境变量
  13. IIS发布可下载文件的站点
  14. LoadRunner 11 安装及破解
  15. dosbox 实现程序编译
  16. 黑苹果alc269声卡仿冒id_笔记本制作仿冒声卡驱动AppleHDA最详细教程
  17. 使用java + selenium + OpenCV破解腾讯防水墙滑动验证码
  18. matlab中counter怎么用,matlab中fspecial函数的用法
  19. wps取消英文首字母大写功能
  20. stm32使用各种传感器的教程

热门文章

  1. 【转】SQL Server服务器名称与默认实例名不一致的修复方法
  2. sharepoint 概念及认证方式介绍
  3. TFS(Team Foundation Server)敏捷使用教程
  4. TFS下的源代码控制
  5. linux 14.04安装方法,Ubuntu 14.04 安装配置GNOME经典界面
  6. oracle ora-22288,向oracle的blob字段导入文件
  7. 【 HDU - 5459】Jesus Is Here(dp)
  8. 【CodeForces - 558C】Amr and Chemistry(位运算,bfs,计数,思维,tricks)
  9. 【牛客 - 280A】勘测(fib数列,思维,打表)
  10. JS正则表达式常见场景下的用法总结