Pages

2/25/2013

Install CUDA on Ubuntu

This is another short-note from my struggle in installing Nvidia's CUDA. 
My main purpose was to run Pyrit on graphic card using CUDA, but installing CUDA just happened to be uneasy task.

Brief explanation of the steps in installing CUDA is,
1. install pre-requisite packages
2. download CUDA.run
3. symlink libglut.so
4. symlink gcc-4.6
5. start CUDA.run
6. post-installation

1. Install the pre-requisites
It needs: freeglut3, freeglut3-dev, python-dev, build-essential, gcc-4.6 
put them all together: 

sudo apt-get install freeglut3 freeglut3-dev python-dev build-essential gcc-4.6

remark: I don't know why it really need gcc-4.6. In my machine, gcc-4.7.2 was already installed, but it gave an error, "unsupported gcc 4.7.2", while compiling CUDA.

2. download CUDA toolkit
Download the install file from https://developer.nvidia.com/cuda-downloads
I chose Ubuntu 11.10 x64, and the file name is cuda_5.0.35_linux_64_ubuntu11.10-1.run

remark: although it's for 11.10, but it works as well on 12.10

3. create symbolic link for libglut.so
After installing freeglut3 package, the library, named "libglut.so.3", has been installed in /usr/lib/x86_64-linux-gnu/libglut.so.3. However, the CUDA installation file only looks in /usr/lib, so it will never found the library. I needed to make a symbolic link for it there:

sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so.3 /usr/lib/libglut.so

4. create symbolic link for gcc-4.6
As mentioned above, I don't understand why it only needs gcc-4.6. So, I changed it anyway.
In /usr/bin, there is a link for gcc --> gcc-4.7 already. If I want to use gcc-4.6 for that instant, I can change it to point to gcc-4.6 instead.

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.6 gcc

remark: to undo this, execute these two lines again, but change from 4.6 to 4.7

5. start CUDA.run

chmod +x cuda_5.0.35_linux_64_ubuntu11.10-1.run
sudo ./cuda_5.0.35_linux_64_ubuntu11.10-1.run

It will display a license agreement document. You can press 'q' to quit the screen after read it.
It then asks whether you accept this agreement or not, type "agree" if you agree.
After that it'll ask you 4 questions:
 - install a new proprietary version of nvidia driver?
 - install CUDA toolkit?
 - where to install it?
 - install CUDA samples?

I input: n, y, (enter), n   << means no, yes, default value, no
Installation will run. Wait for it to finish.

6. Post-installation
It is now installed in the location given in step5, (default is at /usr/local/cuda-5.0)
What to do next is:

6.1 Link gcc for CUDA 
I'm not sure that it is neccessary, but I saw a post from http://gunnicom.wordpress.com/2012/09/23/blenderto-render-with-cycles-and-cuda-on-nvidia-gpu-in-ubuntu-12-10-2/ that made me do the same :)

sudo ln -s /usr/bin/gcc-4.6 /usr/local/cuda-5.0/bin/gcc

remark: so gcc at /usr/bin is now free from cuda, you can change it back

6.2 set path for the binary files
There are many binary file inside /usr/local/cuda-5.0/bin, you can add PATH environment to point to that location.

echo "export PATH=$PATH:/usr/local/cuda-5.0/bin" >> ~/.bash.rc

6.3 set path for the library files
There are 2 directories inside CUDA - lib and lib64. You can add LD_PATH to point to these locations too.

echo "export LD_PATH=$LD_PATH:/usr/local/cuda-5.0/lib64:/usr/local/cuda-5.0/lib" >> ~/.bash.rc



More Readings:

No comments:

Post a Comment