Skip to content

Preface

Programming Massively Parallel Processors 5e — English original (Preface)

Preface

We are proud to present to you the 5th edition of “Programming Massively Parallel Processors – a hands-on approach.”

Since the publication of the fourth edition in 2022, exascale computing using hundreds of thousands of GPUs interconnected with fast networks has powered the AI revolution to full gear. GPUs have played a front-and-center role in training the large language models behind ChatGPT, DeepSeek, and Gemini. GPUs have also become the workhorse of serving AI queries from users that span the entire age, race, and geography spectrum. The impact of GPU computing is now felt across all sectors of the industry and society.

We are also witnessing wide adoption of GPU computing in key industry vertical markets, such as transportation, e-commercial, manufacturing, health care, financial services, and logistics. Many will be able to achieve breakthroughs in these disciplines using digital twins of their physical infrastructure that are of unprecedented levels of scale, accuracy, safety, controllability, and observability. This book provides a critical ingredient for this vision: teaching parallel programming to millions of graduate and undergraduate students so that parallel thinking and programming skills will be as pervasive as calculus.

The target audience of this book starts with graduate and undergraduate students from all science and engineering disciplines where parallel computing is needed to achieve breakthroughs. From our experience, the book has also been successfully used by many industry professional developers who need to refresh their parallel computing skills and keep up-to-date with the ever increasing speed of technology evolution. These professional developers work in fields such as machine learning, network security, autonomous vehicles, computational financing, data analytics, cognitive computing, mechanical engineering, civil engineering, electrical engineering, bio-engineering, physics, chemistry, astronomy, and geography; they use computation to advance their field. We assume that the reader has at least some basic C++ programming experience. The book takes the approach of teaching parallel programming by building up an intuitive understanding of the techniques. We use CUDA, a parallel programming environment that is supported on NVIDIA GPUs. There are more than one billion of these processors in use and millions of programmers actively using CUDA.

Since the publication of the fourth edition, we have received numerous comments from our readers and instructors. Many told us about the existing features which they value. Others gave us ideas about how we should expand its contents to make the book even more valuable. Furthermore, the hardware and software technology for heterogeneous parallel computing has advanced tremendously since then. In the hardware arena, three more generations of GPU computing architectures, Ada Lovelace, Hopper, and Blackwell, have been introduced. In the software domain, CUDA 11 through CUDA 13 have allowed programmers to access new hardware and system features. New algorithms have also been developed or adapted to take advantage of new GPU features. Accordingly, we added four new chapters and rewrote or expanded a substantial number of the existing chapters and appendices. We also removed three chapters to make room for the newly added contents.

The four new parallel patterns and applications chapters are Chapter 12 (Filtering), Chapter 15 (Advanced Optimizations for Matrix Multiplication), Chapter 16 (Wavefront Parallelism), and Chapter 20 (Large Language Models). Our motivations for adding these chapters are as follows:

  • Chapter 12 (Filtering): Filtering is a classical parallel pattern that is often included in the same libraries that support the other patterns we cover. The newly added chapter covers both unstable and stable filtering. Unstable filtering is used as a vehicle for introducing the optimization of coalescing atomic operations, and the underlying warp voting functions needed by the optimization. It is also used to introduce the important concept of work efficiency in parallel algorithm design. Stable filtering is presented as an extension that preserves the relative order of the filtered elements, and is shown to be a building block of radix sort as covered in Chapter 14.
  • Chapter 15 (Advanced Optimizations for Matrix Multiplication): Matrix multiplication is a core computation of many scientific, engineering, and AI applications, including the deep learning methods behind today’s AI revolution. This chapter covers a progression of advanced optimization techniques for general matrix multiplication (GEMM) on the GPU architecture, including register tiling, double buffering, and the use of the specialized tensor cores of recent NVIDIA GPUs. The chapter also introduces the concept of roofline analysis for reasoning about the achievable performance of an implementation.
  • Chapter 16 (Wavefront Parallelism): Dynamic programming algorithms form an important class of computations in areas such as bioinformatics and operations research. This chapter introduces wavefront parallelism for exploiting the parallelism hidden in the data dependences of dynamic programming computations. It starts from a naive parallelization that divides the dynamic programming table into tiles, observes the warp underutilization and poor data locality that result from the changing dimensions of the wavefronts, and then applies a hypertile transformation that keeps all threads active and improves data locality.
  • Chapter 20 (Large Language Models): Large Language Models (LLMs) have become the keystone of Artificial Intelligence (AI), which represents arguably the most significant scientific, technological, and societal revolution since the appearance of the Internet. Chatbot applications (just an example of LLMs’ multiple applications) like OpenAI ChatGPT reached millions of users in just a few days after their launch and their impact on the ways people work, learn, and communicate is being transformative and indelible. The high computation requirement for training and using LLM models have been the driving force behind the fast growth of hundred-thousand-GPU data centers around the world. This chapter introduces the architecture of Transformers, which are as of today the most successful LLM architecture. We put special focus on their attention mechanism, which identifies relationships (e.g., semantic, contextual, syntactic) between fragments of words called tokens. We present two key optimizations of the parallel implementation of attention. First, KV caching avoids recomputation during the generation of new tokens by the LLM. Second, flash attention proposes an algorithmic transformation that greatly reduces overheads derived from multiple kernel execution and repeated memory accesses. We also use the attention mechanism to illustrate the use of batching to improve the throughput of processing queries and resource utilization at the cost of increased latency experienced by each individual query.

