如何在 Ubuntu 上编译 OpenCL? [英] How to compile OpenCL on Ubuntu?

查看:48
本文介绍了如何在 Ubuntu 上编译 OpenCL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:需要什么头文件和驱动程序,我可以从哪里获得它们以使用 gcc/g++ 在 ubuntu 上编译开放式 CL?

Question: What is needed headers and drivers are needed and where would I get them for compiling open CL on ubuntu using gcc/g++?

信息:一段时间以来,我一直在试图弄清楚如何在我的桌面和上网本上安装 open CL.有几个教程我已经尝试过,但似乎都不起作用.此外,它们都只是一步一步地给出,而没有真正解释为什么要这样做,或者更糟糕的是,它们是特定于特定 IDE 的,因此您必须学习 IDE 才能做任何事情.

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.

所以我的台式机中有一个 NVIDA GX465,而我的上网本中有集成显卡.我的首要任务当然是我的台式机,上网本只是为了方便开发(两者都运行 ubuntu 11.04 并且一出来就会运行 11.10).有人可以为我说明获取它到底需要什么,以便我可以实际编译代码并运行它.如果您还可以解释每件作品的作用,以便我了解它的重要性.

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.

推荐答案

要在 Linux 下编译和运行 OpenCL 代码,您需要四件事:

To compile and run OpenCL code under Linux, you'll need four things:

1) 支持 OpenCL 的 NVIDIA 驱动程序.Ubuntu 自带的驱动有点旧的,但它们应该仍然可以正常工作.除非您明确需要当前驱动程序,您应该坚持使用 Ubuntu 打包的驱动程序.需要明确的是,这些是通过受限驱动​​程序管理器安装的相同驱动程序.OpenCL 库与驱动程序一起提供,因此只需运行 OpenCL 程序驱动程序就足够了.

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) CUDA 工具包.这包括编译 OpenCL 代码所需的头文件.将此安装到默认位置.

2) The CUDA toolkit. This includes the headers necessary to compile OpenCL code. Install this to the default location.

3) GPU 计算 SDK(可选).这包括各种 NVIDIA 特定的支持工具,以及 OpenCL 代码示例.

3) The GPU Computing SDK (optional). This includes various NVIDIA specific support tools, as well as OpenCL code samples.

所有这三个项目都可以在 http://developer.nvidia.com/cuda 上找到-工具包-40.

All three of these items may be found at 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 一个你的桌面上.

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.

安装这些后,您需要执行更多步骤才能在 NVIDIA SDK 之外编译和运行 OpenCL.

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) 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_PATHCPLUS_INCLUDE_PATH 环境变量,但这只会持续当前会话.

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 and CPLUS_INCLUDE_PATH environment variables, but this would last for only currest session.

2) 确保 OpenCL 库 (libOpenCL.so) 存在于/usr/lib 中.这应该由驱动程序设置到位,因此您不必执行任何操作.

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.

您已准备好编写代码.确保在任何 C(++) 程序中包含 CL/cl.h(或 CL/cl.hpp,如果您想使用 C++ 版本的 API)这使得 OpenCL API 调用.编译时,请确保链接到 OpenCL 库(向 gcc 传递 -lOpenCL 标志).

You're ready to write code. Make sure to include CL/cl.h (or CL/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).

就您的上网本而言,集成显卡通常不支持 OpenCL.理论上,AMD的APP加速支持运行OpenCL在 CPU 上,但不清楚它是否真的有效.

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 上编译 OpenCL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