Install OpenCL on Debian, Ubuntu and Mint orderly

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!


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/448607.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux7 配置mysql5.7字符集编码

linux 安装后 mysql5.7 字符集默认是拉丁,不能存储中文,修改步骤如下: 在 vim /etc/mysql/my.cnf 修改配置文件 在[mysqld] 下添加如下配置 character-set-serverutf8 init_connectSET NAMES utf8 重启mysql服务 systemctl restart mysqld.…

解决:java.io.IOException: invalid constant type: 15

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 启动 dubbo 服务报错: java.io.IOException: invalid constant type: 15 我的情况是项目本身 是用的1.7 。而我自己用的…

liunx常用命令笔记

安装软件教程 linux安装java:https://www.cnblogs.com/lamp01/p/8932740.html linux安装mysql:https://www.cnblogs.com/daemon-/p/9009360.html linux安装redis:https://blog.csdn.net/qq_30764991/article/details/81564652 linux安装nginx…

李洋疯狂C语言之编程实现统计某年某月份的天数

今天的题目:编程实现统计某年某月的天数 例如: 输入:2017.7 输出:31天 先附上我自己想的方法,由于几个功能放一起太繁琐,于是我想把他们分为三个函数,分别来实现这个功能: #incl…

MQ 之 RocketMQ

前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。 RocketMQ 是出自 A 公司的开源产品,用 Java 语言实现,在设计时参考了 Kafka,并做出了自己的一些改进…

好久没敲代码了(强行补上今天的博客。。。)

流水账日记(哈哈) 今天没课,早上好好的睡了个懒觉(虽然还是很困- -); 哥几个把昨天买的排骨洗了做了个排骨汤,虽然不如家里做的好吃,但对此时的我们来说已经是美味了,晚…

Ubuntu下使用AMD APP编写OpenCL程序

对于Ubuntu或其近亲(Lubuntu、Kubuntu、Mint等)编写OpenCL程序也不会太难。由于本例用的是AMD APP SDK,因此需要AMD的GPU以及相关驱动。首先,去AMD官网下载GPU驱动——AMD Catalyst。如果你用的是APU并且还有一块独立显卡的话&…

jdk的安装与配置

Linux一、安装JDK 从sun网站上直接下载JDK:http://java.sun.com/j2se/1.4.2/download.html提供了两个下载j2re-1_4_2_10-linux-i586.bin 13.75 MB, j2re-1_4_2_10-linux-i586-rpm.bin 13.27 MB:1、RPM in self-extracting file (j2re-1_4_2_10-linux…

李洋疯狂C语言之n个人报数,报到3的退出,最后留在场上的是原来的第几位(约瑟夫环)

今天老师布置了个题目&#xff0c;约瑟夫环&#xff0c;俗称猴子选大王。n个人报数&#xff0c;报到3的退出&#xff0c;最后留在场上的时原来的第几位 #include <stdio.h>int main() {int i, n, q, p 0; //计数 i ,人数 n ,报数 p ,场上人数 qprintf ("input…

搭建Vue脚手架(vue-cli)并创建一个项目

1、 安装nodejs环境 官网下载&#xff1a;https://nodejs.org/en/download/ 一直默认就行&#xff0c;路径可以改变但要记得到 安装完成后cmd&#xff0c;输入node -v ,npm -v 如果能看到node和npm的版本号了&#xff0c;说明已经安装成功 2、安装vue-cli 有npm和cnpm两种方式…

NPM 使用介绍

前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到教程。 NPM是随同NodeJS一起安装的包管理工具&#xff0c;能解决NodeJS代码部署上的很多问题&#xff0c;常见的使用场景有以下几种&#xff1a…

人生致命的八个经典问题

问题一&#xff1a;如果你家附近有一家餐厅&#xff0c;东西又贵又难吃&#xff0c;桌上还爬着蟑螂&#xff0c;你会因为它很近很方便&#xff0c;就一而再、再而三地光临吗&#xff1f; 回答&#xff1a;你一定会说&#xff0c;这是什么烂问题&#xff0c;谁那么笨&#xff0c…

RabbitMQ学习总结(5)——发布和订阅实例详解

2019独角兽企业重金招聘Python工程师标准>>> 一、Publish/Subscribe&#xff08;发布/订阅&#xff09;&#xff08;using the Java Client&#xff09; 在前面的教程中,我们创建了一个work Queue&#xff08;工作队列&#xff09;。工作队列背后的假设是每个任务是…

iOS有哪些数据类型/基本数据类型?

简述 本文主要探究使用OC作为iOS开发语言时&#xff0c;我们能使用哪些数据类型。 一切类型始于C。 C语言的类型 基本数据类型&#xff1a; 基本数据类型&#xff08;fundamental data types&#xff09;也叫原始数据类型&#xff08;primitive data types&#xff09; 整型、字…

李洋疯狂C语言之将”you are come from shanghai ”倒置为”shanghai from come are you”,将句子中的单词位置倒置,而不改变单词内部结构

题目: 编写一个C函数,将”you are come from shanghai ”倒置为”shanghai from come are you”,及将句子中的单词位置倒置,而不改变单词内部结构 #include <stdio.h> #include <string.h> void change(char *p1, char *p2); //函数声明 int main() {char str[] …

马桶怎么清洗才干净无异味?

方法/步骤 在马桶水箱中一定要放上洁厕宝&#xff1a; 洁厕宝里面含有多种去除马桶中杂质以及异味的功能&#xff0c;另外它还带有香香的味道&#xff0c;我们一按冲马桶的按钮&#xff0c;放出来的总是蓝色的水&#xff0c;十分的美观和好看&#xff0c;但是这并不是花瓶般的作…

白话解说:阻塞和非阻塞,同步和异步

阻塞和非阻塞&#xff0c;同步和异步是node.js里经常遇到的词汇&#xff0c;举例说明&#xff1a; 我要看足球比赛&#xff0c;但是妈妈叫我烧水&#xff0c;电视机在客厅&#xff0c;烧水要在厨房。家里有2个水壶&#xff0c;一个是普通的水壶&#xff0c;另一个是水开了会叫的…

苏嵌点滴(一)

来苏嵌也有12天了&#xff0c;也渐渐开始习惯这样的生活&#xff0c;每天睁眼到闭眼&#xff0c;全都是代码。每天都得学习很多新的知识&#xff0c;C语言学到现在也学得差不多了&#xff0c;还有明天一天课。 指针、数组这些C语言中的重点&#xff0c;还是需要一点时间消化的…

Mysql学习总结(8)——MySql基本查询、连接查询、子查询、正则表达查询讲解...

2019独角兽企业重金招聘Python工程师标准>>> 查询数据指从数据库中获取所需要的数据。查询数据是数据库操作中最常用&#xff0c;也是最重要的操作。用户可以根据自己对数据的需求&#xff0c;使用不同的查询方式。通过不同的查询方式&#xff0c;可以获得不同的数据…

安装OpenCL和AMD驱动程序

我们将安装AMD OpenCL软件开发工具包&#xff08;SDK&#xff09;和AMD驱动程序。 userubuntu:~$ mkdir AMD-APP-SDK-v2.5-lnx64 userubuntu:~$ cd AMD-APP-SDK-v2.5-lnx64/ userubuntu:~$ wgethttp://developer.amd.com/Downloads/AMD-APP-SDK-v2.5-lnx64.tgz userubuntu:~$ t…