To write code for CUDA devices you need to set up your system properly. The following explanation is taken from
Life of a Programmer Geek. First of all make sure you have a CUDA enabled graphics device,
Wikipedia has a list of supported devices.
Install the build tools we need
Open a console window and type the following:
sudo apt-get install build-essential libglut3-dev
Install the NVIDIA driversGo to the
CUDA ZONE download page and download the CUDA driver. (The Ubuntu 8.04 will work for Ubuntu 9.04 Jaunty).
Press CTRL+ALT+F1 to go to a terminal, log in with your username and password.
Navigate to the folder that you placed the driver file in and type the following:
chmod +x NVIDIA-Linux-x86_64-180.22-pkg2.run
This will first make the driver installer runnable. We then need to stop Xwindows (remember to save any open files). (if you are using KDE use kdm instead of gdm (which is for gnome)):
sudo /etc/init.d/gdm stop
Next we run the driver installation (Usually selecting yes to all questions is ok):
sudo ./NVIDIA-Linux-x86_64-180.22-pkg2.run
Finally we restart the Xwindows session.
sudo /etc/init.d/gdm start
A new error for Ubuntu Jaunty is that upon reboot you might get a message similar to:
(EE)Failed to load module "type1" (module does not exist,0)
(EE)Failed to load module "freetype" (module does not exist,0)
(EE) NVIDIA(0) Failed to load the NVIDIA Kernel Module
(EE) NVIDIA ***Aborting***
(EE) Screen(s) found, but none have a usable configuration.
To fix this problem edit the file
/etc/modprobe.d/lrm-video
and comment out the line
install nvidia /sbin/lrm-video nvidia $CMDLINE_OPTS
by putting a # in front of it.
Solution found from:
http://ubuntuforums.org/showthread.php?t=950777Install the CUDA ToolkitGo to the CUDA ZONE download page again and download the CUDA Toolkit. Open a console window and navigate to the directory containing the file, type the following:
chmod +x cudatoolkit_2.1_linux64_rhel5.2.run
sudo ./cudatoolkit_2.1_linux64_rhel5.2.run
Use the default options suggested by the installer (press enter).
Note: The following steps need to be taken by all usersAdd environment variablesThis is very important step.
Open a console window to your home directory and edit the file
.bashrc
, this is the settings file for your console window. Add the following lines to the bottom of the file:
PATH=$PATH:/usr/local/cuda/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib
export PATH
export LD_LIBRARY_PATH
These settings will not take effect before you open a new window so remember to do that.
Install the CUDA SDKdownload the CUDA SDK from the CUDA ZONE download page. As with the Toolkit, open a console window, navigate to the directory with the files and type the following:
chmod +x cuda-sdk-linux-2.10.1215.2015-3233425.run
./cuda-sdk-linux-2.10.1215.2015-3233425.run
Accept the default options. The installer will create a folder called NVIDIA_CUDA_SDK in your home directory.
Compile and run an exampleOpen a console window, navigate to the NVIDIA_CUDA_SDK folder in your home directory, type:
make
./bin/linux/release/fluidsGL
This should open a window with a fluid dynamics simulation.
Writing code for CUDA devicesWhen writing code for CUDA GPUs its is useful to begin from the examples included in the SDK, the source code can be found in
~/NVIDIA_CUDA_SDK/projects/
(the directory in your home directory). Copy one of the directories and start editing the files in it. To compile the program type
make
.
If you want to put the files in a different directory or rename or add files to your project, you need to edit the
Makefile
file in your project directory and possibly also the
common.mk
file located in
~/NVIDIA_CUDA_SDK/common/
folder.