In addition to the newly added chapters, three chapters have gone through major expansion and revision. The rationales for rewriting these chapters are as follows:

  • Chapter 6 (Performance Considerations): In the previous edition, this chapter included a checklist of six optimizations: occupancy tuning, reducing control divergence, and shared memory and register tiling which were covered in previous chapters, privatization which was covered in later chapters, and coalescing of memory accesses and thread coarsening which were introduced in the chapter itself. In the current edition, the checklist is significantly expanded with additional optimizations including warp-level primitives which are covered in later chapters, and loop unrolling, vector loads and stores, avoiding shared memory bank conflicts, and double buffering which are introduced in the chapter itself. Moreover, thread coarsening was previously demonstrated with matrix multiplication. This example is replaced with a more abstract coverage since the application of thread coarsening to matrix multiplication is discussed in-depth in the new Chapter 15.
  • Chapter 11 (Scan): In the previous edition, this chapter focused on comparing the Kogge-Stone and Brent-Kung approaches to parallel scan with emphasis on work efficiency. It also covered thread coarsening as a means for improving work efficiency, a scan-scan-add decomposition for parallelizing scan across multiple blocks, and a single-kernel scan based on single-lookback. In the current edition, the chapter was significantly revised to put less emphasis on the Brent-Kung approach, discuss work efficiency more thoroughly, and apply more optimizations in the context of the Kogge-Stone approach. In particular, the revised chapter covers double-buffering and warp-level primitives as a means for reducing synchronization overhead, and register tiling as a means for reducing shared memory access latency. It also covers the reduce-scan-scan decomposition and compares it to the scan-scan-add decomposition from the perspective of memory bandwidth utilization. It fixes the implementation of single-lookback with C++ atomics that have release and acquire semantics. It also introduces multiple lookback and decoupled lookback that overcome the long latency experienced by the single lookback implementation.
  • Chapter 23 (Multi-GPU Programming): In the previous edition, this chapter used a 3D stencil computation as a running example to introduce multi-GPU programming with MPI without CUDA-awareness. In the current edition, the running example was revised to use 2D stencil with residual computation. Moreover, the running example was used to introduce not just one but three different multi-GPU programming models: CUDA-aware MPI, NCCL, and NVSHMEM.

The eight chapters and appendix that were subject to substantial expansion or updates are:

  • Chapter 4 (Compute Architecture and Scheduling): This chapter was revised to use the Hopper H100 GPU specifications in its examples. Moreover, additional text was added to introduce thread block clusters, a new level of the CUDA thread grid hierarchy that enables more threads to synchronize with each other and access each other’s shared memory. Warp-level primitives are also briefly introduced, but are more thoroughly covered in later chapters.
  • Chapter 5 (Memory Architecture and Data Locality): This chapter was also revised to use the Hopper H100 GPU specifications in its examples. Moreover, additional text was added to introduce distributed shared memory. The chapter also more thoroughly defines and discusses the concepts of arithmetic intensity, compute- and memory-boundedness, and speed of light analysis, setting the stage for more thorough analyses of memory bandwidth considerations in Chapter 7 (Convolution), Chapter 8 (Stencil), and Chapter 11 (Scan).
  • Chapter 9 (Histogram): In the previous edition, this chapter used a text histogram as a running example to introduce atomic operations, focusing on CUDA’s low-level atomic intrinsics. In the current edition, the revised chapter uses an image histogram as a more intuitive running example. It also uses the higher-level CUDA C++ atomics API which exposes the scope of atomic operations (block, device, system) and their memory ordering semantics (relaxed, release, acquire, sequential). In fact, the code examples in other chapters were also revised to use the higher-level API.
  • Chapter 10 (Reduction): This chapter was expanded to introduce warp-level primitives, especially warp shuffle operations, and use these primitives to reduce the synchronization overhead of the reduction kernel.
  • Chapter 14 (Sorting): This chapter was expanded to cover odd-even sort as a simpler pedagogical introduction to sorting on GPUs. It also observes that radix sort is built on the newly added stable filter pattern in the new Chapter 12 on filtering.
  • Chapter 17 (Sparse Matrix Computation): This chapter was expanded to cover the Compressed Sparse Column (CSC) format. While CSC is not typically used for SpMV, it is useful in other contexts where column-wise traversal of the sparse matrix is desired. For this reason, it was added to the chapter.
  • Chapter 18 (Graph Traversal): This chapter was expanded to use BFS as an example for demonstrating how the cooperative groups API can be used to launch kernels that can perform grid-wide barrier synchronizations. In particular, instead of launching a new grid for every BFS level, a new kernel was introduced that iterated across all levels while performing a grid-wide barrier synchronization within the kernel.
  • Chapter 19 (Convolutional Neural Networks): When we wrote the chapter for the fourth edition, we felt that we needed to offer a more extensive background section on machine learning and deep learning to help readers understand the main contents of the chapter. As a result, the chapter became the longest chapter by far. Since then, students in all majors have increasingly taken courses in these areas. Therefore, for the fifth edition, we feel that much of the background material is no longer needed by most of our readers. We decided to remove the material from Chapter 19 into a new Appendix B (Deep Learning Basics). This way, readers who miss some background in these areas can still have easy access to the background material that is curated to be directly relevant to the chapter.
  • Appendix A (Numerical Considerations): Since the publication of the fourth edition, there has been rapid progress in defining and adopting low-precision floating-point format standard across industry. This movement is in response to the insatiable demand for very high floating-point throughput and advances in quantization techniques for large language model parameters. With the help from expert reviewers, we expanded the appendix to cover the new formats and the improvements in the floating-point implementation in recent GPU architecture generations. We also added more insights into the original sections.

In order to make room for the newly added contents, three chapters were removed. It is never easy to let a chapter go. We carefully decided on the following chapters because of the recent changes in GPU architecture trends and application landscape.

  • Iterative MRI Reconstruction: The main objective of this old chapter was to contrast an input-centric scatter-based implementation of the iterative MRI reconstruction application with an output-centric gather-based implementation. The same contrast is also made in Chapter 21 (Electrostatic Potential Map), but in the context of another application. Since the two chapters carried the same message, we decided to omit one of them and keep the other. We kept the electrostatic potential map chapter because the application is representative of a wider range of physical modeling and simulation use cases and because it presented other optimizations as well. We moved some of the fundamental discussions on the scatter-based and gather-based implementations into Chapter 21. Readers who are particularly interested in the Iterative MRI Reconstruction application can still refer to older editions of the book.
  • Dynamic Parallelism: The main objective of this old chapter was to introduce dynamic parallelism, a feature of CUDA for capturing nested parallelism in computations by allowing threads running on the GPU to call kernel functions and launch new grids as they discover more work during their execution. Over a decade has passed since the first implementation of dynamic parallelism in the Kepler architecture. Unfortunately, the feature has not seen wide adoption, in part due to its high overhead. For this reason, we decided to remove the chapter from the book. Readers who are interested in learning about and using dynamic parallelism can still refer to the CUDA programming guide, or to old editions of the book. We plan to revise and include the spatial sorting pattern covered by this chapter in a future edition.
  • Other Advanced Practices: The main objective of this old chapter was to briefly present some promising, advanced CUDA features that were not mature enough at the time and/or not illustrated with code examples. Over time, some of these features, such as cooperative groups and thread block clusters, have matured and are adopted into revised/new code examples of this edition. As a result, we decided to remove the old chapter. The materials in this chapter addressing the evolution of CUDA memory types, address spaces, and CUDA pointers’ reach have been moved into the new Appendix C. These topics have been confusing to many CUDA developers, particularly as they continue to evolve with time. A clear understanding of the history and nuances help avoid performance pitfalls that can trip even experienced developers.

While making all these improvements, we tried to preserve the features that seem to contribute most to the book’s popularity. First, we keep our explanations as intuitive as possible. While it is tempting to formalize some of the concepts, especially when we cover the basic parallel algorithms, we strive to keep all our explanations intuitive and practical. Second, we keep the book as concise as possible. While it is tempting to keep adding new material, we want to minimize the number of pages a reader needs to go through to learn all the key concepts. We accomplished this by removing some of the chapters mentioned earlier.

In addition to adding new chapters and substantially rewriting others since the previous edition, we have also organized the book into four major parts. The updated organization is illustrated in Fig. P.1. The first part introduces the fundamental concepts behind parallel programming, the GPU architecture, and performance analysis and optimization. This part has remained the same compared to the previous edition. The second part applies these concepts by covering common computation patterns and showing how they can be parallelized and optimized. Each parallel pattern also introduces a new programming feature or technique. Compared to the previous edition, the new Chapter 12 (Filtering) and Chapter 15 (Advanced optimizations for Matrix Multiplication) were added to this part and Chapter 14 (Sort) was moved from the third part to this part. The third part introduces additional advanced patterns and applications and continues to apply the optimizations that are practiced in the second part. However, it puts more emphasis on exploring alternative forms of problem decomposition to parallelize a computation and analyzes the trade-offs between different decompositions and their associated data structures. Compared to the previous edition, this part was expanded by the addition of Chapter 16 (Wavefront Parallelism) and Chapter 20 (Large Language Models). Moreover, Chapter 23 (Multi-GPU Programming) was moved to this part from the old fourth part. On the other hand, the old chapter on Iterative MRI Reconstruction was removed from this part, and as mentioned earlier, Chapter 14 (Sort) was moved from this part to the second part. Finally, the old fourth part on advanced practices and programming features was removed because the two chapters on Dynamic Parallelism and Other Advanced Practices were removed from the book, and the remaining Chapter 23 (Multi-GPU Programming) was moved to the third part.

Fig. P.1
Fig. P.1 Organization of the book.

How to use the book

We would like to offer some of our experience in teaching courses with this book. Since 2006, the original ECE498AL course has become a permanent course known as ECE408 or CS483 at the University of Illinois at Urbana-Champaign. We started writing some of the early chapters of this book when we offered ECE498AL the second time. Since then, we have used the book for numerous offerings of ECE408 as well as the Coursera Heterogeneous Parallel Programming course, and the VSCSE and PUMPS summer schools.

A two-phased approach

Most of the chapters in the book are designed to be given in approximately a single 75 min lecture each. The chapters that may need two 75 min lectures to be fully covered are Chapter 11 (Scan), Chapter 17 (Sparse Matrix Computation), Chapter 18 (Graph Traversal) and Chapter 19. In ECE408, the lectures, programming assignments, and final project are paced with each other and are organized into two phases. In the first phase, which consists of Parts 1 and 2 of this book, students learn the fundamentals and basic patterns, and they practice the skills they learn via guided programming assignments. This phase consists of 14 chapters and typically takes around eight weeks, where each week students work on a programming assignment corresponding to the lectures covered that week. For example, in the first week, a lecture based on Chapter 2 is dedicated to teaching the basic CUDA memory/threading model, the CUDA extensions to the C++ language, and the basic programming tools. After that lecture, students can write a simple vector addition code in a couple of hours.

The following two weeks include a series of four lectures based on Chapters 3 through Chapter 6 that give students conceptual understanding of the CUDA memory model, the CUDA thread execution model, GPU hardware performance features, and modern computer system architecture. During these two weeks, students work on different implementations of matrix-matrix multiplication where they see the performance of their implementations increases throughout this period. In the remaining five weeks, the lectures cover common data-parallel programming patterns needed to develop a high-performance parallel application based on Chapters 7 through Chapter 14. Throughout these weeks, students complete assignments on convolution, histogram, reduction, and scan. By the end of the first phase, students should be quite comfortable with parallel programming and should be ready to implement more advanced code with less handholding.

In the second phase, which is based on Part 3, students learn advanced patterns and applications while they themselves work on a final project that involves accelerating an advanced pattern or application. Although we do not usually assign weekly programming assignments during this phase, the project typically has a weekly milestone to help students pace themselves. Depending on the duration and format of the course, instructors may be able to cover only a small subset of the chapters in this phase and may need to skip some. Instructors may also choose to replace some lectures with guest lectures, paper discussion sessions, or lectures that support the final project. For this reason, Fig. P.1 uses arrows to indicate the dependencies between chapters to assist instructors in selecting which chapters they can skip or reorder to customize the course for their local context.

Tying it all together: the final project

While the lectures, labs, and chapters of this book help lay the intellectual foundation for the students, what brings the learning experience together is the final project. The final project is so important to the full-semester course that it is prominently positioned in the course and commands nearly two months’ focus. It incorporates five innovative aspects: mentoring, workshop, clinic, final report, and symposium. While much of the information about the final project is available in the NVIDIA Accelerated Computing Teaching Kit, we would like to offer the reasoning that was behind the design of these aspects.

Students are encouraged to base their final projects on problems that represent current challenges in the research community. To seed the process, the instructors should recruit several computational science research groups to propose problems and serve as mentors. The mentors are asked to contribute a one-to-two-page project specification sheet that briefly describes the significance of the application, what the mentor would like to accomplish with the student teams on the application, the technical skills (particular type of Math, Physics, Chemistry courses) required to understand and work on the application, and a list of web and traditional resources that students can draw upon for technical background, general information, and building blocks, along with specific URLs or ftp paths to particular implementations and coding examples. These project specification sheets also provide students with learning experiences in defining their own research projects later in their careers. Several examples are available in the Teaching Kit.

The design document

Once the students decide on a project and form a team, they submit a design document for the project. This helps them to think through the project steps before they jump into it. The ability to do such planning will be important to their career success. The design document should discuss the background and motivation for the project, application-level objectives and potential impact, main features of the end application, an overview of their design, an implementation plan, their performance goals, a verification plan and acceptance test, and a project schedule.

The project report and symposium

Students are required to submit a project report on their team’s key findings. We also recommend a whole-day class symposium. During the symposium, students use presentation slots proportional to the size of the teams. During the presentation, the students highlight the best parts of their project report for the benefit of the whole class. The presentation accounts for a significant part of the students’ grades. Each student must answer questions directed to the student individually, so that different grades can be assigned to individuals in the same team. The symposium is an opportunity for students to learn to produce a concise presentation that motivates their peers to read a full paper.

Class competition

In 2016, the enrollment level of ECE408 far exceeded the level that can be accommodated by the final project process. As a result, we moved from the final project to a class competition. At the middle of the semester, we announce a competition challenge problem. We use one lecture to explain the competition challenge problem and the rules that will be used for ranking the teams. All student submissions are autograded and ranked. The final ranking of each team is determined by the execution time, correctness, and clarity of their parallel code. The students do a demo of their solution at the end of the semester and submit a final report. This compromise preserves some of the benefits of final projects when the class size makes final projects infeasible.

Course resources

The NVIDIA Accelerated Computing Teaching Kit is a publicly available resource that contains lecture slides, recordings of past lectures, lab assignments, final project guidelines, and sample project specifications for instructors who use this book for their classes. The lecture slides and lab assignments are also available at the companion site of the textbook, and the recordings of past course offerings are available on the book’s YouTube channel. We are also in the process of making the sample codes from the book’s figures available with their associated host codes for instructors who would like to demo the code in class, or general readers who would like to experiment with the code themselves. While this book provides the intellectual contents for these classes, the additional material is crucial in achieving the overall education goals.

Finally, we would like to hear from you if you have any ideas for improving this book. We would also like to know how we can improve the supplementary on-line material. Of course, we always love to know what you like about the book. We hope to hear from you soon.

Wen-mei W. Hwu

David B. Kirk

Izzat El Hajj