What is OpenCL?

opencl logoOpenCL means Open Computing Language and it is an standard for parallel programming of heterogeneous systems. OpenCL is supported by the main graphic card manufacturers such as NVIDIA or AMD so the code developed will be compatible across the platforms, which doesn't happen with CUDA. OpenCL is not only an API, not, it also includes OpenCL C language that allow us to perform several operations at the same time. For example, vector addition with four components each (x, y, z, w).



Why I do this? Because...

  • ... I love computer architecture and supercomputers
  • ... my master's thesis wraps OpenCL and I think that heterogeneous computing is very interesting and powerful
  • ... it will help me to improve my code and documentation


Setting-up OpenCL

Verify if you have a CUDA-Capable System

lspci | grep -i nVidia


Is your device in this list?


Do you have an x86-based distribution of Linux? Check it

uname -a
  • i386 is a 32-bit system
  • x86_64 is a 64-bit system


Ensure you have installed the gcc compiler

gcc –version


Download and install NVIDIA driver and follow NVIDIA installing instructions. Also, you can download and install with apt

sudo apt-get update
sudo apt-get install nvidia-319


To check if it is installed type in


You will see something like this:



Now, you gonna download the cuda tookit. Then, run cuda_x.x.x_linux_x.run and don't install the drivers again. Please, look at installation path: /usr/local/cuda-x.x by default. Also, you can install CUDA drivers with:

sudo apt-get install nvidia-cuda-tookit


Export enviroment variables:

export PATH=/usr/local/cuda-5.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib64:$LD_LIBRARY_PATH


Check if you can execute CUDA

cd ~/NVIDIA_CUDA-5.5_Samples/NVIDIA_CUDA-5.5_Samples/1_Utilities/deviceQuery


You will see something similar to this:



Perfect, CUDA works. Finally, download GPU Computing SDK for your platform. After that, run sh gpucomputingsdk_4.x.x. Now you have a folder named “NVIDIA_GPU_Computing_SDK” in your home folder. Inside there is a “Documentation.html” file, this file contains useful information and links about OpenCL. Well, OpenCL folder has a “Samples.html” where resides all information about samples that we have. src folder has all OpenCL code samples of NVIDIA. In OpenCL folder type in:


A new binary has been created in OpenCL/bin/linux/release/oclDeviceQuery, run it.

You must see something similar to this:





We are ready to run our first serious OpenCL example. Let's go to “src/oclVectorAdd”. Do "make" (if you have any problem type make again). It will generate a executable file into OpenCL/bin/release folder. Run it. Now you can do the same with the others examples.


In conclusion, OpenCL can be used to compute anything executed in the processor although we gonna have better results whether the problem is highly parallel. The last and pretty example is how OpenCL computes sine wave pattern and then shows it into a window using OpenGL to rendering.


sine wave


The popular vision software OpenCV already includes a OpenCL module to accelerate OpenCV functionalities on OpenCL compatible devices. In the next article I'll cover the benchmarking of the PI calculation between CPU and GPU in a quite simple example.