问题
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.
回答1:
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 and CPLUS_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
(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).
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.
回答2:
Ubuntu 15.10 with an NVIDIA NVS 5400M, Lenovo T430
sudo apt-get install nvidia-352 nvidia-352-dev nvidia-prime nvidia-modprobe
sudo ln -s /usr/include/nvidia-352/GL /usr/local/include
sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/local/lib/libOpenCL.so
Then use the header as:
#include <CL/cl.h>
And compile with:
gcc -o main main.c -lOpenCL
Notes:
- a minimal test program to try it out
- find your GPU model: https://askubuntu.com/questions/72766/how-do-i-find-out-the-model-of-my-graphics-card
- test that the driver is working: https://askubuntu.com/questions/68028/how-do-i-check-if-ubuntu-is-using-my-nvidia-graphics-card
- do not install the
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.
回答3:
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
/opt/intel/opencl-1.2-6.4.0.25/lib64/clinfo
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
https://codeload.github.com/hpc12/tools/tar.gz/master
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
回答4:
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: -lOpenCL
Explaination 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
来源:https://stackoverflow.com/questions/7542808/how-to-compile-opencl-on-ubuntu