Skip to content

Haque Academy Homework Blog 8bbit

Please, wait while we are validating your browser

CUDA Application Design and Development

CUDA Application Design and Development Rob Farber

AMSTERDAM • BOSTON • HEIDELBERG • LONDON NEW YORK • OXFORD • PARIS • SAN DIEGO SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO Morgan Kaufmann is an imprint of Elsevier

Acquiring Editor: Todd Green Development Editor: Robyn Day Project Manager: Danielle S. Miller Designer: Dennis Schaeffer Morgan Kaufmann is an imprint of Elsevier 225 Wyman Street, Waltham, MA 02451, USA © 2011 NVIDIA Corporation and Rob Farber. Published by Elsevier Inc. All rights reserved. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from the publisher. Details on how to seek permission, further information about the Publisher’s permissions policies and our arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our website: www.elsevier.com/permissions. This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may be noted herein).

Notices Knowledge and best practice in this field are constantly changing. As new research and experience broaden our understanding, changes in research methods or professional practices, may become necessary. Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any information or methods described herein. In using such information or methods they should be mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility. To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions, or ideas contained in the material herein. Library of Congress Cataloging-in-Publication Data Application submitted. British Library Cataloguing-in-Publication Data A catalogue record for this book is available from the British Library. ISBN: 978-0-12-388426-8 For information on all MK publications visit our website at www.mkp.com Typeset by: diacriTech, Chennai, India Printed in the United States of America 11 12 13 14 15 10 9 8 7 6 5 4 3 2 1

Dedication

This book is dedicated to my wife Margy and son Ryan, who could not help but be deeply involved as I wrote it. In particular to my son Ryan, who is proof that I am the older model – thank you for the time I had to spend away from your childhood. To my many friends who reviewed this book and especially those who caught errors, I cannot thank you enough for your time and help. In particular, I’d like to thank everyone at ICHEC (the Irish Center for High-End Computing) who adopted me as I finished the book’s birthing process and completed this manuscript. Finally, thank you to my colleagues and friends at NIVDIA, who made the whole CUDA revolution possible.

v

Contents

FOREWORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi PREFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii CHAPTER 1

First Programs and How to Think in CUDA . . . . . . . . . 1 Source Code and Wiki . . . . . . . . . . . . . . . . . . . . . . . . . . Distinguishing CUDA from Conventional Programming with a Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . Choosing a CUDA API . . . . . . . . . . . . . . . . . . . . . . . . . . Some Basic CUDA Concepts . . . . . . . . . . . . . . . . . . . . . Understanding Our First Runtime Kernel . . . . . . . . . . . . Three Rules of GPGPU Programming . . . . . . . . . . . . . . . Big-O Considerations and Data Transfers . . . . . . . . . . . CUDA and Amdahl’s Law . . . . . . . . . . . . . . . . . . . . . . . Data and Task Parallelism . . . . . . . . . . . . . . . . . . . . . . . Hybrid Execution: Using Both CPU and GPU Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . Regression Testing and Accuracy . . . . . . . . . . . . . . . . . Silent Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction to Debugging . . . . . . . . . . . . . . . . . . . . . . . UNIX Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Windows Debugging with Parallel Nsight . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CHAPTER 2

....2 . . . . . . . .

. . . . . . . .

. . . . . . . .

.2 .5 .8 11 13 15 17 18

. . . . . . .

. . . . . . .

. . . . . . .

19 21 22 23 24 29 30

CUDA for Machine Learning and Optimization. . . . . . 33 Modeling and Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 Machine Learning and Neural Networks . . . . . . . . . . . . . . . 38 XOR: An Important Nonlinear Machine-Learning Problem. . . .39 Performance Results on XOR . . . . . . . . . . . . . . . . . . . . . . . . 53 Performance Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 The C++ Nelder-Mead Template . . . . . . . . . . . . . . . . . . . . . 57

vii

viii

Contents

CHAPTER 3

The CUDA Tool Suite: Profiling a PCA/NLPCA Functor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 PCA and NLPCA . . . . . . . . . . . . . . . . . . . . Obtaining Basic Profile Information . . . . . . Gprof: A Common UNIX Profiler . . . . . . . . The NVIDIA Visual Profiler: Computeprof . Parallel Nsight for Microsoft Visual Studio . Tuning and Analysis Utilities (TAU) . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . .

CHAPTER 4

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

64 71 73 74 77 82 83

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. 86 . 92 . 94 100 102 108

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

109 111 112 114 116 124 131

Efficiently Using GPU Memory . . . . . . . . . . . . . . . . . 133 Reduction. . . . . . . . . . . . . . . . . . . . . . . Utilizing Irregular Data Structures . . . . Sparse Matrices and the CUSP Library Graph Algorithms . . . . . . . . . . . . . . . . SoA, AoS, and Other Structures . . . . . . Tiles and Stencils . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . .

CHAPTER 7

. . . . . . .

CUDA Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 The CUDA Memory Hierarchy . GPU Memory . . . . . . . . . . . . . . L2 Cache . . . . . . . . . . . . . . . . . L1 Cache . . . . . . . . . . . . . . . . . CUDA Memory Types . . . . . . . Global Memory. . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . .

CHAPTER 6

. . . . . . .

The CUDA Execution Model . . . . . . . . . . . . . . . . . . . . 85 GPU Architecture Overview . . . . . . . . . . . . . . . Warp Scheduling and TLP . . . . . . . . . . . . . . . . ILP: Higher Performance at Lower Occupancy Little’s Law . . . . . . . . . . . . . . . . . . . . . . . . . . . CUDA Tools to Identify Limiting Factors . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CHAPTER 5

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

134 146 149 151 154 154 155

Techniques to Increase Parallelism. . . . . . . . . . . . . . 157 CUDA Contexts Extend Parallelism . . . . . . . . . . . . . . . . . . 158 Streams and Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Out-of-Order Execution with Multiple Streams . . . . . . . . . 166

Contents

Tying Data to Computation . . . . . . . . . . . . . . . . . . . . . . . . 172 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176

CHAPTER 8

CUDA for All GPU and CPU Applications . . . . . . . . . 179 Pathways from CUDA to Multiple Hardware Backends . Accessing CUDA from Other Languages . . . . . . . . . . . . Libraries. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . CUBLAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . CUFFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

CHAPTER 9

. . . . . .

. . . . . .

180 188 191 191 191 205

Mixing CUDA and Rendering . . . . . . . . . . . . . . . . . . 207 OpenGL . . . . . . . . . . . . . . . . . . . . . . . . . . . GLUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction to the Files in the Framework Summary . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

208 208 213 238

CHAPTER 10 CUDA in a Cloud and Cluster Environments . . . . . . 241 The Message Passing Interface (MPI) How MPI Communicates . . . . . . . . . . Bandwidth . . . . . . . . . . . . . . . . . . . . . Balance Ratios . . . . . . . . . . . . . . . . . . Considerations for Large MPI Runs . . Cloud Computing . . . . . . . . . . . . . . . . A Code Example . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

242 246 248 249 252 255 256 264

CHAPTER 11 CUDA for Real Problems . . . . . . . . . . . . . . . . . . . . . . 265 Working with High-Dimensional Data PCA/NLPCA . . . . . . . . . . . . . . . . . . . . Force-Directed Graphs . . . . . . . . . . . . Monte Carlo Methods. . . . . . . . . . . . . Molecular Modeling . . . . . . . . . . . . . . Quantum Chemistry. . . . . . . . . . . . . . Interactive Workflows . . . . . . . . . . . . A Plethora of Projects. . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

266 267 271 272 273 273 274 274 275

CHAPTER 12 Application Focus on Live Streaming Video . . . . . . . 277 Topics in Machine Vision. . . . . . . . . . . . . . . . . . . . . . . . . . 278 FFmpeg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 TCP Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283

ix

x

Contents

Live Stream Application . . . . . . . The simpleVBO.cpp File. . . . . . . The callbacksVBO.cpp File. . . . . Building and Running the Code . The Future . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . Listing for simpleVBO.cpp . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

287 291 291 295 295 297 297

WORKS CITED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311

Foreword

