CUDA-ENABLED GRAPHICS PROCESSORS

Một phần của tài liệu Jason sanders, edward kandrot CUDA by example (Trang 35 - 43)

Fortunately, it should be easy to find yourself a graphics processor that has been built on the CUDA Architecture because every NVIDIA GPU since the 2006 release of the GeForce 8800 GTX has been CUDA-enabled. Since NVIDIA regularly releases new GPUs based on the CUDA Architecture, the following will undoubt- edly be only a partial list of CUDA-enabled GPUs. Nevertheless, the GPUs are all CUDA-capable.

For a complete list, you should consult the NVIDIA website at www.nvidia.com/cuda, although it is safe to assume that all recent GPUs (GPUs from 2007 on) with more than 256MB of graphics memory can be used to develop and run code written with CUDA C.

ptg

develoPment envIronment

15 2.2 DEVELOPMENT ENVIRONMENT

GeForce GTX 480 GeForce GTX 470 GeForce GTX 295 GeForce GTX 285 GeForce GTX 285 for Mac GeForce GTX 280 GeForce GTX 275 GeForce GTX 260 GeForce GTS 250 GeForce GT 220 GeForce G210 GeForce GTS 150 GeForce GT 130 GeForce GT 120 GeForce G100 GeForce 9800 GX2 GeForce 9800 GTX+

GeForce 9800 GTX GeForce 9800 GT GeForce 9600 GSO GeForce 9600 GT GeForce 9500 GT GeForce 9400GT GeForce 8800 Ultra GeForce 8800 GTX GeForce 8800 GTS GeForce 8800 GT GeForce 8800 GS GeForce 8600 GTS GeForce 8600 GT GeForce 8500 GT GeForce 8400 GS GeForce 9400 mGPU GeForce 9300 mGPU

GeForce 8300 mGPU GeForce 8200 mGPU GeForce 8100 mGPU Tesla S2090 Tesla M2090 Tesla S2070 Tesla M2070 Tesla C2070 Tesla S2050 Tesla M2050 Tesla C2050 Tesla S1070 Tesla C1060 Tesla S870 Tesla C870 Tesla D870 QUADro mobile ProDUCtS Quadro FX 3700M Quadro FX 3600M Quadro FX 2700M Quadro FX 1700M Quadro FX 1600M Quadro FX 770M Quadro FX 570M Quadro FX 370M Quadro FX 360M Quadro NVS 320M Quadro NVS 160M Quadro NVS 150M Quadro NVS 140M Quadro NVS 135M Quadro NVS 130M Quadro FX 5800

Quadro FX 5600 Quadro FX 4800 Quadro FX 4800 for Mac Quadro FX 4700 X2 Quadro FX 4600 Quadro FX 3800 Quadro FX 3700 Quadro FX 1800 Quadro FX 1700 Quadro FX 580 Quadro FX 570 Quadro FX 470 Quadro FX 380 Quadro FX 370

Quadro FX 370 Low Profile Quadro CX

Quadro NVS 450 Quadro NVS 420 Quadro NVS 295 Quadro NVS 290 Quadro Plex 2100 D4 Quadro Plex 2200 D2 Quadro Plex 2100 S4 Quadro Plex 1000 Model IV GeForCe mobile ProDUCtS GeForce GTX 280M GeForce GTX 260M GeForce GTS 260M GeForce GTS 250M GeForce GTS 160M GeForce GTS 150M GeForce GT 240M GeForce GT 230M

Table 2.1 CUDA-enabled GPUs

Continued

ptg

GettInG stArted

16

Table 2.1 CUDA-enabled GPUs (Continued)

GeForce GT 130M GeForce G210M GeForce G110M GeForce G105M GeForce G102M GeForce 9800M GTX GeForce 9800M GT GeForce 9800M GTS GeForce 9800M GS

GeForce 9700M GTS GeForce 9700M GT GeForce 9650M GS GeForce 9600M GT GeForce 9600M GS GeForce 9500M GS GeForce 9500M G GeForce 9300M GS GeForce 9300M G

GeForce 9200M GS GeForce 9100M G GeForce 8800M GTS GeForce 8700M GT GeForce 8600M GT GeForce 8600M GS GeForce 8400M GT GeForce 8400M GS

nvIdIA devIce drIver 2.2.2

NVIDIA provides system software that allows your programs to communicate with the CUDA-enabled hardware. If you have installed your NVIDIA GPU properly, you likely already have this software installed on your machine. It never hurts to ensure you have the most recent drivers, so we recommend that you visit www.nvidia.com/cuda and click the Download Drivers link. Select the options that match the graphics card and operating system on which you plan to do develop- ment. After following the installation instructions for the platform of your choice, your system will be up-to-date with the latest NVIDIA system software.

cudA develoPment toolKIt 2.2.3

If you have a CUDA-enabled GPU and NVIDIA’s device driver, you are ready to run compiled CUDA C code. This means that you can download CUDA-powered appli- cations, and they will be able to successfully execute their code on your graphics processor. However, we assume that you want to do more than just run code because, otherwise, this book isn’t really necessary. If you want to develop code for NVIDIA GPUs using CUDA C, you will need additional software. But as prom- ised earlier, none of it will cost you a penny.

You will learn these details in the next chapter, but since your CUDA C applica- tions are going to be computing on two different processors, you are consequently going to need two compilers. One compiler will compile code for your GPU, and one will compile code for your CPU. NVIDIA provides the compiler for your GPU code. As with the NVIDIA device driver, you can download the CUDA Toolkit at http://developer.nvidia.com/object/gpucomputing.html. Click the CUDA Toolkit link to reach the download page shown in Figure 2.1.

