CUDA Tutorial 01 - Linux |
This tutorial shows you which software to install on your PC in order to start developing CUDA software. The installation process has been tested with Ubuntu 12.04 64 bit desktop edition and Linux Mint 16 (Petra). All necessary packages are installed on Prometheus, so if you plan on working that computer you may skip this tutorial, log on to Prometheus and get going with programming.
Not thirty seconds after I finished writing this tutorial, NVIDIA sent an email announcing the release candidate (RC) of CUDA 6.0. As I found out that CUDA 6.0 brought a significant improvement for beginners over CUDA 5.5, I rewrote the installation process to include the updated version, which is also simpler than installation of CUDA 5.5. The old installation process can be found below under section 2. Try the procedure described in this section first and go to section 2 if you encounter any problems.
Go to NVIDIAs driver webpage (http://www.geforce.com/drivers) and get the newest available driver .run-file (let’s assume you downloaded 331.41, otherwise adjust the version number where appropriate). At the time of this writing, there is no official release of CUDA 6.0 available, though NVIDIA has released a release candidate (RC) of the upcoming iteration. Most probably by the time you read this, there will be a stable official release, until then you need to get the package by registering for a developer account or, more easily, by downloading the file
Now thing become interesting. A piece of advise: Depending on distribution, after this step you might not be able to start your window manager when you reboot before installing the new driver version, so print this tutorial or open with a different computer so you know what to do when all that fancy windows are gone. Do not worry, nothing is lost when something gows awry, just ask the system administrator of your choice (or me), but I do not think that this will be necessary.
Hit <CTRL> + <ALT> + <F1> to open a terminal.
Get rid of possibly installed older NVIDIA drivers:
Navigate to the downloaded files from step 1.1 and make them executable (adjust filenames where necessary):
Shutdown your window manager by typing
Substitute lightdm in the line above by your window manager. If lightdm doesn’t do the trick, try
If that also achieves nothing, ask google what window manager your distribution is running.
Install the driver:
Follow the instructions given by the installer, use default values if you are not sure what it wants from you, except when it asks to overwrite X configuration file. You want that to happen so the NVIDIA driver starts automatically, so chosse ’yes’ in that situation.
Install the CUDA toolkit via
The installer will ask you several things. Choose as follows:
(if not running Ubuntu)Install on unsupported device -> well, at least try...
Install NVIDIA Accelerated Graphics Driver.... -> no! you just installed a newer version (but be sure you really did, otherwise ugly runtime errors are sure to be experienced)
Install CUDA toolkit -> yes, of course, that’s why we are here
Enter toolkit Location -> hit enter, the default value is ok
Do you want to install a symbolic link... ->yes, why not, but I don’t think that you will need that
Install the CUDA samples -> yes, we want to play around with them
Enter CUDA samples location -> anything is fine, I chose /usr/local/cuda-6.0/samples
Now the installer will do its thing. There will be a warning due to partially unfinished installation. That is because we chose
to not install the driver coming with the CUDA package but the newer one, so ignore this warning.
You may now restart the window manager
If you encounter problems in this step, take a look at section 2.4, maybe something there might help you out.
You now have to tell your system where to find the binaries and libraries of the toolkit. To do so, open/create .bashrc file (in your home folder by typing ’gedit ~/.bashrc’) and append the following line:
Save and exit.
Then edit /etc/ld.so.conf (type ’sudo gedit /etc/ld.so.conf’) and append the following two lines:
Save and exit. Type in a terminal
Now reboot your system.
If everything went according to plan, you have now everything installed and setup to start using CUDA capabilities in your own programs. Let’s test this hypothesis.
Navigate to the folder where you installed the samples and make all that stuff, so in my case, where the samples were stored as mentioned above, this would look like this:
This will take a couple of minutes, so grab a coffe or do stuff. When that process is finished, go to the bin folder
and have some fun. Try what you want, but for our purposes here, deviceQuery is a nice choice because it will confirm that everything went fine during installation and additionaly shows some CUDA capabilities of your graphics card(s). So type
That’s it. Good luck programming nice and fast CUDA programs. If you are eager to get your first program running, go on to tutorial 02.
This is the process for the old CUDA toolkit. Please try installing a newer version first (section 1) and find solutions to possible problems during that process here.
Go to NVIDIAs driver webpage (http://www.geforce.com/drivers) and get the newest available driver .run-file (331.38 at the time of this writing). Navigate to the CUDA developer homepage (https://developer.nvidia.com/cuda-downloads) and get the newest CUDA toolkit (5.5 / Ubuntu 12.10, also a .run-file, not the deb-package).
Get them by typing
For some reason unknown to me, the CUDA toolkit needs a gcc version older than 4.7.3 to compile, so you have to adjust your system to support an older version that you probably have (let’s assume you have 4.8 for the following commands, adjust accordingly). You already installed version 4.6 in the previous step, so now install the alternative by typing
Now thing become interesting. A piece of advise: Depending on distribution, after this step you might not be able to start your window manager when you reboot before installing the new driver version, so print this tutorial or open with a different computer so you know what to do when all that fancy windows are gone. Do not worry, nothing is lost when something gows awry, just ask the system administrator of your choice (or me), but I do not think that this will be necessary.
Hit <CTRL> + <ALT> + <F1> to open a terminal.
Get rid of possibly installed older NVIDIA drivers:
Navigate to the downloaded files from step 2.1 and make them executable (adjust filenames where necessary):
Use the newer version (4.8) of gcc by typing
and choosing the appropiate value. Shutdown your window manager by typing
Substitute lightdm in the line above by your window manager. If lightdm doesn’t do the trick, try
If that also achieves nothing, ask google what window manager your distribution is running.
Now install the driver:
Follow the instructions given by the installer, use default values if you are not sure what it wants from you, except when it asks to overwrite X configuration file. You want that to happen so the NVIDIA driver starts automatically, so chosse ’yes’ in that situation.
Switch to the old version (4.6) of gcc by again typing
Install the CUDA toolkit via
The installer will ask you several things. Choose as follows:
Install NVIDIA Accelerated Graphics Driver.... -> no! you just installed a newer version
Install CUDA toolkit -> yes, of course, that’s why we are here
Enter toolkit Location -> hit enter, the default value is ok
Install the CUDA samples -> yes, we want to play around with them
Enter CUDA samples location -> anything is fine, I chose /usr/local/cuda-5.5/samples
Now the installer will do its thing. There will be a warning due to partially unfinished installation. That is because we chose
to not install the driver coming with the CUDA package but the newer one, so ignore this warning.
You now have to tell your system where to find the binaries and libraries of the toolkit. To do so, open/create .bashrc file (in your home folder by typing ’gedit ~/.bashrc’) and append the following line:
Save and exit.
Then edit /etc/ld.so.conf (type ’sudo gedit /etc/ld.so.conf’) and append the following two lines:
Save and exit. Type in a terminal
Now reboot your system (and pray or sacrifice a goat, if you think that might help).
If everything went according to plan, you have now everything installed and setup to start using CUDA capabilities in your own programs. Let’s test this hypothesis.
Navigate to the folder where you installed the samples and make all that stuff, so in my case, where the samples were stored as mentioned above, this would look like this:
This will take a couple of minutes, so grab a coffe or do stuff. When that process is finished, go to the bin folder
and have some fun. Try what you want, but for our purposes here, deviceQuery is a nice choice because it will confirm that everything went fine during installation and additionaly shows some CUDA capabilities of your graphics card(s). So type
That’s it. Good luck programming nice and fast CUDA programs. If you are eager to get your first program running, go on to tutorial 02.
This document was translated from LATEX by HEVEA.