My goal was to be able to run software on the dedicated Nvidia GPU in my hybrid graphics laptop. I didn't want to run the entire X server on my Nvidia, as this causes tearing: the displays are connected to the Intel graphics and the Nvidia card has no way to synchronize blanks with them.
Additionally, running all of X on the Nvidia meant that I would have to choose either battery life or performance, and restart X and all my applications when I changed my mind.
The Bumblebee Project, though not very active lately, provides a convenient way to
Currently, there are some limitations with regards to OpenCL software:
Ubuntu comes with a tool called GPU manager. It handles turning of any dedicated graphics hardware which isn't refered to from xorg.conf. This increases the battery life of a laptop by a lot, but since March 2017 I've been welcomed by a complete system lock-up (black screen syndrome) when the X server is started while the Nvidia graphics are disabled (referred to as power saving profile by nvidia-settings).
To prevent this from happening, I advise you to disable GPU manager before installing and configuring anything else. GPU manager functionality conflicts with Bumblebee anyway, since they perform similar tasks.
To disable GPU manager, run the following commands as root:
systemctl stop gpu-manager.service
systemctl disable gpu-manager.service
systemctl mask gpu-manager.service
If you're graphics card doesn't work well with the default open source nouveau driver that comes with Ubuntu (at the time of writing, this means Maxwell and Pascal cards), you should install the proprietary driver using Ubuntu's "additional drivers" settings.
These drivers are the only option if you want OpenCL or CUDA to work, as far as I can tell.
During the rest of this document, I will assume you're using the proprietary drivers, though you can probably figure out how to use the nouveau drivers without too much trouble.
The default Ubuntu repositories contain an (older) version of Bumblebee. This version worked fine with my GTX 1060 and the default kernel and nvidia's 378 drivers. If you're having trouble, you could try out some newer versions from the Official Bumblebee PPA.
apt install bumblebee