问题:使用 gcc/g++ 在 ubuntu 上编译 open CL 需要什么头文件和驱动程序?在哪里可以获取它们?
信息:有一段时间我一直在摸索如何在我的桌面上安装 open CL,如果可能的话,在我的上网本上安装。我尝试过一些教程,但似乎都不起作用。此外,它们都只是一步一步地给出,而没有真正解释为什么、做什么,或者更糟糕的是,它们是特定于特定 IDE 的,因此您必须学习 IDE 才能做任何事情。
所以我的台式机上有 NVIDA GX465,上网本上有集成显卡。我的首要任务当然是我的台式机,上网本只是为了方便开发(两者都运行ubuntu 11.04,并且一旦发布就会运行11.10)。有人可以为我说明一下到底需要什么才能获得它,以便我可以实际编译代码并运行它。如果您还可以解释一下每部分的作用,以便我能够理解它的重要性。
Question: What is needed headers and drivers are needed and where would I get them for compiling open CL on ubuntu using gcc/g++?
Info: for a while now I've been stumbling around trying to figure out how to install open CL on my desktop and if possible my netbook. There are a couple tutorials out there that I've tried but none seem to work. Also, they all just give a step by step with out really explaining why for the what, or even worse they are specific to a particular IDE so you have to learn the IDE to be able to do anything.
So I have an NVIDA GX465 in my desktop and integrated graphics in my netbook. my priority is of course my desktop, the netbook is just a convenience for development purposes(both run ubuntu 11.04 and will be running 11.10 as soon as it comes out). Can some one spell out for me what exactly is needed to get it so I can actually compile code and have it run. and if you could also explain what each piece does so that I can understand it's importance.
发布评论
评论(4)
要在 Linux 下编译和运行 OpenCL 代码,您需要四样东西:
1) 支持 OpenCL 的 NVIDIA 驱动程序。 Ubuntu 打包的驱动有点
旧了,但它们应该仍然可以正常工作。除非您明确需要电流
驱动程序,您应该坚持使用 Ubuntu 附带的驱动程序。需要明确的是,这些是
通过受限驱动程序管理器安装的相同驱动程序。 OpenCL 库随驱动程序一起提供,因此只需运行 OpenCL 程序驱动程序就足够了。
2)CUDA工具包。这包括编译 OpenCL 代码所需的标头。将其安装到默认位置。
3)GPU计算SDK(可选)。其中包括各种 NVIDIA 特定支持工具以及 OpenCL 代码示例。
所有这三个项目都可以在 http://developer.nvidia.com/cuda-toolkit- 找到40。
4) OpenCL C++ 绑定(可选)。奇怪的是,它们不包含在 CUDA Toolkit 中,但如果您使用 C++,它们可以使您的代码更加可重读。您可以从 http://www.khronos.org/registry/ 下载它们cl/api/1.1/cl.hpp,然后将其放入您的桌面 /usr/local/cuda/include/CL 中。
安装这些之后,您需要执行更多步骤才能在 NVIDIA SDK 之外编译和运行 OpenCL。
1) CUDA 工具包将包含 OpenCL 标头(列于 http://www.khronos.org/ registry/cl/),可能它们位于目录 /usr/local/cuda/include/CL 中。要使这些标头在系统范围内可用,您应该将此目录链接到 /usr/include/,以便可以通过 /usr/include/CL/[headerfilename] 访问它们。您可以将 /usr/local/cuda/include 添加到您的
C_INCLUDE_PATH
和CPLUS_INCLUDE_PATH
环境变量,但是这只会持续当前的会话。2) 确保 OpenCL 库 (libOpenCL.so) 存在于 /usr/lib 中。这应该是由司机设置的,所以你不需要做任何事情。
您已经准备好编写代码了。确保在任何 C(++) 程序中包含
CL/cl.h
(如果您想使用 C++ 版本的 API,则包含CL/cl.hpp
)它进行 OpenCL API 调用。编译时,请确保链接到 OpenCL 库(向 gcc 传递-lOpenCL
标志)。就您的上网本而言,集成显卡通常不支持 OpenCL。理论上,AMD 的 APP 加速支持运行 OpenCL在CPU上,但尚不清楚它是否真的有效。
To compile and run OpenCL code under Linux, you'll need four things:
1) An NVIDIA Driver which supports OpenCL. The drivers packaged with Ubuntu are somewhat
old, but they should still work just fine. Unless you have explicit need for current
drivers, you should stick with the ones packaged with Ubuntu. To be clear, these are
the same drivers installed through the restricted drivers manager. OpenCL libaries are shipped with driver, so to just run OpenCL programs driver should be enough.
2) The CUDA toolkit. This includes the headers necessary to compile OpenCL code. Install this to the default location.
3) The GPU Computing SDK (optional). This includes various NVIDIA specific support tools, as well as OpenCL code samples.
All three of these items may be found at http://developer.nvidia.com/cuda-toolkit-40.
4) OpenCL C++ bindings (optional). Strangely, they are not included with CUDA Toolkit, but in case you use C++, they could make your code much more redable. You can download them from http://www.khronos.org/registry/cl/api/1.1/cl.hpp, and just put it in /usr/local/cuda/include/CL an you desktop.
Once these are installed, you'll need to perform a few more steps to be able to compile and run OpenCL outside of the NVIDIA SDK.
1) The CUDA toolkit will have included the OpenCL headers (Listed at http://www.khronos.org/registry/cl/), likely they are in the directory /usr/local/cuda/include/CL. To make these headers available system wide, you should link this directory into /usr/include/, such that they may be accessed as /usr/include/CL/[headerfilename]. Instead of creating a symlink, you could add /usr/local/cuda/include to your
C_INCLUDE_PATH
andCPLUS_INCLUDE_PATH
environment variables, but this would last for only currest session.2) Make sure that the OpenCL library (libOpenCL.so) is present in /usr/lib. This should have been put in place by the driver, so you shouldn't have to do anything.
You're ready to write code. Make sure to include
CL/cl.h
(orCL/cl.hpp
if you'd like to use C++ version of API) in any C(++) program which makes OpenCL API calls. When you compile, make sure to link against the OpenCL library (pass gcc the-lOpenCL
flag).As far as your netbook, integrated graphics don't generally support OpenCL. In theory, AMD's APP Acceleration supports running OpenCL on the CPU, but it's not clear that it actually works.
Ubuntu 20.04 搭配 NVIDIA Quadro M1200、Lenovo P51
自从我上次尝试以来,软件集成已经好多了,所以我会进行更新。
首先,至少对于图形,我需要调整一些 BIOS 设置,如所提到的,不确定 OpenCL 是否需要:https://askubuntu.com/questions/973605/ubuntu-17-10-boot-stuck-at-message-started-nvidia-persistence-daemon-after-ins/976578#976578
然后,我找到并安装最新的可用驱动程序:
您还可以
在“其他驱动程序”选项卡中进行搜索。
现在我可以编译并运行以下测试程序:
main.c
GitHub 上游
:
注释:
带有 NVIDIA NVS 5400M、Lenovo T430 的 Ubuntu 15.10
然后使用标头:
并编译为:
注意:
nvidia-current
软件包。它很旧了。要么apt-cache搜索nvidia
并获取最新的驱动程序,或者使用software-properties-gtk
“其他驱动程序”选项卡。我真的建议升级到 15.10 来让它工作:我以前从未成功过。
Ubuntu 20.04 with an NVIDIA Quadro M1200, Lenovo P51
The software integration got a lot better since I had last tried, so I will do an update.
First, at least for graphics, I needed to tweak some BIOS settings as mentioned at, not sure needed for OpenCL: https://askubuntu.com/questions/973605/ubuntu-17-10-boot-stuck-at-message-started-nvidia-persistence-daemon-after-ins/976578#976578
Then, I find and install the latest driver available:
You can also search under:
in the "Additional Drivers" tab.
Now I can compile and run the following test program:
main.c
GitHub upstream
with:
Notes:
Ubuntu 15.10 with an NVIDIA NVS 5400M, Lenovo T430
Then use the header as:
And compile with:
Notes:
nvidia-current
package. It is old. Eitherapt-cache search nvidia
and get the latest one, or usesoftware-properties-gtk
"Additional Drivers" tab.I really recommend upgrading to 15.10 to get this to work: I had never managed before.
在 Ubuntu 16.04 中对我有用的东西
我已经安装了 openCL:
SandyBridge CPU:仅 cpu
IvyBridge GPU
Nvidia GTX 950
安装包
的通用 ubuntu 包
用于 OpenCL基本安装
<代码>
sudo apt install ocl-icd-libopencl1
sudo apt install opencl-headers
sudo apt install clinfo
允许编译 OpenCL 代码的包(我认为是 1.2)
需要链接和编译
<代码>
sudo apt install ocl-icd-opencl-dev
适用于 Intel GT 核心
包,可在 Intel GT、IvyBridge 及更高版本上运行 openCL
sudo apt install beignet
对于 SandyBridge Intel CPU 和其他可能的 CPU
下载此文件
适用于 Ubuntu* 的英特尔® 酷睿™ 和英特尔® 至强® 处理器的 OpenCL™ 运行时 16.1.1(64 位)
在 https://software.intel.com/en-us/articles/ opencl-drivers#latest_linux_SDK_release
安装用于将 rpm 转换为 deb 的软件包
<代码>
sudo apt-get install -y rpm 外星人 libnuma1
解压下载的文件
<代码>
tar -xvf opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25.tgz
cd opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25/rpm/
将 rpm 文件转为 deb
<代码>
fakeroot 外星人 --to-deb opencl-1.2-base-6.4.0.25-1.x86_64.rpm
fakeroot Alien --to-deb opencl-1.2-intel-cpu-6.4.0.25-1.x86_64.rpm
安装 .deb 包
<代码>
sudo dpkg -i opencl-1.2-base_6.4.0.25-2_amd64.deb
sudo dpkg -i opencl-1.2-intel-cpu_6.4.0.25-2_amd64.deb
触摸本地配置文件
<代码>
sudo touch /etc/ld.so.conf.d/intelOpenCL.conf
打开文件
<代码>
sudo vim /etc/ld.so.conf.d/intelOpenCL.conf
并添加行
创建供应商目录并添加 intel.icd
<代码>
sudo mkdir -p /etc/OpenCL/vendors
sudo ln /opt/intel/opencl-1.2-6.4.0.25/etc/intel64.icd /etc/OpenCL/vendors/intel64.icd
须藤ldconfig
测试这是否有效
clinfo 应该列出您的设备
下载此文件
运行此代码以确保一切正常
<代码>
tar xzvf 工具-master.tar.gz
CD工具大师
制作
./打印设备
./cl-演示 1000 10
最后应该打印出 GOOD
对于 Nvidia
安装 nvidia 驱动程序(我使用 370),这应该包括所有运行时驱动程序
Things that worked for me in Ubuntu 16.04
I have installed openCL on:
SandyBridge CPU: cpu only
IvyBridge GPU
Nvidia GTX 950
install packets
Generic ubuntu packages for OpenCL
Basic installation
sudo apt install ocl-icd-libopencl1
sudo apt install opencl-headers
sudo apt install clinfo
Package that allows to compile OpenCL code (1.2 I think)
Needed to link and compile
sudo apt install ocl-icd-opencl-dev
For Intel GT core
Package that enables runnig openCL on Intel GT, IvyBridge and up
sudo apt install beignet
For SandyBridge Intel CPU and possible others
Download this file
OpenCL™ Runtime 16.1.1 for Intel® Core™ and Intel® Xeon® Processors for Ubuntu* (64-bit)
On https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_SDK_release
Install packages for turning rpm to deb
sudo apt-get install -y rpm alien libnuma1
Untar downloaded file
tar -xvf opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25.tgz
cd opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25/rpm/
Turn rpm files to deb
fakeroot alien --to-deb opencl-1.2-base-6.4.0.25-1.x86_64.rpm
fakeroot alien --to-deb opencl-1.2-intel-cpu-6.4.0.25-1.x86_64.rpm
Install .deb packages
sudo dpkg -i opencl-1.2-base_6.4.0.25-2_amd64.deb
sudo dpkg -i opencl-1.2-intel-cpu_6.4.0.25-2_amd64.deb
Touch local config file
sudo touch /etc/ld.so.conf.d/intelOpenCL.conf
Open the file
sudo vim /etc/ld.so.conf.d/intelOpenCL.conf
and add the line
Create a vendors dir and add intel.icd
sudo mkdir -p /etc/OpenCL/vendors
sudo ln /opt/intel/opencl-1.2-6.4.0.25/etc/intel64.icd /etc/OpenCL/vendors/intel64.icd
sudo ldconfig
test if this worked
clinfo should list your devices
Dowload this file
Run this code to make sure everything works
tar xzvf tools-master.tar.gz
cd tools-master
make
./print-devices
./cl-demo 1000 10
This should print out GOOD in the end
For Nvidia
install nvidia drivers (I used 370), this should include all the runtime dirvers
我最近在 Linux 上的干净构建中使用了类似的过程,使用 NVIDIA 卡设置 OpenCL。
我采取的步骤:
1 - 安装 NVIDIA 驱动程序。
2 - 安装 CUDA 工具包 - (按照指南中的步骤进行,有很多方法可以做到,但我使用的是 .deb 安装程序,指南可以在这里找到:http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/)
3 - 使用 apt-get 安装 OpenCL 标头。命令:
sudo apt-get install opencl-headers
使用:
CL/opencl.h
标头,我能够使用 gcc/g++ 和标志编译 C/C++ 代码: -lOpenCL步骤说明
1 - 不言自明
2 - CUDA 工具包还安装 OpenCL 库 (libOpencl.so),但不安装标头(至少在我的系统上没有)
3 -因此可以使用 apt-get 安装标头。头文件存储在 /usr/include/CL 目录中
I've recently used similar process on a clean build on linux, setting up OpenCL with an NVIDIA card.
Steps I took:
1 - install the NVIDIA driver.
2 - install the CUDA tool kit - (follwing the steps in the guide, there are many ways to do it, but I used the .deb installer, guide can be found here: http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/)
3 - using apt-get install the OpenCL headers. Command:
sudo apt-get install opencl-headers
Using the :
CL/opencl.h
header I was able to compile C/C++ code using gcc/g++ and the flag: -lOpenCLExplaination of steps
1 - Self explanatory
2 - The CUDA toolkit also installs the OpenCL library (libOpencl.so) but not the header (at least not on my system)
3 - hence the header can be installed with apt-get. The header files get stored in the /usr/include/CL directory