Sunday, 4 November 2012

Installing CUDA 5 on Kubuntu

Introduction

So today I decided to install the CUDA 5 toolkit on my linux machine so that I can test my OpenCL applications on it. This turned out to be much more of a pain than I had originally thought as there is no definitive guide on how to install CUDA under linux and also the installer is quite finicky and really needs a rethink. So I'm posting some tips on how to install the toolkit so that other people don't make the same mistakes I did. Just so you guys know the linux version that I use is Kubuntu 12.10. The main issue with installing the toolkit is that the driver they package with it requires you to have gcc version 4.7 but the toolkit installation requires that you have version 4.4, I'm sure you can all see why this would be an issue. Before reading this guide I advise watching these videos:


So the first piece of advice I have for you guys is to install the driver FIRST and then the toolkit/samples after.

DISCLAIMER: This guide is offered without any guarantees, I am not responsible if you end up bricking your install. You have been warned!

1. Installing the Driver

First install the following libraries & Tools:
sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev

Next we will blacklist some modules(drivers), in terminal enter:
sudo kate /etc/modprobe.d/blacklist.conf

Add the following to the end of the file(one per line like so):
blacklist amd76x_edac
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv

Save the file and close the editor.
Now we want to get rid of any nvidia residuals, in terminal:
sudo apt-get remove --purge nvidia*

Next you need to restart your machine (sudo reboot). At this point, if you log back it to your machine you may find that the window manager isn't working correctly (window borders are missing etc.). Before worrying about that I advise installing the driver portion of the toolkit

0) Press Ctrl+Alt+F1 at login screen(you don't have to login, we'll have to restart later anyway), then log in.
1) sudo service lightdm stop
2) cd Downloads
3) chmod +x <cuda>.run (your toolkit filename)
4) sudo ./<cuda>.run

When asked if you wish to install the driver enter y, but do NOT install the toolkit or samples. After the installation execute “sudo service lightdm start” to restart the x server. Log in to the machine, if your window manager is still screwed I solved this by running “sudo apt-get install kubuntu-desktop”. If you are running another version of linux this command will differ from mine.

Round about here you've installed the driver and (hopefully) your system is running fine. Now for the easy bit, installing the toolkit and samples.

2. Making GCC 4.4 the default version

In this section we are going to use update-alternatives to make gcc-4.4 the default version on your system. In the terminal execute the following commands

sudo apt-get install gcc-4.4
sudo update-alternatives --remove-all gcc
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
sudo update-alternatives --config gcc

Choose gcc-4.4

gcc --version

You should have gotten some output saying your version number is 4.4.x

3. Installing the Toolkit/Samples

Now you are ready to install the toolkit. All you need to do is navigate to your downloads folder(from the terminal of course) and run “sudo ./<cuda>.run” the same as before but this time when it asks if you want to install the driver select no and install the toolkit and samples instead. This installation worked for me first time but I have heard of some people getting error messages about missing glut libraries (and possibly others), if this happens you will need to find out where the glut library is on your computer and make a symbolic link to /usr/lib using ln (the link tool). Anywhoooo... assuming your install was a success you have very little else to do apart from set up your environment variables and test the install.

Add Environmental variables:
export PATH=/usr/local/cuda/bin:$PATH

#for 64-bit machines:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH

#for 32-bit machines:
export LD_LIBRARY_PATH=/usr/local/cuda/lib:$LD_LIBRARY_PATH

Now we want to test did the toolkit install properly:
nvcc --version

If you get some output telling you the version number of nvcc then congrats! You are now ready to develop for CUDA and OpenCL!!!

No comments:

Post a Comment