CUDA Getting Started Linux
CUDA Getting Started Linux
FOR LINUX
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | ii
LIST OF FIGURES
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | iii
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | iv
Chapter 1.
INTRODUCTION
1.1. System Requirements
To use CUDA on your system, you will need the following installed:
‣ CUDA-capable GPU
‣ A supported version of Linux with a gcc compiler and toolchain
‣ NVIDIA CUDA Toolkit (available at http://developer.nvidia.com/cuda-downloads)
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 1
Introduction
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 2
Chapter 2.
INSTALLING CUDA DEVELOPMENT TOOLS
The setup of CUDA development tools on a system running the appropriate version of
Linux consists of a few simple steps:
‣ Verify the system has a CUDA-capable GPU.
‣ Verify the system is running a supported version of Linux.
‣ Verify the system has gcc installed.
‣ Download the NVIDIA CUDA Toolkit.
‣ Install the NVIDIA CUDA Toolkit.
‣ Test that the installed software runs correctly and communicates with the hardware.
You can override the install-time prerequisite checks by running the installer with
the -override flag. Remember that the prerequisites will still be required to use the
NVIDIA CUDA Toolkit.
If you do not see any settings, update the PCI hardware database that Linux maintains
by entering update-pciids (generally found in /sbin) at the command line and rerun
the previous lspci command.
If your graphics card is from NVIDIA and it is listed in http://developer.nvidia.com/
cuda-gpus, your GPU is CUDA-capable.
The Release Notes for the CUDA Toolkit also contain a list of supported products.
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 3
Installing CUDA Development Tools
You should see output similar to the following, modified for your particular system:
i386 Red Hat Enterprise Linux WS release 4 (Nahant Update 6)
The i386 line indicates you are running on a 32-bit system. On 64-bit systems running
in 64-bit mode, this line will generally read: x86_64. The second line gives the version
number of the operating system.
If an error message displays, you need to install the development tools from your Linux
distribution or obtain a version of gcc and its accompanying toolchain from the Web.
For ARMv7 cross development, a suitable cross compiler is required. For example,
performing the following on Ubuntu 12.04:
sudo apt-get install g++-4.6-arm-linux-gnueabihf
will install the gcc 4.6 cross compiler on your system which will be used by nvcc.
Please refer to th NVCC manual on how to use nvcc to cross compile to the ARMv7
architecture
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 4
Installing CUDA Development Tools
Distribution-specific packages and repositories are not provided for Redhat 5 and
Ubuntu 10.04. For those two Linux distributions, the stand-alone installer must be
used.
Standalone installers are not provided for the ARMv7 release. For both native ARMv7
as well as cross developent, the toolkit must be installed using the distribution-
specific installer.
Prerequisites
‣ The package manager installations (RPM/DEB packages) and the stand-alone
installer installations (.run file) of the NVIDIA driver are incompatible. Before using
the distribution-specific packages, uninstall the NVIDIA driver with the following
command:
/usr/bin/nvidia-uninstall
‣ On Redhat, the NVIDIA driver RPM packages depend on other external packages,
such as DKMS and libvdpau. Those packages are only available on third-party
repositories, such as EPEL. Any such third-party repositories must be added to the
package manager repository database before installing the NVIDIA driver RPM
packages, or missing dependencies will prevent the installation from proceeding.
‣ For x86 to ARMv7 cross development, the host system must be an Ubuntu 12.04
system.
‣ On Ubuntu 12.04, to enable armhf as a foreign architecture, the following commands
must be executed first:
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 5
Installing CUDA Development Tools
Installation Instructions
‣ Redhat & Fedora
Environment Setup
The PATH variable needs to include /usr/local/cuda-5.5/bin
The LD_LIBRARY_PATH variable needs to contain /usr/local/cuda-5.5/lib on a 32-
bit system, and /usr/local/cuda-5.5/lib64 on a 64-bit system
$ export PATH=/usr/local/cuda-5.5/bin:$PATH
$ export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib:$LD_LIBRARY_PATH
‣ To change the environment variables for 64-bit operating systems:
$ export PATH=/usr/local/cuda-5.5/bin:$PATH
$ export LD_LIBRARY_PATH=/usr/local/cuda-5.5/lib64:$LD_LIBRARY_PATH
$ cuda-install-samples-5.5.sh <dir>
Available packages
The recommended installation packages are cuda and cuda-cross. Those two packages
will install the full set of other CUDA packages required for development and should
cover most scenarios
The cuda package installs all the available packages for native developments. That
includes the compiler, the debugger, the profiler, the math libraries,... For x86 patforms,
this also include NSight Eclipse Edition and the visual profiler It also includes the
NVIDIA driver package.
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 6
Installing CUDA Development Tools
The cuda-cross package installs all the packages required for cross-platform
developments, such as the i386 and x86_64 CUDA libraries. On supported platforms,
the cuda-cross-armhf package installs all the packages required for cross-platform
development on ARMv7. The libraries and header files of the ARMv7 display driver
package are also installed to enable the cross compilation of ARMv7 applications. The
cuda-cross and cuda-cross-armhf packages do not install the native display driver.
The packages installed by the packages above can also be installed individually by
specifying their names explicitly. The list of available packages be can obtained with:
Package Upgrades
The cuda and cuda-cross packages points to the latest stable release of the CUDA
Toolkit. When a new version is available, the standard package managers upgrade
command will install the latest CUDA Toolkit.
Some desktop environments, such as GNOME or KDE, will display an notification alert
when new packages are available.
To avoid any automatic upgrade, and lock down the installation to the X.Y release,
install the cuda-X-Y or cuda-cross-X-Y.
Side-by-side installations are supported. For instance, to install both the X.Y CUDA
Toolkit and the X.Y+1 CUDA Toolkit, install the cuda-X.Y and cuda-X.Y+1 packages.
Distribution-Specific Quirks
RHEL and Fedora
$ yumdownloader libvdpau.i686
$ rpm -U --oldpackage libvdpau*.rpm
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 7
Installing CUDA Development Tools
Ubuntu
‣ When using a proxy server with aptitude, wget must be set up to use the same
proxy settings before installing the cuda-repo package.
‣ The libcuda.so library is installed in the /usr/lib/nvidia-current directory. For pre-
existing projects which use libcuda.so, it may be useful to add a symbolic link from
libcuda.so in the /usr/lib directory.
2.5.2. Runfile Installation
This section does not apply for ARMv7 development. The ARMv7 release is only
available through the DEB package installer.
This section describes the installation and configuration of the CUDA Toolkit runfile,
which you previously downloaded.
The toolkit installation can install any combination of the driver, toolkit and samples.
The toolkit also installs a pristine copy of the samples within the toolkit directory.
This directory is used by the Samples Browser, and can be used to replace the writable
directory, should it become corrupt.
The samples installs and a writable copy of the samples where you should build and run
the samples.
Before installing the CUDA software packages, you should read the bundled Release
Notes, as the notes provide important details on installation and software functionality.
Then, follow these few steps for a successful installation.
If you wish to have a version of the Cuda Toolkit installed earlier than v5.5, it must
be installed prior to installing a Cuda Toolkit v5.5 or greater.
If you've already installed a stand-alone driver, you need to make sure it meets the
minimum version requirement for the toolkit. This requirement can be found in the
CUDA Toolkit release notes.
On many distributions, the driver version number can be found in the graphical
interface menus under Applications > System Tools > NVIDIA X Server Settings. Or,
from the command line, run:
/usr/bin/nvidia-settings
You can extract individual installers for each component by running (xx in 5.5.xx is
the minor version of the installation package):
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 8
Installing CUDA Development Tools
sh cuda_5.5.xx_linux_32_rhel5.x.run -extract=/path/to/extract/dir/
Still others require changing the system runlevel using a command such as
/sbin/init 3
Consult your distribution's documentation to find out how to properly exit the GUI.
2. If you are running an Ubuntu distro which installs the nvidia-current Debian package
by default, and want to install the NVIDIA Display Driver, remove this package by
running:
sudo apt-get --purge remove nvidia-current
3. The driver and toolkit must be installed for CUDA to function. If you have not
installed a stand-alone driver, install the driver from the NVIDIA CUDA Toolkit.
If the CUDA Samples are installed as a different user, others can install a writable
copy of the samples by running cuda-install-samples-5.5.sh <dir>
Install the CUDA Toolkit (xx in 5.5.xx is the minor version of the installation package)
by running the downloaded .run file as a superuser.
sudo sh cuda_5.5.xx_linux_32_rhel5.x.run
If you are using an Optimus system and are installing the driver, you must pass the
--optimus option to the CUDA Toolkit installer. If you are instead installing a stand
alone driver on an optimus system, you must pass --no-opengl-files to the installer
and decline the xorg.conf update at the end of the installation.
If the Display Driver component fails to install, you may have the Nouveau drivers
worked into your root filesystem (initramfs). To remove this, you will have to rebuild
your initramfs image:
sudo mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-
nouveau.img
If you are using Grub2 as a bootloader, you may also need to edit its config to prevent
Nouveau from loading. Add "rdblacklist=nouveau nouveau.modeset=0" to the end
of the GRUB_CMDLINE_LINUX entry in /etc/default/grub. Then, remake your Grub
configuration by running:
grub2-mkconfig -o /boot/grub2/grub.cfg
. Once this is done, reboot your machine and attempt the install again.
You can select which packages you wish to install at the start of the installation.
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 9
Installing CUDA Development Tools
6. Check that the device files/dev/nvidia* exist and have the correct (0666) file
permissions. These files are used by the CUDA Driver to communicate with the
kernel-mode portion of the NVIDIA Driver. Applications that use the NVIDIA driver,
such as a CUDA application or the X server (if any), will normally automatically
create these files if they are missing using the setuid nvidia-modprobe tool that is
bundled with the NVIDIA Driver. Some systems disallow setuid binaries, however,
so if these files do not exist, you can create them manually either by running the
command nvidia-smi as root at boot time or by using a startup script such as the
one below:
#!/bin/bash
/sbin/modprobe nvidia
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 10
Installing CUDA Development Tools
else
exit 1
fi
7. Restart the GUI environment (using the command startx or init 5 or sudo /etc/
init.d/gdm start or the equivalent command on your system).
New versions of CUDA software can require later versions of Linux and of the NVIDIA
driver, so always verify that you are running the correct driver release and version of
Linux for the version of the CUDA toolkit you are using.
Installing Mesa may overwrite the /usr/lib/libGL.so that was previously installed
by the NVIDIA driver, so a reinstallation of the NVIDIA driver might be required after
installing these libraries.
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 11
Installing CUDA Development Tools
The NVIDIA CUDA Toolkit includes sample programs in source form. You should
compile them by changing to ~/NVIDIA_CUDA-5.5_Samples and typing make. The
resulting binaries will be placed in ~/NVIDIA_CUDA-5.5_Samples/bin/x86_64/
linux/release.
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 12
Installing CUDA Development Tools
Running the bandwidthTest program ensures that the system and the CUDA-capable
device are able to communicate correctly. Its output is shown in Figure 2.
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 13
Chapter 3.
ADDITIONAL CONSIDERATIONS
Now that you have CUDA-capable hardware and the NVIDIA CUDA Toolkit installed,
you can examine and enjoy the numerous included programs. To begin using CUDA to
accelerate the performance of your own applications, consult the CUDA C Programming
Guide, located in /usr/local/cuda-5.5/doc.
A number of helpful development tools are included in the CUDA Toolkit to assist
you as you develop your CUDA programs, such as NVIDIA® Nsight™ Eclipse Edition,
NVIDIA Visual Profiler, cuda-gdb, and cuda-memcheck.
For technical support on programming questions, consult and participate in the
developer forums at http://developer.nvidia.com/cuda/.
www.nvidia.com
NVIDIA CUDA Getting Started Guide for Linux DU-05347-001_v5.5 | 14
Notice
ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS,
DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY,
"MATERIALS") ARE BEING PROVIDED "AS IS." NVIDIA MAKES NO WARRANTIES,
EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE
MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF
NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR
PURPOSE.
Information furnished is believed to be accurate and reliable. However, NVIDIA
Corporation assumes no responsibility for the consequences of use of such
information or for any infringement of patents or other rights of third parties
that may result from its use. No license is granted by implication of otherwise
under any patent rights of NVIDIA Corporation. Specifications mentioned in this
publication are subject to change without notice. This publication supersedes and
replaces all other information previously supplied. NVIDIA Corporation products
are not authorized as critical components in life support devices or systems
without express written approval of NVIDIA Corporation.
Trademarks
NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA
Corporation in the U.S. and other countries. Other company and product names
may be trademarks of the respective companies with which they are associated.
Copyright
© 2009-2013 NVIDIA Corporation. All rights reserved.
www.nvidia.com