cs344 ยป

This is how to install and operate a development environment on Ubuntu Linux. You will need a CUDA-capable GPU card in the computer. Even an inexpensive GeForce GT610 will be able to run the programs for this class.

First, install Ubuntu 12.04 LTS. This is left as an exercise for the reader. You may want to run the server version of Ubuntu so that the video card isn't used for displaying anything. CUDA programs can interfere with the graphics display.

To install the Nvidia drivers, you must not be running the GUI. The server version of Ubuntu doesn't run the GUI by default, so you're OK. But if you are running the desktop version, you'll need to boot into text-only mode for these installation steps.

Once you have your Ubuntu system up, log in to a shell. The rest of these instructions assume familiarity with using a command line.


Update repositories and do updates.

sudo apt-get update
sudo apt-get upgrade

Remove the default display driver.

sudo apt-get --purge remove nvidia*

Blacklist other drivers. Use an editor (vi, nano, etc.) to create a file called /etc/modprobe.d/blacklist-nouveau.conf and add the following lines:

blacklist nvidiafb
blacklist nouveau
blacklist rivafb
blacklist rivatv
blacklist vga16fb
options nouveau modeset=0

Update the kernel image.

sudo update-initramfs -u


sudo reboot

Once the system is back up, go back to a command line. Install developer tools.

sudo apt-get install build-essential libopencv-dev linux-headers-`uname -r`

Get the CUDA SDK.

For 32-bit:

wget http://developer.download.nvidia.com/compute/cuda/5_0/rel-update-1/installers/cuda_5.0.35_linux_32_ubuntu11.10-1.run

For 64-bit:

wget http://developer.download.nvidia.com/compute/cuda/5_0/rel-update-1/installers/cuda_5.0.35_linux_64_ubuntu11.10-1.run

Run the installer.

sudo sh cuda_5.0.35_linux_64_ubuntu11.10-1.run

You'll need to accept the license agreement and decide if you want to install the display drivers (yes), toolkit (yes), samples (optional).

If you're running a GUI, you may need to reboot again at this point so the Nvidia drivers load. But if you are command-line only (no GUI), you're OK to continue.

For command line use, you'll want to force the drivers into persistence mode so they don't have to be loaded every time you run a CUDA program. And you can put them into EXCLUSIVE_PROCESS mode so only one CUDA program can run at a time. You may also want to add these lines to the /etc/rc.local file so they are run every time your system boots. (These are probably not necessary at all if you are using a GUI.)

sudo nvidia-smi -pm ENABLED
sudo nvidia-smi -c EXCLUSIVE_PROCESS

So that your shell can find the nvcc compiler, add the following lines to your $HOME/.bashrc

export CUDA_HOME=/usr/local/cuda-5.0
export PATH=${PATH}:${CUDA_HOME}/bin

Note: if you are running 32-bit Linux, use this LD_LIBRARY_PATH setting instead of the one above:


Log out and log in again. (Or just run them on the command line.)

Finally, install Git.

sudo apt-get install git

Now we're ready to start developing!

Getting ready for Problem Set 1

Fetch the provided source code.

git clone https://github.com/udacity/cs344

This will create a directory called cs344. There will be an HW1/student directory where the files for Problem Set 1 reside.

cd cs344/HW1/student

Test that you can build the executable.


There might be some warnings, but you should end up with an executable called hw. It doesn't do anything yet.

Edit your program

Use your favorite editor to edit the student_func.cu file. This is where the kernel and kernel launch code go, and is the same as the file shown in the website IDE.

Run your program

Run your program with the input and output images as arguments:

./hw cinque_terre_small.jpg cinque_terre_small_bw.jpg

View the image to see what it looks like!

Updating the source code

When a new problem set is released or problems are found with the provided source code, you'll need to pull in the changes from the Git repository. This is easily done with:

cd cs344
git pull

It will merge in any changes from the repository. The files you've edited should be intact.

Modifications for EC2

The instructions given above need a few tweaks for AWS EC2 instances.

Start from an instance of "Ubuntu Server 12.04.1 LTS for Cluster Instances," which differs from the "Ubuntu Server 12.04.1 LTS" AMI in the Quick Start menu. You will also need to specify "cg1.4xlarge" as the instance type.

Prior to installing the CUDA toolkit, add the following commands:

sudo apt-get install freeglut3 freeglut3-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/libglut.so /usr/lib/libglut.so

The rest of the instructions work without modification. To load the drivers for the first time, you will need to execute the following command:

sudo nvidia-smi

After the next reboot, the suggested configuration file mods should take care of loading the drivers for you.