Configuring Environment for OpenCL on Ubuntu with Optimus


First of All, My machine is as follows:

Dell Inspiron notebook N5110 Core i5 with Nvidia GT 525M with optimus technology, This optimus technology is simply the device have two graphics cards, one Intel and the other is the Nvidia one. 

This is used to save laptop's battery by disabling the Nvidia card that is relying on GPUs when low graphics processing is needed and doing that on the intel one, and when high performance is needed the work is done on the Nvidia GPUs are redirected to the intel one after being done.

Basically, to be able to use this technology on Ubuntu machines you will have to install Bumblebee, That project gives you the ability to run whatever application on the Nvidia GPUs, It disables the card by default to save battery and enables it when you need it.

To run an application with Nvidia GPUs just call optirun before it! To test it after installation try

 optirun glxgears 

It should run a window with some gears and will output some information on the terminal that are different from running glxgears alone


glxgears running on intel c glxgears running on intel card


NVidia glxgears running on Nvidia GPUs


To install Bumblebee, you will add a repository for it that will install some Nvidia drivers and packages, I think those will have the required packages for OpenCL as well

So to write OpenCL programs you will find the nvidia-cuda-toolkit in the package manager, just install it and it will install some dependencies, install another package called ocl-icd-opencl-dev -not sure if it is required or not-, and install OpenCL-headers package as you go..


you will need to make another step that is icd registration, that is simply copying a file "nvidia.icd" from /usr/share/nvidia-current to /etc/OpenCL/vendors/

Open that nvidia.icd file and check the name of the ".so" file that is there, for me that was a problem that it was "" and that file wasn't anywhere in my machine, but there was "/usr/lib/nvidia-current/"

So I changed the name in the icd file to be "" and made a symbolic link in "/usr/lib/nvidia-current/" to reference ""


 sudo ln -s 


Before doing that when I compile and run an OpenCL application, when the clGetPlatformIDs is called in the code it will return with the error code -1001, that is CL_PLATFORM_NOT_FOUND_KHR

Last but not least..

When you run the opencl application after all of that it will crash with no specific reason! but the reason is the executable doesn't see the nvidia card as it is disabled thanks to Bumblebee, so you will need to change how you run the executable to call optirun before the executable name, either in eclipse or through terminal!

The rest to do is normal C++ fuss, add headers, add their include directories, get some linking errors for undefined references, search for under /etc/share/nvidia-common/ and don't forget when adding it to eclipse to just write the additional library name as OpenCL only not, the compiler will write the rest :D 

after all,


Happy Coding!