Leanpub Header

Skip to main content

CUDA Programming from Scratch

From First Principles to Production-Grade GPU Applications

This book is 100% completeLast updated on 2026-07-13

Learn CUDA programming from the ground up by understanding how GPUs really execute code. This book shows you how to write efficient kernels, optimize performance, and build high-performance applications for AI, scientific computing, image processing, and other demanding workloads on modern NVIDIA GPUs, including Blackwell.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
90
Pages
About

About

About the Book

This book takes you from absolute beginner to advanced practitioner in CUDA programming. You will learn how GPUs execute code, how to design kernels that exploit parallelism at every level of the hardware hierarchy, and how to profile, debug, and optimize production applications. By the end, you will be able to write high-performance GPU code spanning AI training pipelines, scientific simulations, image processing, and high-performance computing using modern CUDA through the Blackwell architecture.

Bundle

Bundles that include this book

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 400 engineers and researchers from Ukraine, Belarus and Russia. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

CUDA Programming from Scratch

  1. From First Principles to Production-Grade GPU Applications

Introduction: Why GPU Computing Matters Today

Chapter 1: The GPU Revolution — Architecture and History

  1. From Graphics to General-Purpose Computing
  2. GPU vs CPU: Divergent Design Philosophies
  3. The CUDA Platform Ecosystem
  4. GPU Architecture Roadmap: Fermi through Blackwell

Chapter 2: The CUDA Programming Model — Threads, Blocks, and Warps

  1. SIMT Execution: Single Instruction, Multiple Threads
  2. Thread Hierarchy: Threads, Warps, Blocks, Grids, and Clusters
  3. Kernel Launch Syntax and Configuration
  4. The Grid-Stride Loop Pattern
  5. Occupancy: Theory, Calculation, and the Occupancy API

Chapter 3: Memory Models — The GPU Memory Hierarchy

  1. Registers and Local Memory
  2. Global Memory and Coalesced Access
  3. Shared Memory: Scope, Latency, and Bank Conflicts
  4. Constant and Texture Memory
  5. L1/L2 Cache Architecture
  6. Memory Alignment and Vectorized Access

Chapter 4: Writing and Optimizing Kernels

  1. Your First CUDA Kernels: Vector Addition, Matrix Multiply
  2. Tiling and Shared Memory Optimization
  3. Avoiding Bank Conflicts: Padding and Swizzling
  4. Warp-Specialized Kernels and Producer-Consumer Patterns
  5. Common Pitfalls: Divergence, Race Conditions, Out-of-Bounds

Chapter 5: Synchronization — From Warps to Grids

  1. Warp-Level Synchronization (Implicit and Explicit)
  2. Block-Level Barriers (syncthreads)
  3. Cooperative Groups: Thread Block Tiles, Cluster Groups, Grid Groups
  4. Scoped Atomics and Thread Scopes
  5. Asynchronous Barriers and cuda::barrier (Hopper+)

Chapter 6: Warp-Level and Intrinsics Programming

  1. Warp Shuffle Primitives: __shfl_sync, __shfl_down_sync, __shfl_up_sync, __shfl_xor_sync
  2. Vote and Mask Operations: __ballot_sync, __any_sync, __all_sync, __activemask
  3. Warp-Level Reductions and Scans
  4. Inline PTX Assembly for Performance-Critical Code
  5. When to Use Warp Primitives vs. Cooperative Groups

Chapter 7: Asynchronous Execution — Streams, Events, and Overlap

  1. CUDA Streams: Default and User-Created
  2. Events for Synchronization and Timing
  3. Overlapping Data Transfers with Computation
  4. Multi-Stream Pipelining Patterns
  5. CUDA Graphs: Capture, Replay, and Constant-Time Launch

Chapter 8: Unified Memory and Advanced Memory Management

  1. The Problem with Explicit Host-Device Transfers
  2. cudaMallocManaged and Page Migration Engine
  3. Pinned (Page-Locked) Memory
  4. Unified Memory Performance: When It Works, When It Doesn’t

Chapter 9: Tensor Cores and Mixed-Precision Computing

  1. Evolution of Tensor Cores: Volta through Blackwell
  2. Matrix Multiply-Accumulate (MMA) Operations
  3. Data Precision Formats
  4. Writing Tensor Core Kernels with WGMMA
  5. The Transformer Engine and Dynamic Scaling

Chapter 10: Hopper Innovations — TMA, Barriers, and Pipelines

  1. Tensor Memory Accelerator (TMA): Architecture and Programming Model
  2. cuda::memcpy_async and Asynchronous Data Copies
  3. CUDA Pipelines: Producer-Consumer Patterns with Multi-Buffering
  4. Warp-Specialized Kernels for Maximum Utilization
  5. Cluster-Sized Thread Blocks and GPC-Level Scheduling

Chapter 11: CUDA Libraries — Building on NVIDIA’s Foundation

  1. Linear Algebra: cuBLAS, cuSOLVER, cuSPARSE
  2. Signal Processing: cuFFT
  3. Parallel Primitives: CUB and Thrust
  4. Random Numbers: cuRAND
  5. Image and Video: NPP, nvJPEG, nvCodec
  6. When to Use Libraries vs. Custom Kernels

Chapter 12: Dynamic Parallelism and Multi-GPU Programming

  1. Dynamic Parallelism: Child Kernels, Nested Launches
  2. Multi-GPU Architecture: PCIe vs NVLink
  3. Peer-to-Peer Memory Access (GPUDirect P2P)
  4. NCCL: Collective Communication Primitives
  5. Multi-GPU Design Patterns and Scaling Considerations

Chapter 13: Profiling, Debugging, and Performance Engineering

  1. CUDA-GDB and Nsight Debugger
  2. Compute Sanitizer: memcheck, racecheck, synccheck, initcheck
  3. Nsight Systems: System-Wide Profiling
  4. Nsight Compute: Kernel-Level Metrics and Analysis
  5. The APOD Framework (Assess, Parallelize, Optimize, Deploy)
  6. Performance Engineering Case Studies

Chapter 14: Real-World Applications — AI, HPC, and Scientific Computing

  1. Convolutional Kernels for Image Processing
  2. Matrix Multiplication at Scale: From Naive to Tensor Core Optimized
  3. Sparse Linear Algebra for Scientific Computing
  4. AI Training and Inference Pipelines
  5. Mini-Project: GPU-Accelerated Particle Simulation

Conclusion: The Future of GPU Computing

References

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

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.)

In fact, authors have earned over $15 million writing, publishing and selling 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