Intel Integrated Graphics, dedicated GPU for CUDA and Ubuntu 13.10 and 14.04

Attention conservation notice: Summary to self about a hacky configuration process, probably fixed really soon anyway somewhere upstream.

The goal is to get Ubuntu 13.10 and 14.04 (Desktop version) running on the integrated Intel HD 3000 graphics chip and use the available GTX 660i as a dedicated CUDA device. Googling around brings up various guides, e.g. from RTutorial for Ubuntu 12.10 and one on AskUbuntu specifically for Ubuntu 13.10. These guides advocate downloading the newest driver and CUDA toolkit from NVIDIAs website and running the installation process manually. Doing so however broke my Xorg setup: After logging in with lightdm, the screen stays black, something is wrong with Unity. Investigating this issue (i.e. looking into /var/log/Xorg.0.log), it seems that with the current NVIDIA provided drivers (that is version 331.??) intel's libGLX.so gets overwritten and thus Unity can not start. Looking around, Juan Mauricio Matera already provided a simple fix for that. Possibly other people also stumbled over this problem, e.g. see this question on AskUbuntu. In the following a brief write up of the complete process, mixing these two guides.

Note: The preferred way of installing CUDA-toolkit via apt-get did not work for me.

BIOS

Make sure that in the BIOS the integrated graphics unit (iGP) is set as the primary device.

lspci check

After the standard installation of Ubuntu 13.10 or 14.04, check with lspci that both devices are available. Your output should look similar to this.

lspci | grep 'VGA\|NVIDIA'
00:02.0 VGA compatible controller: Intel Corporation ... Integrated Grahpics Controller ...
01:00.0 VGA compatible controller: NVIDIA Corporation ...

Preparing installation of NVIDIA drivers

The next steps are copied from the main guide. Blacklist any driver that is in conflict with NVIDIA's binary driver (e.g. nouveau): Create the file blacklist-file-drivers.conf in /etc/modprobe.d/ with

blacklist nouveau
blacklist lbm-nouveau
blacklist amd76x_edac
blacklist vga16fb
blacklist rivatv
blacklist rivafb
blacklist nvidiafb
blacklist nvidia-173
blacklist nvidia-96
blacklist nvidia-current
blacklist nvidia-173-updates
blacklist nvidia-96-updates
alias nvidia nvidia_current_updates
alias nouveau off
alias lbm-nouveau off

Get all dependencies for the toolkit fulfilled:

sudo apt-get install freeglut3 freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev gcc g++ gcc-4.6 g++-4.6 linux-headers-generic linux-source
sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so.3 /usr/lib/libglut.so

We need to install gcc-4.6 because the CUDA toolkit currently does not work with higher versions of gcc (gcc-4.8 is provided in Ubuntu 13.10 and 14.04). To provide for these alternatives we need to

sudo update-alternatives --remove-all gcc
sudo update-alternatives --config gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50

Finally, download the lastest NVIDIA driver from here and the newest toolkit from here (both as a .run file). Reboot to make the blacklist do its work.

Installation NVIDIA drivers

After rebooting, change into a text console via CTRL+ALT+F1 and stop the display manager (lightdm for a vanilla Ubuntu 13.10 and 14.04).

sudo service lightdm stop

I also made a backup of /usr/lib/xorg/modules. Then go to the directory where you downloaded the NVIDIA driver (probably Downloads), choose your latest gcc and run the driver installation. Note that the last two commands depend on your specific version of the download.

sudo update-alternatives --config gcc          #choose 4.8
sudo chmod +x NVIDIA???.run
sudo ./NVIDIA???.run

Follow the text instructions, ignore warnings. After the installation, we have to add the NVIDIA module to the Linux Kernel and your NVIDIA GPU is ready:

sudo modprobe nvidia-uvm
nvidia-smi

However, if you start lightdm again in order to log in graphically, you will get (after the greeting login screen) a black screen instead of Unity. To fix the problems with the overwritten OpenGL libraries, we reinstall these again (To see the problem first hand, change e.g. into /usr/lib/xorg/modules/extensions and compare to your previous backup).

sudo apt-get install --reinstall xserver-xorg-core  xserver-xorg-video-intel xserver-xorg-video-glamoregl libgl1-mesa-glx

After this step compare /usr/lib/xorg/modules again to your previous backup. (Note: libglamouregl.so was still missing for me, I simply copied it over from my backup). Reboot the system in order to set up the CUDA-toolkit. This can happen with the graphical UI running, so no need to stop the display manager.

Installation CUDA Toolkit

Go to your download place and after changing gcc to version 4.6 (note that this might be not necessary for later versions) we can install the cuda toolkit (version 5.5 in my case). Again, the specific name of the downloaded file depends on the version you get from NVIDIA.

sudo update-alternatives --config gcc          #choose 4.6
sudo chmod +x cuda_5.5???.run
sudo ./cuda_???.run

Do not install the NVIDIA driver that comes with the toolkit! However, install the provided samples. When this done, change back to your standard version of gcc, e.g:

sudo update-alternatives --config gcc          #choose 4.8

Set PATH and LD_LIBRARY_PATH accordingly. If you chose the standard settings during the toolkit installation this is /usr/local/cuda with CUDA 5.5:

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

Changing into the samples directory, run make. After building all sample programs, go several levels below the bin/ directory and test ./deviceQry.