First cautious steps with CUDA

I recently obtained an account on our GPU cluster, so I thought I should get my head around some of the technology that drives GPU computing.
Put simply, GPUs can be used to perform calculations and since there are many processors on a GPU, this can lead to quite substantial speed increases as compared with CPUs. NVIDIA are leading the way and they provide libraries and software tools for people interested in this field.
Development is typically performed using C, C++ or Fortran. I’m not a compiled languages guy – I could just about manage a hello world in C – so I’m relying on tools built by other people, such as R gputools.
Step 1 is to download and install the required libraries, toolkit and possibly, drivers. I ran into a couple of minor problems on my machine, so I thought I’d document them here.

I run Ubuntu 10.04 on a 64-bit machine with a quad-core AMD Phenom II X4 955 Processor and a GeForce 9600 GT nVidia 512 MB card. The issues documented here relate largely to Ubuntu 10.04.

Install the CUDA toolkit
This is reasonably straightforward. Note that the latest version of the toolkit is for Ubuntu 9.04.

chmod +x
sudo ./

The installer asks where you would like to install the toolkit. I chose /opt/cuda, over the default /usr/local/cuda. You then add /opt/cuda/bin to your PATH and /opt/cuda/lib64 to LD_LIBRARY_PATH. There are several ways to achieve this; I like to edit ~/.profile:

if [ -d "/opt/cuda/bin" ] ; then

Download and unpack the SDK
This is also quite easy.

chmod +x

This simply unpacks the SDK to the default destination of ~/NVIDIA_GPU_Computing_SDK.

Fix up issues with compilation
In theory, the next step is to cd to ~/NVIDIA_GPU_Computing_SDK/C, type “make” and watch the sample applications compile. There are a couple of problems with Ubuntu 10.04.
First, the version of GCC in the distribution is 4.4.3, whereas the SDK requires, at most, 4.3.x. We need to install gcc-4.3:

sudo apt-get install gcc-4.3

Next, we have to tell the SDK which GCC to use. Open up ~/NVIDIA_GPU_Computing_SDK/C/common/ in a text editor and:

# look for this line
# NVCCFLAGS       :=
# and change it to this
NVCCFLAGS       := --compiler-bindir=/usr/bin/gcc-4.3

At this point, make still failed with errors related to libraries. Ubuntu 10.04 has an up-to-date version of the NVIDIA video driver, so there should be no need to update it. However, check whether your system has libxi-dev, libxmu-dev and libglut3-dev and install them if required.
My final make error was “unable to find -lcuda”. On my system, it lives in /usr/lib/nvidia-current/ A temporary symbolic link to /usr/lib did the trick:

sudo ln -sf /usr/lib/nvidia-current/ /usr/lib/

Finally, make works and creates 68 executables in the directory ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release. If everything went well, you can now enjoy a fast rendering of a smoke cloud, like the one in the video at the top of this post, by running smokeParticles.

Next step – figuring out how to do something useful and bioinformatics-related with this new toy.

I used several very helpful blog posts by other people to troubleshoot these issues. Unfortunately, I don’t have the links with me right now, so I’ll update this post later in the day.

Update: those useful (though a little dated) links are…

4 thoughts on “First cautious steps with CUDA

  1. Hi! Thank you for posting a guide on this often challenging topic, the only thing I had to do differently was install g++-4.3 in addition to gcc-4.3. Your topic was actually reposted on another site, so it wasn’t until the end that I noticed you’re a bioinformaticist. Quite an exciting coincidence as I am starting a bioinformatics PhD program at the University of California, San Diego in the fall and installing CUDA to learn a few new tricks as well. Thanks again!

    • Glad to be of help. My recollection is that g++ installs automatically with gcc but I may be wrong; perhaps I had it installed already. Hope you enjoy the PhD.

  2. Thanks for the great guide! I’ll second Martin’s modification of having to install g++-4.3 in addition… and I was working from a fresh Lucid install.

  3. Your well-written guide works great! I wish that nVidia would do a little better job supporting Linux distros, but I suppose that’s how it goes in the proprietary software world. I also had to install g++-4.3. build-essential has the current version of g++ as a dependency; gcc won’t automatically install it.

    Good job! I’m sure that many will find it helpful but not comment.

Comments are closed.