Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: (美)Nicholas Wilt

Rating No ratings yet

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A deep, architecture-first guide to CUDA for developers who already write GPU code and want to understand why it runs fast or slow—covering hardware internals, memory models, concurrency, and advanced optimization patterns with concrete, measurable examples. 【Book Arc】 - **Opening (~0%–11%)**: Sets the stage with GPU history and the shift to heterogeneous CPU+GPU computing, then lays out the book’s three-part structure: hardware/software architecture, programming model, and advanced case studies. Establishes why bottleneck analysis must precede optimization. - **Early (~11%–33%)**: Dives into hardware foundations—virtual memory, page tables, TLB behavior, and the host interface—then explains the CUDA runtime vs. driver API split, context management (including the floating-context trick for multi-GPU), and introduces streams/events as the coarse-grained concurrency mechanism. Also covers host memory types (pageable vs. pinned) and why pinned memory enables async copies. - **Middle (~33%–56%)**: Moves into the programming model proper: global/static/shared memory allocation, cache behavior across SM 2.x and 3.x, warp-level memory access patterns, and the cost of CPU/GPU synchronization. Includes practical measurement experiments (e.g., null kernel launch overhead) and a first look at reduction kernels—the book’s recurring example. - **Late (~56%–78%)**: Explores the SM instruction set (SASS), special function units (SFU) and their precision trade-offs, then covers multi-GPU programming via peer-to-peer addressing and copy, plus texture and surface memory in depth—including pitch, normalized coordinates, and the new-in-Fermi surface read/write intrinsics. - **Ending (~78%–100%)**: Focuses on advanced algorithm patterns: warp-level reductions using shuffles and atomics, parallel scan (prefix sum) with circuit diagrams and recursive implementations, and a full case study on normalized cross-correlation for image matching—showing how to combine texture cache, shared memory, and tiling for real performance gains. 【Key Takeaways】 - **Bottleneck analysis before optimization** (Opening): Profile to find the actual hotspot (GPU kernel vs. data transfer) before touching code; optimizing the wrong part wastes effort. Use timing code or profilers to quantify first. - **Pinned memory is the gateway to async transfers** (Early): Pageable memory can’t be accessed by the GPU directly; CUDA uses staging buffers. Pinned (page-locked) memory enables faster copies, async operations, and even direct kernel access via mapped memory—critical for hiding transfer latency. - **Streams and events are the coarse-grained concurrency toolkit** (Early): They let you overlap CPU/GPU work, DMA copies with kernel execution, and even run multiple kernels or GPUs in parallel. Operations within a stream are serial; concurrency comes from using multiple streams. - **Context management is a hidden performance lever** (Early): The driver API’s push/pop context stack lets a single thread drive multiple GPUs or libraries create “floating” contexts without knowing their caller. On WDDM (Windows Vista+), popping a context with pending commands triggers a kernel thunk—avoid it for speed. - **Cache behavior varies by architecture—know your SM** (Middle): SM 2.x caches global memory in L1; SM 3.x doesn’t (use `__ldg()` or `const __restrict__` to route through texture cache). Shared memory vs. L1 cache split is configurable on SM 3.x. These details change which optimization works. - **Synchronization is expensive—measure it** (Middle): Full CPU/GPU syncs (e.g., synchronous memcpy) can cost ~8 microseconds per call on real hardware. Async operations and careful stream usage hide driver overhead; even in CUDA 1.0, kernel launches were async. - **Warp-level primitives beat shared memory for reductions** (Late): Shuffle instructions, atomics, and memory fences let you implement single-pass reductions without multiple kernel launches or shared memory bank conflicts. This is the modern pattern for high-performance reductions. - **Texture and surface memory are specialized tools, not defaults** (Late): Textures offer hardware filtering, normalized coordinates, and cache-friendly access for read-only data; surfaces (SM 2.x+) add write access to CUDA arrays. Use them when the access pattern fits—e.g., image processing with overfetch and boundary handling. 【Reading Tips】 - **Skim the historical intro (Ch. 1) and jump to Ch. 2–3 for architecture**: The early GPU history is interesting but not actionable. The hardware diagrams and memory-model explanations in Ch. 2–3 are the foundation for everything later—read them carefully. - **Deep-read Ch. 5 (memory) and Ch. 6 (streams/events)**: These are the most practically useful chapters for everyday CUDA coding. The pinned-memory discussion and the concurrency experiments (e.g., `concurrencyMemcpyKernel.cu`) directly translate to real performance wins. - **Treat Ch. 8 (SM instruction set) as a reference, not a cover-to-cover read**: The SASS-level details and SFU precision tables are valuable when you’re optimizing hot loops, but you don’t need them upfront. Bookmark the tables and come back when profiling points to arithmetic bottlenecks. - **Work through the reduction and scan examples (Ch. 12–13) with code in hand**: These are the book’s core algorithmic case studies. The progression from simple to optimized versions (atomics, shuffles, zero-padding, templates) is the best way to internalize the optimization mindset. - **Expect some dated material**: The book references CUDA 5.0, Fermi/Kepler architectures, and AWS EC2 instances from that era. Modern GPUs (Volta+) have changed some details (e.g., independent thread scheduling, different cache hierarchies), so cross-check with current NVIDIA docs for the latest hardware. 【Coverage Limits】 This guide synthesizes the provided excerpts, which cover roughly the first 15 chapters and the glossary. The book’s later chapters (beyond Ch. 15) and any appendices are not represented here.
Excerpt 1
书名: CUDA专家手册:GPU编程权威指南 (高性能计算技术丛书) ((美)Nicholas Wilt) (z-library.sk, 1lib.sk, z-lib.sk) 作者: (美)Nicholas Wilt 推荐序 自CPU单核性能在2004年左右停止提升后,功耗的限制及大量并行 应用本身的特点决定了多...
View in text
Excerpt 2
动程序架构中,压入和弹出上下文的成本足够廉价, 所以一个单线程应用程序可以保持多个GPU同时忙碌。对只在Windows Vista和其后续版本中的WDDM驱动程序,弹出当前上下文操作只在没有 GPU命令挂起的时候才能快速运行。当有命令挂起,驱动程序会引发内 核转换,以保证在弹出CUDA上下文之前提交挂起的命令 [...
View in text
Excerpt 3
提交到GPU,并在GPU处理完 毕之前将控制权返回给调用者。 我们可以通过发射一系列用计时操作包围的空内核启动来测量驱 动程序的开销。代码清单6-1展示了nullKernelAsync.cu,它是一个测 量执行内核启动所需时间的小程序。 代码清单6-1 nullKernelAsync.cu. 及一个异步的设备到主...
View in text
Excerpt 4
2.2 节)。 7.3.3 线程块与线程ID 一组特殊的只读寄存器会以线程ID和线程块ID的形式提供每个线 程的上下文。线程与线程块ID会在一个CUDA内核开始执行时分配。对 CUDA确保在所有子网格完成之前,父网格是不会完成的。虽然父 网格与子网格可以并发执行,但这却不能保证一个子网格会在它的父 网格调用cud...
View in text
Excerpt 5
写操作的唯一方式就是 将纹理引用与线性设备内存进行绑定。 但若使用流处理器簇2.x上新增加的表面内存读写函数,开发者可 以将CUDA数组与表面引用进行绑定,并调用surf1Dread()与 surf1Dwrite()指令,对内核中的CUDA数组执行读写操作。与拥有特有 硬件缓存的纹理读取不同,表面内存的读写操作将...
View in text
Excerpt 6
述公式符号的C语言变量表示: 15.4 共享内存中的图像 对于那些供我们的示例程序计算相关值的矩形来说,CUDA内核程 序展示了同模板匹配的图像的像素是如何被大量复用的。目前为止, 我们的代码仅依靠纹理缓存而不需要外部存储便可以进行大量的读取 操作。然而,对于更小的模板,通过使用共享内存可以使得图像数据 得到更低...
View in text
Tags
AI categories
Programminggpuparallel computing
ISBN: 7111472659
Language: Chinese
File Format: PDF
File Size: 9.8 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…