Appendix C CUDA memories, address spaces, and pointers
Appendix C CUDA memories, address spaces, and pointers
APPENDIX
CUDA memories, address spaces, and pointers C With special contributions from Isaac Gelado and Mark Harris Throughout this book, we have mostly assumed a fairly simple model of interaction between the host and the device in a heterogeneous computing system. In this simple model, as presented in Chapter 2, each device has a device memory (CUDA global memory) that is separate from the host memory, or the system memory. The data to be processed by a kernel running on a device need to be transferred from the host memory to the device memory by calling the cudaMemcpy() function. The data produced by the device also need to be transferred from the device memory to the host by calling the cudaMemcpy() function before it can be utilized by the host. Early GPU generations only supported this simple host/device interaction model. Although the model is simple and easy to understand, it has resulted in several problems at the application level. First, I/O devices such as disk controllers and network interface cards are designed to operate efficiently on the host memory. Since the device memory is separate from the host memory, input data need to be transferred from the host memory to the device memory and output data need to be transferred from the device memory to the host memory for use by I/O devices. Such additional transfers increase the I/O latency and reduce the achievable I/O throughput. For many applications, the ability of I/O devices to operate directly on the device memory would improve overall application performance and simplify the application code. Second, traditional programming systems such as Python place their application data structures in the host memory. Some of the data structures are large. The device memory in CUDA-enabled GPUs tends to offer higher bandwidth but smaller capacity compared to the host memory, which forces application developers to partition their large data structures into chunks that each fit into the device memory. For example, in Chapter 21, the 3D electrostatic energy grid array was partitioned into 2D slices that are transferred between the host memory and the device memory. For many applications, it would be much better if entire data structures can reside in the device memory. For some applications, there may not even be a good way to partition the data structure into smaller chunks. For these applications, it would be best if the GPU can directly access the data in the host memory or have the CUDA runtime system software to migrate the data that are used during kernel execution. As more applications adopted GPU computing, their needs motivated CUDA system software developers and GPU hardware designers to provide a better solution. Researchers have been aware of these needs and have proposed solutions since the early days of CUDA [1]. The rest of this section will go over a brief history of advancements that address these limitations.
Throughout this book, we have mostly assumed a fairly simple model of interaction between the host and the device in a heterogeneous computing system. In this simple model, as presented in Chapter 2, each device has a device memory (CUDA global memory) that is separate from the host memory, or the system memory. The data to be processed by a kernel running on a device need to be transferred from the host memory to the device memory by calling the cudaMemcpy() function. The data produced by the device also need to be transferred from the device memory to the host by calling the cudaMemcpy() function before it can be utilized by the host. Early GPU generations only supported this simple host/device interaction model. Although the model is simple and easy to understand, it has resulted in several problems at the application level.
First, I/O devices such as disk controllers and network interface cards are designed to operate efficiently on the host memory. Since the device memory is separate from the host memory, input data need to be transferred from the host memory to the device memory and output data need to be transferred from the device memory to the host memory for use by I/O devices. Such additional transfers increase the I/O latency and reduce the achievable I/O throughput. For many applications, the ability of I/O devices to operate directly on the device memory would improve overall application performance and simplify the application code.
Second, traditional programming systems such as Python place their application data structures in the host memory. Some of the data structures are large. The device memory in CUDA-enabled GPUs tends to offer higher bandwidth but smaller capacity compared to the host memory, which forces application developers to partition their large data structures into chunks that each fit into the device memory. For example, in Chapter 21, the 3D electrostatic energy grid array was partitioned into 2D slices that are transferred between the host memory and the device memory. For many applications, it would be much better if entire data structures can reside in the device memory. For some applications, there may not even be a good way to partition the data structure into smaller chunks. For these applications, it would be best if the GPU can directly access the data in the host memory or have the CUDA runtime system software to migrate the data that are used during kernel execution.
As more applications adopted GPU computing, their needs motivated CUDA system software developers and GPU hardware designers to provide a better solution. Researchers have been aware of these needs and have proposed solutions since the early days of CUDA [1]. The rest of this section will go over a brief history of advancements that address these limitations.
C.1 Unified device memory address space
In early CUDA-enabled GPUs, shared, memory, local memory, and global memory formed their own separate address spaces. The developer could use pointers into the global memory but not others. Starting with the Fermi Architecture introduced in 2009, these memories became parts of a unified address space. This unified address space enabled a single set of load/store instructions and pointer addresses to access any of the GPU memory spaces (global, local, or shared memory), rather than different instructions and pointers for each. This made it easier to abstract away which memory contains a particular operand, allowing the programmer to deal with this only during allocation, and making it simpler to pass CUDA data objects to other procedures and functions, irrespective of which memory area they come from. The unified device memory address space support made CUDA code modules much more ``composable’’. That is, a CUDA device function can accept a pointer that may point to any of these memories. For example, without a unified GPU address space, a device function needs to have one implementation for each type of memory that one of its arguments can reside in. Unified GPU address space allows variables in all main types of GPU memories to be accessed the same way, and thus allowing one device function to accept arguments that can reside in different types of GPU memory. The code would run faster if a function argument pointer points to a shared memory location and slower if it points to a global memory location. The programmer can still perform manual data placement and transfers as a performance optimization. This capability significantly reduced the cost of building production quality CUDA libraries. It also enabled full C and C++ pointer support for CUDA kernel and device functions.
C.2 Zero-copy access to host memory
In 2009, CUDA 2.2 introduced zero-copy access to the host memory. This enables the host code to supply to a kernel a special device data pointer to host memory. The CUDA kernel code running on the GPU can use this pointer to directly access the host memory through the system interconnect such as the PCIe bus without calling cudaMemcpy(). Zero-copy memory is pinned host memory (see Chapter 23) and is allocated by calling cudaHostAlloc() with cudaHostAllocMapped as the value of the flag argument. We mentioned that the other values of the flag argument are for more advanced usage. The data pointer returned by cudaHostAlloc() cannot be directly passed to the kernel. The host code has to obtain a valid device data pointer using cudaHostGetDevicePointer() first, and pass the device data pointer returned by this function to the kernel. This means that different data pointers for host and device codes are used to access the same data in the host memory. As we explained in Chapter 23, the host memory pages allocated for zero-copy access by the GPU must be pinned to prevent the operating system from accidentally paging out the data while the GPU is accessing them. Obviously, the access will suffer from the long latency and limited bandwidth of the system interconnect. Thebandwidth of the system interconnect is typically less than 10% of the global memory bandwidth. As we have learned in Chapter 5, a kernel’s performance is typically limited by the global memory bandwidth unless we use tiling techniques to drastically reduce the number of global memory accesses performed per floating-point operation. If most of the memory accesses of a kernel are to zero-copy memory, the kernel’s execution speed can be even more severely limited by the bandwidth of the system interconnect. Therefore, one should only use zero-copy memory for application data structures that are occasionally and sparsely accessed by a kernel running on a GPU.
C.3 Unified virtual address space
In 2011, CUDA 4 introduced the Unified Virtual Address Space (UVAS) which originated from the GMAC library [1]. Until this CUDA release, the host and the device had their own virtual address spaces, each of them mapping host or device data pointers to physical host or device memory locations. These disjoint virtual address spaces imply that the same physical memory location could be accessed by different virtual addresses in the host and the device, which happens when using zero-copy memory. UVAS specifies a single virtual address space shared by the host and the device. The UVAS guarantees that each physical memory address is only mapped to one virtual memory location. This enables the CUDA runtime to determine whether a data pointer is referencing host or device memory by just inspecting its virtual memory address. This feature removes the need to specify the data copy direction on cudaMemcpy() calls. Instead, the programmer can simply specify cudaMemcpyDefault and the direction of transfer is inferred from the values of the pointers. It is important to note that the UVAS in CUDA 4 does not guarantee the accessibility of the data referenced by a pointer. For example, the host code cannot use a device pointer returned by cudaMalloc() to directly access the device memory and vice versa. Zero-copy access to the host memory is the exception: the host code can pass a pointer to zero-copy memory (allocated through cudaHostAlloc()) to the device as a kernel parameter. When the kernel code dereferences this zero-copy pointer, the pointer value is translated to a physical system memory location, and used to access the system memory directly through the PCIe bus. Note that this approach does not necessarily allow the kernel code to dereference a pointer value read from a memory location, such as following a chain of pointers while traversing a linked data structure, unless all pointers reference memory that has been allocated using cudaHostAlloc(). The limitations in both the types of data structures that can be supported and the bandwidth of data accesses of zero-copy memory motivate further improvements in the memory model of GPU architectures beyond UVAS.
C.4 Large virtual and physical GPU address spaces
One fundamental limitation of early CUDA-enabled GPUs is the size of their virtual and physical addresses. These early devices support 32-bit virtual addresses and up to 32-bit physical addresses. For these devices, the size of the device memory is limited to 4 GB, the maximal amount of memory that can be addressed with 32 physical address bits. Furthermore, CUDA kernels could only operate on data sets whose sizes were less than 4 GB, the maximal number of virtual memory locations that can be accessed through 32-bit pointers, regardless of whether the data set resides in the host memory or the device memory. Furthermore, modern CPUs are based on 64-bit virtual addresses with 48 bits actually utilized. These host virtual addresses could not be accommodated by the 32-bit virtual addresses used by GPUs, which contributed to the limitation of the types of data structures supported by and the memory allocation mechanism (cudaHostAlloc()) required for zero-copy memory access. To remove this limitation, GPU generations starting with the Kepler GPU architecture introduced in 2013 have adopted modern virtual memory architecture with 64-bit virtual addresses and physical addresses of at least 40 bits. The obvious benefit is that these GPUs can incorporate more than 4 GB of DRAM and that CUDA kernels can now operate on large data sets. While the enlarged virtual and physical address spaces obviously enable the use of large device memories, they also open the door for much better host/device interaction models. For example, the host and the device can now use exactly the same pointer value to access a piece of data, regardless of whether it is in the host memory or the device memory.
C.5 Unified physical address space
The large GPU physical address space allows the CUDA system software to place device memory of different GPUs in the system into a unified physical address space. The benefit is that one GPU can directly access the memory of any other GPU attached to the same PCIe bus and/or NVLink domain by simply dereferencing a data pointer mapped to the physical address of the other GPU. Prior to the Kepler GPU architecture, communication among different GPUs (e.g., halo exchange in the stencil example in Chapter 23) was only possible through device-to-device memory copies triggered by the host code. This resulted in extra memory consumed to store the data being copied from other GPUs and extra performance overheads due to host-device synchronization and the setup operations needed for the memory copies. Direct access to the memory of other devices in the system enables just passing a device pointer as a kernel call parameter so that the kernel code can use it to load and/or store the data that reside in the other GPU’s device memory.
C.6 Unified memory
In 2013, CUDA 6 introduced Unified Memory, which creates a pool of managed virtual memory pages that are shared between the CPU and GPU, bridging the CPUGPU divide. The managed memory is accessible by both the CPU and GPU using a single pointer. Variables in the managed memory can reside in the CPU physical FIGURE C.1 Unified Memory simplifies porting of CPU code (left) to CUDA code (right).
memory, the GPU physical memory, or even both. The CUDA runtime software and hardware implement data migration and coherence support. The net effect is that the managed memory looks like CPU memory to code running on the CPU, and like GPU memory to code running on the GPU. Of course, the application must perform appropriate synchronization operations such as barriers or atomic operations to coordinate any concurrent accesses to the managed memory locations. A shared global virtual address space allows all variables in an application to be accessed with the same virtual address from the CPU code or the GPU code. Such a memory architecture, when exposed by programming tools and run-time systems to applications, can result in several major benefits. One benefit is the reduced amount of effort required for porting CPU code to CUDA. In Fig. C.1, we show a simple CPU code example on the left side. With Unified Memory, the code can be ported to CUDA with two simple changes. The first change is to use cudaMallocManaged() and cudaFree() in place of malloc() and free(). The second change is to launch a kernel and perform device synchronization rather than calling the qsort() function. Obviously, one still needs to write or have access to a parallel qsort kernel. What we are showing is that the change to the host code is straightforward and easy to maintain. The performance of the CUDA 6 Unified Memory was limited by the hardware capabilities of the Kepler and Maxwell GPU architectures. The contents of all managed memory locations modified by the CPU had to be flushed out to the GPU device memory before any grid launch. The CPU and GPU could not simultaneously access a managed memory allocation and the Unified Memory address space was limited to the size of the GPU physical memory. These limitations are due to the fact that these GPU architectures lacked the ability to support coherence between the host and device memories and that the data migration was mostly performed by software.
C.7 Access to full host virtual address space
In 2016, the Pascal GPU architecture extended GPU address translation capabilities to accommodate 49-bit virtual addressing. This extension is large enough to cover the 48-bit virtual address spaces of modern CPUs, as well as the GPU’s own memory. It allows Unified Memory programs to access the full address spaces of all CPUs and GPUs in the system as a single virtual address space, rather than be limited by the number of virtual address bits that can be handled by the GPU’s address translation mechanism. As a result, the CPUs and GPUs can truly share the pointer values, enabling the GPUs to traverse pointer-based data structures in the host memory.
C.8 Page fault handling
Memory page fault handling support starting with the Pascal GPU architecture is a crucial feature that provides more seamless Unified Memory functionality. Combined with the system-wide virtual address space, the ability to handle page faults eliminates the need for the CUDA system software to synchronize (flush) all managed memory contents to the GPU before each grid launch. The CUDA runtime can implement a coherence mechanism by allowing the host and the device to invalidate each other’s copies of data when they modify that data in the managed memory. The invalidation can be done using the page mapping and protection mechanisms. When launching a grid, the CUDA system software no longer has to bring all GPU copies of the managed memory data up to date. If the grid accesses a piece of data whose copy in the device memory has been invalidated by the host, the GPU will handle a page fault to bring the data up to date and resume execution. If a thread grid running on the GPU accesses a page that is not resident in its device memory, it also experiences a page fault, allowing the page to be automatically migrated to the GPU memory on-demand. Alternatively, the page may be mapped into the GPU address space for access over the system interconnects if the data is expected to be accessed only occasionally (mapping on access can sometimes be faster than migration). This support generalizes zero-copy access to a limited part of the host memory access to zero-copy access to the entire host memory as well as other GPU’s memory in the system. Note that Unified Memory is system-wide: GPUs (and CPUs) can fault and migrate memory pages either from CPU memory or from the memory of other GPUs in the system. If a CPU function dereferences a pointer and accesses a variable mapped to the GPU physical memory, the data access would still be serviced, but perhaps at a longer latency. Such capability allows the CUDA programs to more easily call legacy libraries that have not been ported to GPUs. In the prior CUDA memory architecture, the developer must manually transfer data from the device memory to the host memory in order to use legacy library functions to process them on the CPU. The Unified Memory with the page fault handling capability enables a much more general CPU/GPU interaction mechanism than the original zero-copy access. It allows the GPU to traverse large data structures in the host memory. Starting with the Pascal architecture, a GPU device can traverse a linked data structure even if the data structure does not reside in zero-copy memory. This is because the same pointer value is used in the host code and device code to refer to the same variable. Thus, References the embedded pointer values of a linked data structure built by the host can be traversed by the device, and vice versa. In some application areas such as CAD, the host physical memory system may have hundreds of gigabytes of capacity. These physical memory systems are needed because the applications require the entire data set to be “in core’’. With the ability to directly access very large CPU physical memories, it becomes feasible for GPUs to accelerate these applications.
C.9 Virtual address space control
CUDA 11 introduced a set of low level APIs to provide programmers more flexibility regarding memory allocation. The new API allows reserving a range of the virtual address space using cuMemAddressReserve(). Later on, the programmer can allocate physical memory on any device using cuMemCreate(), and map it to any position in the reserved range using cuMemMap(). These APIs enable building custom layouts of data structures across multiple devices. For instance, it would be possible to allocate a 3D volume across multiple devices while using a single pointer to reference it.
References [1] I. Gelado, J.E. Stone, J. Cabezas, S. Patel, N. Navarro, W.-m.W. Hwu, An asymmetric distributed shared memory model for heterogeneous parallel systems, in: Proceedings of the Fifteenth International Conference on Architectural Support for Programming Languages and Operating Systems, 2010, pp. 347–358.
References
[1] I. Gelado, J.E. Stone, J. Cabezas, S. Patel, N. Navarro, W.-m.W. Hwu, An asymmetric distributed shared memory model for heterogeneous parallel systems, in: Proceedings of the Fifteenth International Conference on Architectural Support for Programming Languages and Operating Systems, 2010, pp. 347–358. memory, 4, 114, 128, 176, 208, 230, 258, 314, Activation function, 602, 613, 614 Adjacent memory locations, 314, 413 optimization, 16, 64, 111, 149, 151–153, 349, Allocated memory, 29, 30, 41, 253 Application Programming Interface (API) functions, Arithmetic and logic unit (ALU), 100 Arithmetic intensity (AI), 94, 115, 167, 171, 189, 272, 351, 352, 491, 492, 497, 504, 506, 539 Atomic operation, 12, 16, 201, 203, 204, 244, 245, 278, 279, 289, 291, 333, 405–407, 434, Automatic variable, 37, 86, 102, 108, 520 Bank conflict, 123, 135, 139–141, 151, 152, 272, Barrier synchronization, 14, 16, 69, 71, 111, 118, 146, 174, 191, 213, 240, 241, 244, 247, 257, 296, 297, 316, 353, 364, 366, 493, 499 Basic Linear Algebra Subprogram (BLAS), 59 dimensions, 46, 89, 106, 165, 177, 193, 268, 525 index, 41, 45, 165, 215, 244, 245, 269, 277, 278, segment, 215, 216, 268–270, 273, 275, 277 size, 37, 46, 62, 74, 81, 85, 177, 179, 192, 193, thread, 24, 33, 63, 99, 124, 165, 168, 188, 191, 207, 208, 230, 237, 256, 257, 296, 315, 333, 350, 351, 379, 381, 442, 443, 459, Boundary condition control divergence, 82 edge-centric parallelization, 436 vertex-centric parallelization, 431 Central processing unit (CPU), 1 Circular-buffer merge kernel, 321 Co-rank function, 306, 308, 309 atomic operations, 291–293, 295, 442 memory access patterns, 415, 416 atomic operations, 290, 291, 294, 442 memory, 123, 124, 129, 193, 216, 234, 298, 299, 314, 339, 340, 369, 410, 413, 521, 527 factor, 141–143, 198, 215, 248, 267–269, 528 thread, 73, 141, 142, 152, 190, 193, 194, 214, 246, 252, 267, 268, 298, 299, 327, 344, 345, 352, 488, 519, 521, 530, 535, 543 examples, 9, 40, 142, 146, 164, 369, 438, 542 kernel, 26, 35, 50, 52, 67, 69, 114, 117, 118, 169, 213, 230, 260, 266, 338, 352, 354, 376, 394, 432, 434, 436, 487, 496, 519, 521 parallel, 12, 21, 123, 204, 539, 577 sequential, 4, 37, 207, 249, 266 Compressed Sparse Column (CSC) format, 418, 419 parallel, 16, 26, 201, 251, 285, 401 pattern, 16, 153, 187, 221, 460 stencil, 183, 189, 198, 352, 396, 542, 543, 548 complexity, 11, 203, 253, 258, 309, 329, 523, Compute-to-global-memory-access ratio, 94, 96 Computer aided design (CAD), 430, 435 threads, 127–129, 239, 297, 299, 345, 395, 412 access consecutive data elements, 413 access consecutive elements, 129, 406 Consolidating block segments, 273 memory, 16, 98, 103, 118, 153, 168, 169, 171, Control divergence, 16, 77, 79, 80, 149, 230, 416 Conventional vector addition, 26 filter, 159, 160, 165, 167, 457 kernel, 159, 160, 165, 167, 168, 191 memory bandwidth bottleneck, 172 pattern, 56, 151, 153, 463, 474 layer, 454–460, 463, 464, 467, 470, 473, 474, Convolutional neural network (CNN), 17, 59, 179, Cooperating parallel workers, 4 Cooperative group, 70, 276, 277, 293, 398, 445, convolutional layer kernel, 460 device, 36, 69, 74, 98, 99, 101, 124, 171, 266, implementation, 454, 474, 484, 486, 493 kernel, 34, 37, 39, 65, 86, 90, 93, 119, 120, 154, 160, 207, 379, 386, 392, 459, 474, 486, occupancy calculation functions, 445 programmer, 13, 91, 98, 103, 118, 147 model, 6, 14, 15, 552, 555, 575 programs, 7, 36, 39, 40, 55, 89 runtime, 88, 169, 172, 558, 563, 628 streams, 555, 563, 564, 566, 575 tiled matrix multiplication kernel, 470 CUDA matrix multiplication kernels, 486 parallelism, 7, 15, 21, 23, 24, 248 CUDA, 36, 69, 74, 98, 99, 101, 124, 171, 266, function, 36, 40, 42, 103, 239, 263, 264, 269, 278, 353, 354, 361, 388, 389, 440, 441, block, 46, 89, 106, 165, 177, 193, 268, 525 Direct Coulomb Summation (DCS), 514, 530 Direct Memory Access (DMA), 563 Direction-optimized implementation, 436 Distributed shared memory, 70, 102 Double-buffering, 146, 147, 152, 258, 366 Dynamic Random-Access Memory (DRAM), 5, 28, bandwidth, 10, 166, 170, 171, 179 burst, 125, 126, 132, 135, 137, 150, 209 memory access, 303, 314, 404–406, 409, 412, Electrostatic potential map computation, 17 tile, 109, 110, 130, 319–321, 498, 500, 503 Embarrassingly parallel applications, 12 Error correcting code (ECC), 130 Exclusive scan, 253, 300, 337–341, 343–345 operation, 253, 298, 339, 342, 343, 345, 347 Extracting parallelism, 333, 449 False dependence, 110, 146, 147, 258, 366 Field Programmable Gate Array (FPGA), 7 Filtering pattern, 150, 152, 153 Fine-grained multithreading, 83 operations, 119, 167, 351, 366, 506, 507, 519, Floyd-Warshall algorithm, 377, 378 Formulating convolutional layers, 463, 474 Full host virtual address space, 627 Fully connected layer (FC), 605 device, 36, 40, 42, 103, 239, 263, 264, 269, 278, 353, 354, 361, 388, 389, 440, 441, 497, 498 kernel, 15, 28, 30, 32, 35–37, 45–47, 50, 98, General Matrix Multiply (GEMM), 350 access, 83, 97, 105, 125, 150, 196, 198, 236, GNU Compiler Collection (gcc), 70 threads, 33, 139, 144, 384, 409, 574 GPU Processing Cluster (GPC), 68 Graphics Double Data Rate (GDDR), 68 Graphics Processing Unit (GPU), 3 points, 21, 184–187, 189–191, 514–521, 531, 533, 536, 542–545, 548, 549, 551, 554 thread, 27, 33, 35, 37, 69, 379, 517, 519, 556 Grid-wide barrier synchronization, 70, 276, 445 Grouped-query attention (GQA), 508 memory access, 5, 364, 366, 367 resources, 1, 69, 74, 88, 93, 94, 123, 143, 251 Heterogeneous parallel computing, 3 Hiding memory latency, 132, 149, 154 Hierarchical tiling, 352, 359, 360 High-Bandwidth Memory (HBM), 68, 133 High-performance computing (HPC), 13 High-performance parallel programs, 14 kernel, 203, 208, 214, 216, 217, 220 Improved memory coalescing, 235 Improving memory coalescing, 298 threads, 75, 80, 230, 266, 286, 298 Inclusive scan operation, 252, 253 Incomplete tiles, 391, 392, 394 Independent thread scheduling, 80 block, 41, 45, 165, 215, 244, 245, 269, 277, 278, thread, 45, 60, 63, 75, 165, 171, 216, 229, 239, execution overhead, 139, 141, 142, 151, 369 Instruction Register (IR), 78, 79 Interleaving memory access, 367 Intrinsic functions, 70, 294, 295, 500 Irregular access patterns, 150, 151 loop, 62, 81, 142, 144, 146, 147, 167, 171, 216, iterative method, 542, 545, 546, 549, 557, 563, kernel, 548, 549, 555–557, 559, 561, 562 format, 150, 151, 416–418, 421 call, 24, 40, 41, 45–47, 117, 273, 274, 386, 388, 500, 501, 517, 555–561, 563, 564 code, 26, 35, 50, 52, 67, 69, 114, 117, 118, 169, 213, 230, 260, 266, 338, 352, 354, 376, 394, 432, 434, 436, 487, 496, 519, 521 convolution, 159, 160, 165, 167, 168, 191 CUDA, 34, 37, 39, 65, 86, 90, 93, 119, 120, 154, 160, 207, 379, 386, 392, 459, 474, 486, execution, 40, 64, 103, 137, 168, 169, 171, 213, function, 15, 28, 30, 32, 35–37, 45–47, 50, 98, histogram, 203, 208, 214, 216, 217, 220 matrix multiplication, 62, 64, 92, 97, 114, 115, parallel scan, 258, 268, 271, 284 reduction, 227, 237, 257, 270, 275 thread coarsening, 195, 196, 198 performance considerations, 577 algorithm, 254, 255, 260, 266, 282, 284 cache arithmetic intensity, 504 caching, 479, 488, 491, 492, 504 Large Language Model (LLM), 477–479, 510 memory access, 11, 118, 209, 210, 364 Leader thread, 245, 278, 279, 292–294 Least-significant bit (LSB), 346 Least-significant digit (LSD), 346 Linear algebraic formulation, 438 Linear algebraic formulation of graph problems, 438 vector, 138, 151, 155, 272, 356, 369, 370 iteration, 62, 81, 142, 144, 146, 147, 167, 171, 216, 219, 257–259, 261, 265, 366 nest, 111, 167, 171, 175, 176, 359 unrolling, 123, 144–146, 149, 270, 271, 363, 364 elements, 64, 65, 96, 107, 468, 494, 539 multiplication, 45, 59, 60, 96, 127, 349, 350 example, 63, 104, 105, 117, 128 kernel, 62, 64, 92, 97, 114, 115, 141, 363, operations, 96, 97, 350, 368, 463 access, 4, 114, 128, 176, 208, 230, 258, 314, efficiency, 303, 314, 404–406, 409, 412, instructions, 364, 366, 368–370, 519 latency, 11, 118, 209, 210, 364 pattern, 112, 113, 127, 128, 150, 216, 360, throughput, 4, 5, 124, 137, 209 bandwidth, 5, 93, 94, 111, 130, 133, 136, 138, 167, 176, 185, 272, 273, 314, 320, 327, 364, 370, 401, 403, 410, 475, 492, 523, 578 coalescing, 123, 124, 129, 150, 193, 216, 234, 298, 299, 314, 339, 340, 369, 410, 413, constant, 16, 98, 103, 118, 153, 168, 169, 171, copy, 30, 169, 555, 560, 561, 563 location, 111, 113, 131, 147, 150, 204, 206, 209, 210, 235, 293, 298, 300, 333, 340, 360, requirements, 504–506, 508, 509 operation, 289, 303–306, 308, 333, 334, 347, parallel, 16, 308, 313, 328, 535 sort, 16, 304, 329, 330, 333, 334, 346, 374, 530, Message Passing Interface (MPI), 12, 541, 545 non-blocking communication, 551 Mixture of Experts (MoE) technique, 510 Model service optimization, 507 Most-significant digit (MSD) radix sort, 346 Multi-GPU stencil, 545, 563, 568 Multi-layer perceptron (MLP), 604 Multi-query attention (MQA), 508 Multiple-Instruction-Multiple-Data (MIMD), 79 Multiple-Instruction-Single-Data (MISD), 79 National Institute of Health (NIH), 6 Natural language processing (NLP), 477 Necessitating optimizations, 251 grid points, 187, 188, 521, 542 Nested loops, 58, 59, 354, 378, 499, 501, 511, 518 NVIDIA Collective Communications Library NVIDIA CUDA Compiler (NVCC), 39, 369 NVIDIA OpenSHMEM Library (NVSHMEM), Occupancy, 85, 90, 135, 144, 149, 363 thread, 115, 138, 144, 149, 363 Odd-even transposition sort, 331 One-sided communication, 569, 570, 575 Open Compute Language (OpenCL), 13 merge, 289, 303–306, 308, 333, 334, 347, 499, reduction, 221, 223, 224, 240, 280, 543, 545, scan, 252, 261, 262, 265, 267, 270, 272, 273, stable filter, 289, 297, 301, 336 Optical character recognition (OCR), 454, 612 techniques, 11, 15, 176, 201, 219, 223, 249, 254, Optimizing parallel patterns, 286, 347 parallelization, 141, 152, 153, 193, 246, 267 synchronization, 12, 141, 146, 152, 237, 241, Overlapping computation, 541, 553, 554, 559, 563, Padding elements, 362, 410–413, 415 algorithms, 11, 16, 17, 102, 153, 159, 179, 226, 251, 253, 265, 266, 401, 529, 530 application, 3, 9, 15, 118, 422 code, 12, 21, 123, 204, 539, 577 computation, 16, 26, 201, 251, 285, 401 computation patterns, 12, 154, 159, 179, 308, computing, 7, 14, 40, 159, 164, 211, 401, 532, execution, 7, 9, 12, 13, 24, 55, 124, 137, 216, 249, 266, 329, 374, 518, 523, 524, 530–532 hardware execution resources, 248 implementations, 9, 266, 270, 282, 289, 302, patterns, 7, 12, 14, 15, 64, 123, 151, 221, 286, 303, 396, 401, 421, 422, 529, 577, 579 program, 2, 3, 11, 12, 21, 111, 123, 254, 539, programmer, 13, 21, 110, 401, 523, 529, 530 programming, 2, 3, 7, 11, 14, 118, 529, 531, 578 reduction, 221, 223, 224, 246, 249 scan, 251, 254, 256, 259, 261, 267, 270, 280, sorting algorithms, 16, 329, 331, 347 approach, 306, 337, 405, 408, 419 overhead, 141, 152, 153, 193, 246, 267 Parameter values, 32, 209, 453, 454 Partial differential equation (PDE), 179 computation, 16, 153, 187, 221, 460 convolution, 56, 151, 153, 463, 474 memory access, 112, 113, 127, 128, 150, 216, stable filter, 329, 336, 534, 535 computational throughput, 94, 118 performance, 3, 4, 111, 272, 274, 276 considerations, 16, 123, 154, 166, 540 optimization techniques, 140, 331, 529 Periodic boundary condition technique, 551 Point-to-point communication, 549 Pointer variable, 26, 29, 30, 50 Private copy, 102, 152, 211–213, 442 Privatization, 152, 211, 295, 442 Privatized histogram kernel, 213 Processing element (PE), 570, 574 parallel, 13, 21, 110, 401, 523, 529, 530 Provisioned access throughput, 132 Public copy, 152, 153, 211, 213, 214, 442 Race condition, 205, 257, 331, 332, 433 sort, 251, 329, 330, 334–336, 340, 342, Read-after-write dependence, 110, 146, 147 Read-modify-write race condition, 205 Reduce-scan-scan decomposition, 275, 276, 280 kernel, 227, 228, 237, 257, 270, 275 operation, 221, 223, 224, 240, 280, 543, 545, parallel, 221, 223, 224, 246, 249 tree, 223, 225–228, 238, 244, 246, 255, 258, global memory accesses, 273, 285, 539 tiling, 112, 123, 149, 151, 190, 196, 252, 270, Resource utilization efficiency, 231 Retrieval-augmented generation (RAG), 481 Return value, 29, 209, 240, 293, 308, 442 Returned value, 42, 209, 293, 320 Scalable parallel execution, 21 kernel, 257, 270, 272, 273, 285 operation, 252, 261, 262, 265, 267, 270, 272, 273, 276, 277, 298, 299, 301, 535 parallel, 251, 254, 256, 259, 261, 267, 270, 280, Scan-scan-add decomposition, 261, 276, 280 block segment, 263, 268, 269, 281 block, 215, 216, 268–270, 273, 275, 277 Shared memory, 69, 99, 139, 151, 152, 236 tiling, 104, 123, 151, 153, 168, 171–173, 189, Single Instruction, Multiple Thread (SIMT), 76, 77 Single Program Multiple Data (SPMD), 15 Single-block reduction kernel code, 245 Single-Instruction-Multiple-Data (SIMD), 79 Single-Instruction-Single-Data (SISD), 79 Single-Program Multiple-Data (SPMD), 32, 33 Small dynamic programming problems, 398 Smith-Waterman algorithm, 382, 384 Softmax function, 478, 484, 490 Source code, 36, 38, 52, 60, 552 Space efficiency, 403, 410, 414, 416 Speculative decoding, 492, 504, 507 Static Random Access Memory (SRAM), 69 Statically allocated arrays, 50, 98 computation, 183, 189, 198, 352, 396, 542, 543, patterns, 55, 151, 153, 183, 193, 196, 198 Stochastic gradient descent, 607 instructions, 138, 142, 360, 361 Streaming Multiprocessor (SM), 68, 69, 89, 93 Stride value, 232, 233, 257, 263 Symmetric memory allocation, 570 overhead, 12, 141, 146, 152, 237, 241, 258, 261, Synchronous Dynamic Random Access Memory Tensor Memory Accelerator (TMA), 369, 504 Terra floating-point operations per second block, 24, 33, 63, 99, 124, 165, 168, 188, 191, 207, 208, 230, 237, 256, 257, 296, 315, 333, 350, 351, 379, 381, 442, 443, 459, size, 38, 41, 81, 91, 176, 195, 246, 328, 363, coarsening, 73, 141, 142, 152, 190, 193, 194, 214, 246, 252, 267, 268, 298, 299, 327, 344, 345, 352, 488, 519, 521, 530, 535, 543 granularity coarsening, 123, 154, 246 grid, 27, 33, 35, 37, 69, 379, 517, 519, 556 indices, 45, 60, 63, 75, 165, 171, 216, 229, 239, occupancy, 115, 138, 144, 149, 363 organization, 34, 48, 173, 174, 177, 460, 461 subsegments, 268, 271, 272, 281 atomic operations, 209–211, 213 matrix multiplication, 112, 368, 369 memory access, 4, 5, 124, 137, 209 elements, 109, 110, 130, 319–321, 498, 500, 503 size, 107, 130, 180, 192, 193, 195, 320, 352, 472 convolution kernel, 173, 176, 177, 191 matrix multiplication, 112, 116, 155, 173, 351, matrix multiplication kernel, 108, 112, 114, 142, parallel convolution implementation, 179, 180 registers, 112, 123, 149, 151, 190, 196, 252, techniques, 112, 119, 124, 183, 185, 303, 327, Training multi-layer classifiers, 611 Transparent scalability, 70, 74 True dependence, 110, 146, 147, 258, 366 Two-sided communication, 549, 568 Unidirectional synchronization, 277 device memory address space, 624 Unified Virtual Address Space (UVAS), 625 Unified Virtual Address (UVA), 35 Unoptimized sequential code, 518 addition, 26, 28, 31, 41, 96, 151 addition kernel, 37, 96, 138, 142, 155 loads, 138, 151, 155, 272, 356, 369, 370 specialization, 367, 368, 370, 504 Warp Group Matrix Multiply Accumulate Warp-level primitives, 77, 152, 237, 261 parallelization performance, 389 Write-after-read dependence, 110, 146, 147 Zero-overhead thread scheduling, 84