Leanpub Header

Skip to main content

Production CUDA for C++ Engineers

Optimizing Warp-Level Primitives and Shared-Memory Tiling with Nsight.

Production CUDA for C++ Engineers
This book is 100% completeLast updated on 2026-12-03

A kernel that hits 90% of peak bandwidth on one GPU can lose a third of that on the next generation with no source change. This book shows you why, and how to find it with Nsight before production does. Fifteen chapters, complete C++20 listings, every kernel checked against a CPU reference.

Minimum price

$29.00

$39.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
About

About

About the Book

Your kernel runs. Every launch succeeds. The sums are almost right.

That is the worst kind of CUDA bug. It's the warp reduction that relied on lockstep execution the hardware stopped promising. It's the tile size that fit one architecture's shared memory, or the single extra register that dropped a kernel from four blocks per SM to three. Nothing crashes, and you find out weeks later, in a number that is slightly off.

Production CUDA for C++ Engineers is about writing kernels that stay fast and correct across GPU generations, and about the profiling discipline that tells you, with evidence, when they aren't.

It doesn't sell you on GPUs. It assumes you write production C++ already. A GPU is treated as a throughput machine with specific constraints, and every optimization is tied to a profiler metric you can read: sectors per request, wavefronts per shared load, eligible warps per scheduler, the dominant warp stall.

Every chapter opens with a failure you may recognize and ends with a Kernel Ledger: the fraction of peak reached, the occupancy and dominant stall, and how correctness was verified. Every kernel is validated against a CPU reference, with the tolerance stated and derived, not guessed.

You will learn to:

  • Diagnose a slow kernel as memory-bound, compute-bound, or latency-bound from one Nsight Compute profile, using the roofline as the yardstick
  • Fix uncoalesced access, bank conflicts, spills, and occupancy cliffs, with counters before and after
  • Write warp-level code with explicit masks that survives independent thread scheduling
  • Build deterministic reductions and scans, and understand exactly when atomics break reproducibility
  • Pipeline loads with cp.async and TMA, and know why low-occupancy kernels can beat high-occupancy ones
  • Move from wmma to mma.sync to wgmma, use CUTLASS and CuTe, and choose precisions with error bounds you can defend
  • Overlap transfers and compute, capture work in CUDA Graphs, and scale across GPUs with NCCL
  • Use Nsight Systems, compute-sanitizer, and cuda-gdb on kernels that contain real, realistic faults
  • Ship it: fatbins and NVRTC, capture-safe C++ APIs, DCGM monitoring, Xid handling, and performance regression tests that fail the build

What makes it different

  • Measured claims, no hype. Performance is stated as typical ranges anchored to the roofline, never as invented benchmarks, and speedups are never measured against a naive CPU baseline.
  • Architecture-aware. Every hardware claim names the compute capability and notes where behavior changed, from Ampere through Hopper to Blackwell.
  • Production code. Modern C++20, every CUDA call checked through RAII wrappers, every warp primitive given an explicit mask, and the failure modes a live GPU system actually hits.
  • Failures you can reproduce. Labs with known bugs show what the sanitizer, the debugger, and the profiler actually report.
What's inside

Part I: Foundations. The GPU mental model for C++ engineers, SIMT, launch geometry, toolchains and CMake, error handling with RAII, and unified memory.

Part II: The Memory System. Coalescing, vectorized loads, the L1/L2 paths, the bandwidth roofline, bank conflicts and swizzling, tiling, asynchronous copies and TMA, registers, spills, occupancy, and instruction throughput.

Part III: The Execution Model. Warp shuffles, votes, cooperative groups, thread block clusters, divergence, reductions, scans, scoped atomics, histograms, tiled GEMM, tensor cores, CUTLASS and CuTe, and mixed precision.

Part IV: Concurrency and Scale. Streams, overlap, pinned memory, CUDA Graphs, peer-to-peer and NVLink, NCCL, MPS and MIG, and multi-GPU scaling.

Part V: Tools and Correctness. Nsight Systems and Nsight Compute in depth, compute-sanitizer, cuda-gdb, numerical reproducibility, and testing strategies for GPU kernels.

Part VI: Production. Libraries versus custom kernels, API design, fatbins, PTX JIT and NVRTC, stdpar, containers and driver compatibility, DCGM monitoring, Xid handling, and kernel performance regression testing.

Appendices. The CUDA memory and execution model, compute capability reference, an Nsight metrics reference, and a kernel optimization checklist.

Who this book is for
  • C++ engineers moving compute onto GPUs
  • Performance engineers handed a GPU budget
  • Quant, simulation, and inference developers whose CUDA works but needs to be fast and maintainable on more than one architecture
  • Anyone who has stared at an Nsight report and wanted to know which number to believe

Not for you if you need an introduction to C++ or parallel programming. The book assumes both from page one.

Prerequisites

Solid modern C++ (templates, RAII, the memory model). Basic parallel programming. A CUDA-capable GPU (compute capability 8.0 or later is ideal; the book notes where Hopper or Blackwell is needed). CUDA Toolkit 13.x, or 12.8 or later.

Bundle

Bundles that include this book

Author

About the Author

Weston Ashgrove

Weston Ashgrove is a C++ systems engineer who builds software where being wrong or slow has a cost. He came up through quantitative trading, building order books, matching logic and the low-latency infrastructure underneath them and now brings the same discipline to performance engineering, concurrency, storage, networking, GPUs, and AI inference.

His rule for performance-critical code is simple: nothing is true until it has been profiled, fuzzed, and replayed. Every technique in his books comes with the measurement that proves it, the trade-off it costs, and the failure it prevents. He writes for working engineers who ship and debug production C++, and he leaves out anything that only works on a slide.

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub