Ubuntu 14.04 with CUDA 6.0 for GPU machine learningPosted: April 25, 2014
Canonical’s recent Ubuntu LTS came out last week, and although it has some known bugs, that hasn’t stopped you and I from early adoption! Here we will talk about how to get the most recent Nvidia drivers working with your Ubuntu. Our lab is using a Nvidia GTX Titan Black, but this walkthrough should work for any similar setups.
Mostly I’m writing this blog post because there are a few recent blog posts in other places that do not work, and will give you the dreaded black screen with blinking cursor after the GRUB menu. More importantly, Nvidia does not officially support CUDA 6.0 for Ubuntu 14.04 (as of early July 2014 as well), so we need to be careful about which linux kernel and compilation toolchain we use.
Let’s get started!
First you should figure out what the most recent drivers are for your card. For us it was 331.X, even though default (sudo apt-get install nvidia-current) repo will install 304. Write down this recent driver for your card. Importantly, when using Theano with GPU acceleration, you MUST use nvidia 331.67 or greater drivers at this point.
First, lets get the actual CUDA toolkit. The most recent version as of this writing is here:
Put that in your home directory or downloads for the time being.
Next download the NVIDIA drivers. I do NOT recommend 334.X or 337.X drivers at this point! At the same time, the default nvidia-331 drivers in a dpkg are only 331.34 which is not sufficient for CUDA 6.0. I had success with the 331.79 drivers…download them here for 64 bit linux:
You should already have basic compilation functionality, but just to make sure:
sudo apt-get install build-essential
Next update your headers to the most recent default supported kernel headers (3.13 as of this writing):
sudo apt-get install linux-generic
Next, we want to stop the current graphics session and remove the current GPU drivers on your machine. But we don’t want to do that in the current X window, or else you won’t be able to see anything! So first thing let’s switch to another command line terminal by pressing:
CTRL + ALT + F2
You will need to log in again with your username. After that, let’s stop the graphical session on X-window,
sudo service lightdm stop
Ok, now lets uninstall the current video drivers, NOTE that there are two dashes for –purge:
sudo apt-get remove –purge nvidia-*
Verify these are gone by looking at:
dpkg -l | grep nvidia
Now that those are gone, let’s reboot the system:
Do not start in normal boot, instead we want to go to recovery. The recovery menu will have a few option, one of them is “network.” Select that so that your /root gets remounted with write capabilities and you have internet. You’ll need it for the next installs.
That next install is of course your drivers itself. Go to the directory you downloaded the 331.79 driver and make the .run file executable:
sudo chmod +x NVIDIA-Linux-x86_64-331.79.run
Now install it with:
You’ll accept the EULA, and then press “yes” for everything else!
Notice we installed drivers version 331.79. You need to install this for the CUDA 6.0 installation to work with some packages like Theano for machine learning. If not installing for CUDA computing, maybe just try the most recent driver for your particular setup, since the default install may not work for your card (current default from canonical is 304).
Finally, there is a known bug with some of the nvidia installs related to the Xorg file. No worries, simply run:
You may not have an existing config file after that purge, so this last command will make one for you. Now simply reboot and enjoy your new drivers!
At this point, you should have the correct linux headers, nvidia drivers (and associated packages like nvidia-settings and nvidia-uvm), and be ready for some CUDA. Now since CUDA 6.0 is not officially supported for Ubuntu 14.04, and because CUDA is notorius for not liking newer versions of g++ and gcc, we’ve gotta override some things.
First navigate to your directory with the CUDA6.0 toolkit, probably ~/Downloads by default. Next make the .run file executable with:
sudo chmod +x cuda_6.0.37_linux_64.run
There will be a massive EULA (license agreement), just press ctrl-c and accept it. Next it will say your configuration is not supported…that’s ok, just continue with “yes.”
Next it will ask you if you want the bundled NVIDIA drivers. Do NOT install these, say “no” or else you will be dealing with hanging packages all day long and will probably lose Xserver functionality.
For everything else, say “yes” including the toolkit and the samples.
At the end of the installation, it should say you need to add a few lines to your .bashrc file. Put these lines are the bottom of your bashrc file!
Reboot just to make sure, and go the sample directory and:
to compile all the sample files. This will take awhile!
At this point, you should have CUDA 6.0 installed and working on your fresh Ubuntu 14.04! Congrats!