GPUs have recently burst onto the scientific computing scene as an innovative technology that has demonstrated substantial performance and energy efficiency improvements for the numerous scientific applications. These initial applications were often pioneered by early adopters, who went to great effort to make use of GPUs. More recently, the critical question facing this technology is whether it can become pervasive across the multiple, diverse algorithms in scientific computing, and useful to a broad range of users, not only the early adopters. A key barrier to this wider adoption is software development: writing and optimizing massively parallel CUDA code, using new performance and correctness tools, leveraging libraries, and understanding the GPU architecture. Part of this challenge will be solved by experts sharing their knowledge and methodology with other users through books, tutorials, and collaboration. CUDA Application Design and Development is one such book. In this book, the author provides clear, detailed explanations of implementing important algorithms, such as algorithms in quantum chemistry, machine learning, and computer vision methods, on GPUs. Not only does the book describe the methodologies that underpin GPU programming, but it describes how to recast algorithms to maximize the benefit of GPU architectures. In addition, the book provides many case studies, which are used to explain and reinforce important GPU concepts like CUDA threads, the GPU memory hierarchy, and scalability across multiple GPUs including an MPI example demonstrated near-linear scaling to 500 GPUs. Lastly, no programming language stands alone. Arguably, for any language to be successful, it must be surrounded by an ecosystem of powerful compilers, performance and correctness tools, and optimized libraries. These pragmatic aspects of software development are often the most important factor to developing applications quickly. CUDA Application Design and Development

xi

xii

Foreword

does not disappoint in this area, as it devotes multiple chapters to describing how to use CUDA compilers, debuggers, performance profilers, libraries, and interoperability with other languages. I have enjoyed learning from this book, and I am certain you will also. Jeffrey S. Vetter 20 September 2011 Distinguished Research Staff Member, Oak Ridge National Laboratory; Professor, Georgia Institute of Technology.

Preface

Timing is so very important in technology, as well as in our academic and professional careers. We are an extraordinarily lucky generation of programmers who have the initial opportunity to capitalize on inexpensive, generally available, massively parallel computing hardware. The impact of GPGPU (General-Purpose Graphics Processing Units) technology spans all aspects of computation, from the smallest cell phones to the largest supercomputers in the world. They are changing the commercial application landscape, scientific computing, cloud computing, computer visualization, games, and robotics and are even redefining how computer programming is taught. Teraflop (trillion floating-point operations per second) computing is now within the economic reach of most people around the world. Teenagers, students, parents, teachers, professionals, small research organizations, and large corporations can easily afford GPGPU hardware and the software development kits (SDKs) are free. NVIDIA estimates that more than 300 million of their programmable GPGPU devices have already been sold. Programmed in CUDA (Compute Unified Device Architecture), those third of a billion NVIDIA GPUs present a tremendous market opportunity for commercial applications, and they provide a hardware base with which to redefine what is possible for scientific computing. Most importantly, CUDA and massively parallel GPGPU hardware is changing how we think about computation. No longer limited to performing one or a few operations at a time, CUDA programmers write programs that perform many tens of thousands of operations simultaneously! This book will teach you how to think in CUDA and harness those tens of thousands of threads of execution to achieve orders-of-magnitude increased performance for your applications, be they commercial, academic, or scientific. Further, this book will explain how to utilize one or more GPGPUs within a single application, whether on a single machine or across a cluster of machines.

xiii

xiv

Preface

In addition, this book will show you how to use CUDA to develop applications that can run on multicore processors, making CUDA a viable choice for all application development. No GPU required! Not concerned with just syntax and API calls, the material in this book covers the thought behind the design of CUDA, plus the architectural reasons why GPGPU hardware can perform so spectacularly. Various guidelines and caveats will be covered so that you can write concise, readable, and maintainable code. The focus is on the latest CUDA 4.x release. Working code is provided that can be compiled and modified because playing with and adapting code is an essential part of the learning process. The examples demonstrate how to get high-performance from the Fermi architecture (NVIDIA 20-series) of GPGPUS because the intention is not just to get code working but also to show you how to write efficient code. Those with older GPGPUs will benefit from this book, as the examples will compile and run on all CUDA-enabled GPGPUs. Where appropriate, this book will reference text from my extensive Doctor Dobb’s Journal series of CUDA tutorials to highlight improvements over previous versions of CUDA and to provide insight on how to achieve good performance across multiple generations of GPGPU architectures. Teaching materials, additional examples, and reader comments are available on the http://gpucomputing.net wiki. Any of the following URLs will access the wiki: ■ ■



My name: http://gpucomputing.net/RobFarber. The title of this book as one word: http://gpucomputing.net/ CUDAapplicationdesignanddevelopment. The name of my series: http://gpucomputing.net/ supercomputingforthemasses.

Those who purchase the book can download the source code for the examples at http://booksite.mkp.com/9780123884268. To accomplish these goals, the book is organized as follows: Chapter 1. Introduces basic CUDA concepts and the tools needed to build and debug CUDA applications. Simple examples are provided that demonstrates both the thrust C++ and C runtime APIs. Three simple rules for high-performance GPU programming are introduced. Chapter 2. Using only techniques introduced in Chapter 1, this chapter provides a complete, general-purpose machine-learning and optimization framework that can run 341 times faster than a single core of a conventional processor. Core concepts in machine learning

Preface

and numerical optimization are also covered, which will be of interest to those who desire the domain knowledge as well as the ability to program GPUs. Chapter 3. Profiling is the focus of this chapter, as it is an essential skill in high-performance programming. The CUDA profiling tools are introduced and applied to the real-world example from Chapter 2. Some surprising bottlenecks in the Thrust API are uncovered. Introductory data-mining techniques are discussed and data-mining functors for both Principle Components Analysis and Nonlinear Principle Components Analysis are provided, so this chapter should be of interest to users as well as programmers. Chapter 4. The CUDA execution model is the topic of this chapter. Anyone who wishes to get peak performance from a GPU must understand the concepts covered in this chapter. Examples and profiling output are provided to help understand both what the GPU is doing and how to use the existing tools to see what is happening. Chapter 5. CUDA provides several types of memory on the GPU. Each type of memory is discussed, along with the advantages and disadvantages. Chapter 6. With over three orders-of-magnitude in performance difference between the fastest and slowest GPU memory, efficiently using memory on the GPU is the only path to high performance. This chapter discusses techniques and provides profiler output to help you understand and monitor how efficiently your applications use memory. A general functorbased example is provided to teach how to write your own generic methods like the Thrust API. Chapter 7. GPUs provide multiple forms of parallelism, including multiple GPUs, asynchronous kernel execution, and a Unified Virtual Address (UVA) space. This chapter provides examples and profiler output to understand and utilize all forms of GPU parallelism. Chapter 8. CUDA has matured to become a viable platform for all application development for both GPU and multicore processors. Pathways to multiple CUDA backends are discussed, and examples and profiler output to effectively run in heterogeneous multi-GPU environments are provided. CUDA libraries and how to interface CUDA and GPU computing with other high-level languages like Python, Java, R, and FORTRAN are covered. Chapter 9. With the focus on the use of CUDA to accelerate computational tasks, it is easy to forget that GPU technology is also a splendid platform for visualization. This chapter discusses primitive restart and how it can dramatically accelerate visualization and gaming applications. A complete working example is provided that allows the reader to create and fly

xv

xvi

Preface

around in a 3D world. Profiler output is used to demonstrate why primitive restart is so fast. The teaching framework from this chapter is extended to work with live video streams in Chapter 12. Chapter 10. To teach scalability, as well as performance, the example from Chapter 3 is extended to use MPI (Message Passing Interface). A variant of this example code has demonstrated near-linear scalability to 500 GPGPUs (with a peak of over 500,000 single-precision gigaflops) and delivered over one-third petaflop (1015 floating-point operations per second) using 60,000 x86 processing cores. Chapter 11. No book can cover all aspects of the CUDA tidal wave. This is a survey chapter that points the way to other projects that provide free working source code for a variety of techniques, including Support Vector Machines (SVM), Multi-Dimensional Scaling (MDS), mutual information, force-directed graph layout, molecular modeling, and others. Knowledge of these projects—and how to interface with other high-level languages, as discussed in Chapter 8—will help you mature as a CUDA developer. Chapter 12. A working real-time video streaming example for vision recognition based on the visualization framework in Chapter 9 is provided. All that is needed is an inexpensive webcam or a video file so that you too can work with real-time vision recognition. This example was designed for teaching, so it is easy to modify. Robotics, augmented reality games, and data fusion for heads-up displays are obvious extensions to the working example and technology discussion in this chapter. Learning to think about and program in CUDA (and GPGPUs) is a wonderful way to have fun and open new opportunities. However, performance is the ultimate reason for using GPGPU technology, and as one of my university professors used to say, “The proof of the pudding is in the tasting.” Figure 1 illustrates the performance of the top 100 applications as reported on the NVIDIA CUDA Showcase1 as of July 12, 2011. They demonstrate the wide variety of applications that GPGPU technology can accelerate by two or more orders of magnitude (100-times) over multi-core processors, as reported in the peer-reviewed scientific literature and by commercial entities. It is worth taking time to look over these showcased applications, as many of them provide freely downloadable source code and libraries. GPGPU technology is a disruptive technology that has redefined how computation occurs. As NVIDIA notes, “from super phones to supercomputers.” This technology has arrived during a perfect storm of opportunities, as traditional multicore processors can no longer achieve significant speedups 1

http://developer.nvidia.com/cuda-action-research-apps.

Preface

Top 100 NVIDIA CUDA application showcase speedups (Min 100, Max 2600, Median 1350) 2500 2000 1500 1000 500 0

1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 82 85 88 91 94 97 100

Reported speedup

3000

Rank in sorted list from highest to lowest speedup

FIGURE 1 Top 100 NVIDIA application showcase speedups.

through increases in clock rate. The only way manufacturers of traditional processors can entice customers to upgrade to a new computer is to deliver speedups two to four times faster through the parallelism of dual- and quad-core processors. Multicore parallelism is disruptive, as it requires that existing software be rewritten to make use of these extra cores. Come join the cutting edge of software application development and research as the computer and research industries retool to exploit parallel hardware! Learn CUDA and join in this wonderful opportunity.

xvii

CHAPTER 1

First Programs and How to Think in CUDA

The purpose of this chapter is to introduce the reader to CUDA (the parallel computing architecture developed by NVIDIA) and differentiate CUDA from programming conventional single and multicore processors. Example programs and instructions will show the reader how to compile and run programs as well as how to adapt them to their own purposes. The CUDA Thrust and runtime APIs (Application Programming Interface) will be used and discussed. Three rules of GPGPU programming will be introduced as well as Amdahl’s law, Big-O notation, and the distinction between data-parallel and task-parallel programming. Some basic GPU debugging tools will be introduced, but for the most part NVIDIA has made debugging CUDA code identical to debugging any other C or C++ application. Where appropriate, references to introductory materials will be provided to help novice readers. At the end of this chapter, the reader will be able to write and debug massively parallel programs that concurrently utilize both a GPGPU and the host processor(s) within a single application that can handle a million threads of execution. At the end of the chapter, the reader will have a basic understanding of: ■ ■ ■ ■ ■ ■ ■



How to create, build, and run CUDA applications. Criteria to decide which CUDA API to use. Amdahl’s law and how it relates to GPU computing. Three rules of high-performance GPU computing. Big-O notation and the impact of data transfers. The difference between task-parallel and data-parallel programming. Some GPU-specific capabilities of the Linux, Mac, and Windows CUDA debuggers. The CUDA memory checker and how it can find out-of-bounds and misaligned memory errors.

CUDA Application Design and Development. DOI: 10.1016/B978-0-12-388426-8.00001-X © 2011 NVIDIA Corporation and Rob Farber. Published by Elsevier Inc. All rights reserved.

1

2

CHAPTER 1:

First Programs and How to Think in CUDA

SOURCE CODE AND WIKI Source code for all the examples in this book can be downloaded from http://booksite.mkp.com/9780123884268. A wiki (a website collaboratively developed by a community of users) is available to share information, make comments, and find teaching material; it can be reached at any of the following aliases on gpucomputing.net: ■ ■



My name: http://gpucomputing.net/RobFarber. The title of this book as one word: http://gpucomputing.net/ CUDAapplicationdesignanddevelopment. The name of my series: http://gpucomputing.net/ supercomputingforthemasses.

DISTINGUISHING CUDA FROM CONVENTIONAL PROGRAMMING WITH A SIMPLE EXAMPLE Programming a sequential processor requires writing a program that specifies each of the tasks needed to compute some result. See Example 1.1, “seqSerial.cpp, a sequential C++ program”: Example 1.1 //seqSerial.cpp #include

CUDA Application Design and Development CUDA Application Design and Development Rob Farber AMSTERDAM • BOSTON • HEID...

Author: Rob Farber


24 downloads 43 Views 7MB Size