CUDA Getting Started Guide For Linux
CUDA Getting Started Guide For Linux
TABLE OF CONTENTS
Chapter 1. Introduction.........................................................................................1 1.1 System Requirements.................................................................................... 1 1.2 About This Document.................................................................................... 2 Chapter2.Installing CUDA Development Tools............................................................ 3 2.1Verify You Have a CUDA-Capable GPU................................................................ 3 2.2Verify You Have a Supported Version of Linux....................................................... 4 2.3Verify the System Has gcc Installed................................................................... 4 2.4Download the NVIDIA CUDA Toolkit....................................................................4 2.5Install the NVIDIA CUDA Toolkit........................................................................ 5 2.6 Verify the Installation....................................................................................8 2.6.1 Verify the Driver Version...........................................................................8 2.6.2 Compiling the Examples............................................................................8 2.6.3 Running the Binaries................................................................................8 Chapter3.Additional Considerations...................................................................... 11
www.nvidia.com
DU-05347-001_v5.0|ii
LIST OF FIGURES
Figure1Valid Results from SDK deviceQuery Program.....................................................9 Figure2Valid Results from SDK bandwidthTest Program.................................................10
www.nvidia.com
DU-05347-001_v5.0|iii
www.nvidia.com
DU-05347-001_v5.0|iv
Chapter 1. INTRODUCTION
NVIDIA CUDA is a general purpose parallel computing architecture introduced by NVIDIA. It includes the CUDA Instruction Set Architecture (ISA) and the parallel compute engine in the GPU. To program to the CUDA architecture, developers can use C, one of the most widely used high-level programming languages, which can then be run at great performance on a CUDA-capable processor. The CUDA architecture and its associated software were developed with several design goals in mind: Provide a small set of extensions to standard programming languages, like C, that enable a straightforward implementation of parallel algorithms. With CUDA and C for CUDA, programmers can focus on the task of parallelization of the algorithms rather than spending time on their implementation. Support heterogeneous computation where applications use both the CPU and GPU. Serial portions of applications are run on the CPU, and parallel portions are offloaded to the GPU. As such, CUDA can be incrementally applied to existing applications. The CPU and GPU are treated as separate devices that have their own memory spaces. This configuration also allows simultaneous computation on both the CPU and GPU without contention for memory resources. CUDA-capable GPUs have hundreds of cores that can collectively run thousands of computing threads. Each core has shared resources, including registers and memory. The on-chip shared memory allows parallel tasks running on these cores to share data without sending it over the system memory bus. This guide will show you how to install and check the correct operation of the CUDA Development Tools.
1.1SYSTEM 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
www.nvidia.com
DU-05347-001_v5.0|1
Introduction
www.nvidia.com
DU-05347-001_v5.0|2
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 has 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.
www.nvidia.com
DU-05347-001_v5.0|3
www.nvidia.com
DU-05347-001_v5.0|4
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:
1. Exit the GUI if you are in a GUI environment by pressing Ctrl-Alt-Backspace. Some distributions require you to press this sequence twice in a row; others have disabled it altogether in favor of a command such as sudo /etc/init.d/gdm stop Still others require changing the system runlevel using a command such as
www.nvidia.com
DU-05347-001_v5.0|5
/sbin/init 3 Consult your distribution's documentation to find out how to properly exit the GUI. 2.
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, copy the pristine installation of the CUDA Samples (/usr/local/cuda-5.0/samples) to the desired user directory and change the ownership of the copied directory and subdirectories to the user.
Install the CUDA Toolkit by running the downloaded .run file as a superuser. sudo sh cuda_5.0.24_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 along 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. You can select which packages you wish to install at the start of the installation. The CUDA Toolkit installation defaults to /usr/local/cuda-5.0. In addition, a symbolic link is created from /usr/local/cuda to /usr/local/cuda-5.0 in order for existing projects to make use of the new CUDA Toolkit. The CUDA Samples are installed to a user folder $(HOME)/ NVIDIA_CUDA-5.0_Samples. A pristine copy of the CUDA Samples also resides in /usr/local/cuda-5.0/samples. 3. Define the environment variables. The PATH variable needs to include /usr/local/cuda-5.0/bin LD_LIBRARY_PATH needs to contain /usr/local/cuda-5.0/lib on a 32-bit system, and both /usr/local/cuda-5.0/lib and /usr/local/cuda-5.0/ lib64 on a 64-bit system The typical way to place these values in your environment is with the following commands: export PATH=/usr/local/cuda-5.0/bin:$PATH and export LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib:$LD_LIBRARY_PATH for 32-bit operating systems, or export LD_LIBRARY_PATH=/usr/local/cuda-5.0/lib:/usr/local/ cuda-5.0/lib64:$LD_LIBRARY_PATH for 64-bit operating systems. To make such settings permanent, place them in ~/.bash_profile.
www.nvidia.com
DU-05347-001_v5.0|6
4. If you wish to build all of the samples, including those with graphical rather than command-line interfaces, you may need to install additional system libraries or headers if you have not done so before. While every Linux distribution is slightly different with respect to package names and package installation procedures, the libraries and headers most likely to be necessary are OpenGL (e.g., Mesa), GLU, GLUT, and X11 (including Xi, Xmu, and GLX). These can be installed on Ubuntu as follows, for example: sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1mesa-dev 5. If you do not use a GUI environment, or use an Optimus system, ensure that the device files/dev/nvidia* exist and have the correct file permissions. (This would be done automatically when initializing a GUI environment on a discrete GPU.) This can be done by creating a startup script like the following to load the driver kernel module and create the entries as a superuser at boot time:
#!/bin/bash /sbin/modprobe nvidia if [ "$?" -eq 0 ]; then # Count the number of NVIDIA controllers found. NVDEVS=`lspci | grep -i NVIDIA` N3D=`echo "$NVDEVS" | grep "3D controller" | wc -l` NVGA=`echo "$NVDEVS" | grep "VGA compatible controller" | wc -l` N=`expr $N3D + $NVGA - 1` for i in `seq 0 $N`; do mknod -m 666 /dev/nvidia$i c 195 $i done mknod -m 666 /dev/nvidiactl c 195 255 else exit 1 fi
6. 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). More information on installing the driver is available at http://us.download.nvidia.com/ XFree86/Linux-x86/295.59/README/index.html.
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
DU-05347-001_v5.0|7
www.nvidia.com
DU-05347-001_v5.0|8
www.nvidia.com
DU-05347-001_v5.0|9
www.nvidia.com
DU-05347-001_v5.0|10
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.0/doc. For technical support on programming questions, consult and participate in the bulletin board and mailing list at http://forums.nvidia.com/index.php?showforum=71.
www.nvidia.com
DU-05347-001_v5.0|11
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
2007-2012 NVIDIA Corporation. All rights reserved.
www.nvidia.com