ptg

develoPment envIronment

17 2.2 DEVELOPMENT ENVIRONMENT

Figure 2.1 The CUDA download page

ptg

GettInG stArted

18

You will again be asked to select your platform from among 32- and 64-bit versions of Windows XP, Windows Vista, Windows 7, Linux, and Mac OS. From the available downloads, you need to download the CUDA Toolkit in order to build the code examples contained in this book. Additionally, you are encouraged, although not required, to download the GPU Computing SDK code samples, which contains dozens of helpful example programs. The GPU Computing SDK code samples will not be covered in this book, but they nicely complement the material we intend to cover, and as with learning any style of programming, the more examples, the better. You should also take note that although nearly all the code in this book will work on the Linux, Windows, and Mac OS platforms, we have targeted the appli- cations toward Linux and Windows. If you are using Mac OS X, you will be living dangerously and using unsupported code examples.

stAndArd c comPIler 2.2.4

As we mentioned, you will need a compiler for GPU code and a compiler for CPU code. If you downloaded and installed the CUDA Toolkit as suggested in the previous section, you have a compiler for GPU code. A compiler for CPU code is the only component that remains on our CUDA checklist, so let’s address that issue so we can get to the interesting stuff.

wIndows

On Microsoft Windows platforms, including Windows XP, Windows Vista, Windows Server 2008, and Windows 7, we recommend using the Microsoft Visual Studio C compiler. NVIDIA currently supports both the Visual Studio 2005 and Visual Studio 2008 families of products. As Microsoft releases new versions, NVIDIA will likely add support for newer editions of Visual Studio while dropping support for older versions. Many C and C++ developers already have Visual Studio 2005 or Visual Studio 2008 installed on their machine, so if this applies to you, you can safely skip this subsection.

If you do not have access to a supported version of Visual Studio and aren’t ready to invest in a copy, Microsoft does provide free downloads of the Visual Studio 2008 Express edition on its website. Although typically unsuitable for commercial software development, the Visual Studio Express editions are an excellent way to get started developing CUDA C on Windows platforms without investing money in software licenses. So, head on over to www.microsoft.com/visualstudio if you’re in need of Visual Studio 2008!

ptg

C

CCHHH PPPRRR RRREEE EEEWWW

19 2.3 AAA TTTEEE VVVIII

LINUX

Most Linux distributions typically ship with a version of the GNU C compiler (gcc) installed. As of CUDA 3.0, the following Linux distributions shipped with supported versions of gcc installed:

Red Hat Enterprise Linux 4.8

Red Hat Enterprise Linux 5.3

OpenSUSE 11.1

SUSE Linux Enterprise Desktop 11

Ubuntu 9.04

Fedora 10

If you’re a die-hard Linux user, you’re probably aware that many Linux software packages work on far more than just the “supported” platforms. The CUDA Toolkit is no exception, so even if your favorite distribution is not listed here, it may be worth trying it anyway. The distribution’s kernel, gcc, and glibc versions will in a large part determine whether the distribution is compatible.

MACINTOSH OS X

If you want to develop on Mac OS X, you will need to ensure that your machine has at least version 10.5.7 of Mac OS X. This includes version 10.6, Mac OS X

“Snow Leopard.” Furthermore, you will need to install gcc by downloading and installing Apple’s Xcode. This software is provided free to Apple Developer Connection (ADC) members and can be downloaded from http://developer.apple.

com/tools/Xcode. The code in this book was developed on Linux and Windows platforms but should work without modification on Mac OS X systems.

Chapter Review

2.3

If you have followed the steps in this chapter, you are ready to start developing code in CUDA C. Perhaps you have even played around with some of the NVIDIA GPU Computing SDK code samples you downloaded from NVIDIA’s website. If so, we applaud your willingness to tinker! If not, don’t worry. Everything you need is right here in this book. Either way, you’re probably ready to start writing your first program in CUDA C, so let’s get started.

ptg

This page intentionally left blank

ptg

21

Chapter 3

Introduction to CUDA C

If you read Chapter 1, we hope we have convinced you of both the immense computational power of graphics processors and that you are just the

programmer to harness it. And if you continued through Chapter 2, you should have a functioning environment set up in order to compile and run the code you’ll be writing in CUDA C. If you skipped the first chapters, perhaps you’re just skimming for code samples, perhaps you randomly opened to this page while browsing at a bookstore, or maybe you’re just dying to get started; that’s OK, too (we won’t tell). Either way, you’re ready to get started with the first code exam- ples, so let’s go.

ptg

IntroductIon to cudA c

22

Chapter Objectives

3.1

Through the course of this chapter, you will accomplish the following:

You will write your first lines of code in CUDA C.

You will learn the difference between code written for the

host and code written

for a device.

You will learn how to run device code from the host.

You will learn about the ways device memory can be used on CUDA-capable

devices.

You will learn how to query your system for information on its CUDA-capable

devices.

A First Program

3.2

Since we intend to learn CUDA C by example, let’s take a look at our first example of CUDA C. In accordance with the laws governing written works of computer programming, we begin by examining a “Hello, World!” example.

Một phần của tài liệu Jason sanders, edward kandrot CUDA by example (Trang 35 - 43)

Tải bản đầy đủ (PDF)

(311 trang)