Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CUDA Kernels: GPU & Parallel Programming from First Principles

A comprehensive, no-fluff guide to GPU and parallel programming with CUDA: the hardware model, fully documented CUDA C++ kernels, modern C++ idioms, and GPU kernels in pure Rust with CUDA-Oxide - all wrapped around a complete image-processing capstone project.

NVIDIA CUDA NVIDIA GPU C++20 Rust CUDA-Oxide

mdBook GitHub Pages License: MIT Contributor Covenant

Read the book

https://arpanpathak.github.io/gpu-parallel-book/

What is inside

  • Part I - Foundations of GPU Computing (Chapters 1-3): the mathematics of parallelism (Amdahl, Gustafson, the roofline model), the GPU hardware model (warps, streaming multiprocessors, the memory hierarchy), and the CUDA programming model.
  • Part II - Writing CUDA C++ Kernels (Chapters 4-6): memory management and data movement, synchronisation/atomics/race conditions, and streams/events for asynchronous execution.
  • Part III - Optimisation & Advanced Patterns (Chapters 7-9): memory optimisation, reduction/scan/histogram, and optimised matrix multiplication.
  • Part IV - Modern C++ & The CUDA Ecosystem (Chapters 10-12): RAII and modern C++ idioms, the Thrust/CUB/cuBLAS libraries, and NVRTC runtime compilation with the driver API.
  • Part V - Rust, CUDA-Oxide & Safe GPU Programming (Chapters 13-15): Rust host code with cudarc, NVIDIA's experimental CUDA-Oxide Rust-to-CUDA compiler, and the image-processing capstone.
  • Part VI - The Engineering Mindset (Chapter 16): profiling with Nsight Compute, debugging with Compute Sanitizer, and reproducible performance engineering.

Plus a foreword, an epilogue, and three appendices (CUDA API reference, mathematical notation, recommended reading).

Highlights

  • Every concept explained from first principles; every primitive (type, built-in variable, API call) defined before use.
  • Every code block fully commented, with the reasoning for each design decision.
  • A complete capstone: an RGB -> greyscale -> Gaussian blur -> Sobel pipeline, implemented three ways (hand-written CUDA C++, Thrust, CUDA-Oxide Rust), streamed with pinned memory and verified against a CPU reference.
  • A Night Owl inspired dark theme (bluish-black, easy on the eyes) with full support for printing.

Cloud GPUs: learn without owning hardware

Every kernel in this book runs on any NVIDIA GPU with CUDA 12.x - including the free ones. If you do not own a GPU, start in the cloud; most providers give away enough free compute to finish the entire book.

Provider What you get Free credits (approx.; check current terms) Best for
Google Colab Free T4 GPU in browser notebooks Free tier with dynamic session limits First kernels, zero setup
Kaggle Notebooks Free GPU hours (T4/P100) Roughly 30 GPU hours per week Notebook-based learning
Google Cloud Full GPU/TPU VMs (L4, A100, H100) Roughly USD 300 new-account trial Serious projects
Microsoft Azure NC/ND-series GPU VMs Roughly USD 200 new-account credit Enterprise stack
AWS g4dn/g5/p4 GPU instances Free tier is CPU-only; Activate/Educate credits for startups and students Enterprise stack
Paperspace / Gradient GPU notebooks + cloud workstations Small signup credit; free notebook tiers One-click ML
Lambda RTX 4090 / A100 / H100 on demand None typically High-end training
RunPod Pay-as-you-go + serverless GPU Occasional promos Flexible jobs
Vast.ai Community GPU marketplace None Cheapest spot GPUs
NVIDIA LaunchPad Time-boxed hands-on labs on NVIDIA hardware Free labs Trying NVIDIA tech hands-on
Modal Serverless GPU Python Roughly USD 30/month recurring credits Code-first workloads

Notes:

  • Free-credit amounts and session limits change frequently. Always check the provider's current terms before signing up.
  • Everything this book teaches fits in a free tier: the heaviest capstone pipeline runs in minutes on a T4.
  • When you outgrow the free tiers, pay-as-you-go GPU providers (Lambda, RunPod, Vast.ai) are usually cheaper than the big three clouds for GPU-only work.

Repository layout

gpu-parallel-book/
β”œβ”€β”€ LICENSE                      # MIT license
β”œβ”€β”€ CODE_OF_CONDUCT.md           # Contributor Covenant 2.1
β”œβ”€β”€ CONTRIBUTING.md              # How to contribute (read this first)
β”œβ”€β”€ SECURITY.md                  # How to report vulnerabilities
β”œβ”€β”€ CODING_STANDARDS.md          # The book's constitution
β”œβ”€β”€ .github/workflows/
β”‚   └── deploy-pages.yml         # GitHub Actions -> GitHub Pages
└── book/
    β”œβ”€β”€ book.toml                # mdBook configuration
    β”œβ”€β”€ custom.css               # Night Owl dark theme
    └── src/                     # Markdown source of the book

Building locally

Requires mdBook v0.5.x:

mdbook build book       # compile to book/book/
mdbook serve book       # live preview at http://localhost:3000

Contributing

Corrections, clarifications and missing concepts are all welcome. Please read CONTRIBUTING.md and CODE_OF_CONDUCT.md first. If you find a bug in a kernel, a formula, or a number, open an issue - the book is a living document.

License

MIT. See LICENSE for details.

About

πŸ“– GPU parallel programming from the ground up : CUDA C++ and Rust πŸ¦€ kernels paired with clickable SVG 2D/3D architecture diagrams (warps, SMs, memory tiers). Includes reduction, scan, matmul, and a full image‑processing capstone

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

36 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages