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-01

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

Share this book

Bundle

Bundles that include this book

Author

About the Author

Steve T. Publications

Steve T. is a cybersecurity leader, researcher, and engineer with more than 20 years of experience across application security, infrastructure security, vulnerability management, software development, and secure engineering practices. Having built his career alongside the growth of the modern internet, he has worked through multiple generations of technology, evolving security threats, and changing development methodologies.

He is currently part of the advanced research organization at a leading cybersecurity company, where he focuses on emerging threats, security innovation, and the practical application of research. His work involves investigating new attack techniques, evaluating emerging technologies, conducting deep technical analysis, and helping organizations better understand and manage complex security risks.

In addition to his research responsibilities, Steve leads a team of senior engineers and subject matter experts who create technical books, training programs, and educational resources for security professionals. Through this work, he helps engineers, developers, architects, and security practitioners strengthen their skills and build more secure systems.

Steve's technical expertise spans software development, reverse engineering, web application security, penetration testing, security architecture, incident response, vulnerability research, operating system internals, and secure software development. His ability to analyze systems at both the source code and binary levels enables him to bridge the worlds of software engineering, security research, and practical defense.

Over the course of his career, Steve has worked with organizations across a wide range of industries, helping them identify, assess, and remediate security weaknesses in critical applications and infrastructure. He is recognized for combining deep technical expertise with a pragmatic approach to security, focusing on solutions that are effective, sustainable, and aligned with business goals.

Through his work in research, engineering, leadership, and education, Steve continues to contribute to the advancement of cybersecurity and the development of secure, resilient technology systems.

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