Install the required build tools
CUDA 4.0 does not support gcc 4.5+, I seemed to already have gcc 4.6 installed on my instance. There is no problem with having multiple versions of gcc installed side-by-side, we just have to install the 4.4 versions.
$ sudo apt-get install build-essential gcc-4.4 g++-4.4
Download the SDKs
Download the CUDA Toolkit for Ubuntu (the 10.10 version) and the GPU Computing SDK from here http://developer.nvidia.com/cuda-toolkit-40
These weigh in at around 210Mb and 140Mb respectively.
Install the CUDA Toolkit:
The CUDA Toolkit needs to be installed as root.
$ chmod 755 cudatoolkit_4.0.17_linux_64_ubuntu10.10.run
$ sudo ./cudatoolkit_4.0.17_linux_64_ubuntu10.10.run
Once you have completed installing this, add the CUDA bin location to your path - I did this in my .bashrc .
And now you need to add the CUDA libs to your library search path, I already had the nvidia_settings.conf file here, though you can add any file with a .conf extension. The lines added are in bold.
$ cat /etc/ld.so.conf.d/nvidia_settings.conf
Now run ldconfig to pick up the changes.
$ sudo ldconfig
Install the GPU SDK
Much like the CUDA Toolkit, though this does not need to be installed by root, it defaults to ~/NVIDIA_GPU_Computing_SDK .
$ chmod 755 gpucomputingsdk_4.1.21_linux.run
Link the 4.4 compilers
If you have multiple gcc versions installed, we need to make sure that nvcc (the CUDA compiler) picks up the 4.4 version. This can be done through flags for nvcc, however we need a link for it called gcc and g++.
Create a new directory in your home, called gcc-4.4 and create a link in here to the 4.4 version of gcc and g++.
$ mkdir gcc-4.4
$ cd gcc-4.4
$ ln -s /usr/bin/g++-4.4 g++
$ ln -s /usr/bin/gcc-4.4 gcc
Set the compiler flag in the provided samples
In order to build the supplied samples we now need to modify the supplied MakeFile.
$ cd ~/NVIDIA_GPU_Computing_SDK/C/common
$ vim common.mk
Find a line that looks like:
And change it to look like:
NVCCFLAGS := -ccbin ~/gcc-4.4/
This flag tells nvcc where to find the gcc and g++ compilers.
Make the sample - deviceQuery
We will build the deviceQuery sample, this sample prints output of our CUDA device.
$ cd ~/NVIDIA_GPU_Computing_SDK/C/src/deviceQuery
$ cd ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release
You should now see the output of the deviceQuery sample.
You will need to use the -ccbin flag if you wish to use nvcc from the commandline, though this is quite easy:
$ nvcc -ccbin ~/gcc-4.4 my_app.cu