AdepojuJeremy/CUDA-120-DAYS--CHALLENGE

A 120-day CUDA learning plan covering daily concepts, exercises, pitfalls, and references (including “Programming Massively Parallel Processors”). Features six capstone projects to solidify GPU parallel programming, memory management, and performance optimization skills.

Shell

962

148 commits

updated Mar 29, 2025

See the code

README

Cuda-120-Days-Challenge

A 120-day CUDA learning plan covering daily concepts, exercises, pitfalls, and references (including “Programming Massively Parallel Processors”). Features six capstone projects to solidify GPU parallel programming, memory management, and performance optimization skills.

120-Day CUDA Curriculum

A structured, day-by-day plan to master NVIDIA CUDA programming over 120 days. Each day includes:

  • Core Topic
  • Practical Exercise / Mini-Project
  • Debugging Pitfalls
  • Resource Suggestions

Six Capstone Projects are spread out at Days 20, 40, 60, 80, 100, and 120 to synthesize the skills acquired.


Day-by-Day CUDA Curriculum

DayCore TopicPractical Exercise / Mini-ProjectDebugging PitfallsResource Suggestions
1Introduction to GPU Computing & CUDA(daily-updates/day-01-intro-cuda.md)Write a simple “Hello GPU” kernel that prints a message from one thread.Missing <cuda_runtime.h> or incorrect compiler flags.CUDA C Programming Guide, Introduction
2Setting Up the Development EnvironmentInstall CUDA Toolkit & drivers; compile and run sample codes.Incompatible driver/toolkit versions.Official “Getting Started” Guide
3GPU vs. CPU Architecture FoundationsCompare GPU SMs and CPU cores; discuss throughput vs. latency.Mixing CPU vs. GPU roles can lead to design inefficiencies.CUDA C Programming Guide, “Hardware Model Overview”
4Thread Hierarchy: Grids & BlocksLaunch a kernel using different grid/block dimensions, experiment with thread indexing.Off-by-one errors in thread indexing.CUDA C Programming Guide, “Thread Hierarchy”
5Thread Hierarchy: Warps (Intro)Inspect warp size and how threads are grouped (no direct warp programming yet).Divergence issues in the same warp.CUDA C Best Practices Guide, “Warps and SIMT Model”
6Basic Kernel Launch & ExecutionWrite a kernel for element-wise addition on a small array.Mixing up cudaMemcpyHostToDevice vs. cudaMemcpyDeviceToHost.CUDA Samples, Vector Addition
7Memory Model (Global Memory Basics)Transfer data to global memory, run a simple computation, transfer results back.Mismatched data sizes or forgetting to free GPU memory.CUDA C Programming Guide, “Global Memory Access”
8Memory Allocation & PointersUse cudaMalloc/cudaFree; practice error checking.Memory leaks if forgetting to free device pointers.CUDA C Programming Guide, “Memory Allocation”
9Memory Alignment & CoalescingBenchmark coalesced vs. non-coalesced memory accesses in a kernel.Non-contiguous access patterns hurt performance.CUDA C Best Practices Guide, “Memory Coalescing”
10Shared Memory FundamentalsImplement tile-based matrix multiplication using shared memory.Race conditions without thread sync.CUDA C Programming Guide, “Shared Memory”
11Thread Synchronization (__syncthreads())Extend tile-based multiplication with sync calls; measure performance.Missing __syncthreads() => partial updates.CUDA C Programming Guide, “Synchronization”
12Bank Conflicts in Shared MemoryTest an access pattern that causes bank conflicts; measure performance impact.Overlooking bank conflict in shared memory accesses.CUDA C Programming Guide, “Shared Memory Bank Conflicts”
13Basic Atomic OperationsUse atomicAdd to sum an array in parallel.Large-scale sums using atomics can degrade performance.CUDA C Programming Guide, “Atomic Functions”
14Progress CheckpointQuick recap or quiz: global vs. shared memory usage.Not consolidating learning => repeated mistakes.Review Days 1–13 notes; create a “lessons learned” list
15Advanced Atomic OperationsExperiment with atomicCAS, atomicExch, etc.Overusing atomics => performance bottlenecks.CUDA C Programming Guide, “Atomic Functions”
16Kernel Configuration TuningAdjust block sizes for the same kernel; observe occupancy changes.Non-multiples of warp size can lower occupancy.CUDA Occupancy Calculator (within Nsight Compute)
17Host-Device Synchronization PatternsUse cudaDeviceSynchronize() for timing; measure kernel durations.Missing sync => partial results readback.CUDA C Programming Guide, “Device Synchronization”
18Error Handling & cudaGetErrorString()Implement robust error checks after each CUDA call.Ignoring errors => hard-to-trace bugs.CUDA Error Handling
19Unified Memory (UM) IntroUse cudaMallocManaged; run simple vector addition.Forgetting that UM still migrates data.CUDA C Programming Guide, “Unified Memory”
20Capstone Project #1Image Convolution Pipeline: 2D convolution (e.g., edge detection) on GPU.––
21Streams & Concurrency (Basics)Launch two kernels in different streams; check overlap.Default stream is blocking if concurrency not enabled.CUDA C Programming Guide, “Streams”
22Events & TimingUse CUDA events for precise kernel timing.Misplacing events => skewed time measurements.CUDA C Programming Guide, “Events”
23Asynchronous Memory CopyCopy data using streams asynchronously.Not using pinned host memory => limited async.CUDA C Programming Guide, “Asynchronous Transfers”
24Pinned (Page-Locked) MemoryCompare pinned vs. pageable host memory transfers.Excessive pinned memory => system performance hit.CUDA C Programming Guide, “Pinned Memory”
25Double Buffering TechniqueImplement a two-buffer pipeline to overlap compute and transfer.Improper sync => reading incomplete data.CUDA Concurrent Kernels Sample
26Constant MemoryUse constant memory for read-only data (e.g., coefficients).Over the constant memory limit or forgetting read-only usage.CUDA C Programming Guide, “Constant Memory”
27Texture & Surface Memory (Intro)Sample a small 2D texture; compare vs. global memory fetch.Missing texture binding/unbinding steps.CUDA C Programming Guide, “Texture Memory”
28Progress CheckpointRecap concurrency & memory (short quiz or multi-topic mini-project).Gaps in concurrency knowledge => suboptimal performance.Review Days 15–27 notes
29Texture Memory (Practical)Implement image-processing kernel (e.g., grayscale) using textures.Incorrect normalized coordinates => invalid fetch.CUDA C Programming Guide, “Texture Reference”
30Surface MemoryWrite operations using surfaces (e.g., output image buffer).Coordinate boundary checks are critical.CUDA C Programming Guide, “Surface Reference”
31Unified Memory Deep DiveUse cudaMallocManaged with multiple kernels; measure page-fault overhead.Poor data locality => excessive page migration.CUDA Unified Memory
32Stream Sync & DependenciesEnforce execution order with events or cudaStreamWaitEvent().Forgetting to record an event => faulty sync.CUDA C Programming Guide, “Stream Synchronization”
33Intro to CUDA GraphsConvert a kernel sequence into a CUDA graph; measure performance.Mistakes in graph capture => unexpected results.CUDA C Programming Guide, “Graphs”
34Nsight Systems / Nsight ComputeProfile a small app to find bottlenecks; read kernel timelines.Misreading profiling data => false conclusions.Nsight Systems / Nsight Compute
35Occupancy & Launch Config TuningUse the Occupancy Calculator to refine block size for better SM use.Overlooking shared memory => reduced occupancy.CUDA C Best Practices Guide, “Occupancy”
36Profiling & Bottleneck AnalysisProfile matrix multiplication or similar; identify memory vs. compute limits.Only measuring compute => ignoring memory throughput (or vice versa).Nsight Compute Metrics
37Intro to Warp-Level PrimitivesUse warp shuffle instructions for a small parallel reduce.Divergence or incorrect shuffle masks can ruin results.CUDA C Programming Guide, “Warp Intrinsics”
38Warp DivergenceWrite a kernel with branching; measure performance difference.Excessive branching => warp serialization.CUDA C Best Practices Guide, “Minimizing Divergence”
39Dynamic ParallelismLaunch kernels from within a kernel to handle subdivided tasks.Over-launching can deplete resources quickly.CUDA C Programming Guide, “Dynamic Parallelism”
40Capstone Project #2Sparse Matrix-Vector Multiplication for large sparse data sets.––
41Advanced Streams & Multi-Stream ConcurrencyLaunch multiple kernels in parallel using multiple streams.Oversubscribing GPU with too many streams.CUDA C Programming Guide, “Streams”
42Progress CheckpointRecap concurrency, warp ops, dynamic parallelism.Missing these => issues in advanced topics later.Short quiz or combined mini-project for Days 29–41
43Efficient Data Transfers & Zero-CopyMap host memory into device space (zero-copy); measure overhead vs. pinned.Improper use => performance losses.CUDA C Programming Guide, “Zero-Copy”
44Advanced Warp Intrinsics (Scan, etc.)Implement a warp-wide prefix sum with __shfl_down_sync.Misaligned warp sync => incorrect partial sums.CUDA C Programming Guide, “Shuffle and Cooperative Groups”
45Cooperative Groups (Intro)Use cooperative groups for flexible synchronization within blocks or grids.Not all GPUs support advanced groups fully.CUDA C Programming Guide, “Cooperative Groups”
46Peer-to-Peer Communication (Multi-GPU)Enable P2P for direct data transfers (if you have multiple GPUs).GPU compatibility issues block P2P.CUDA C Programming Guide, “Peer-to-Peer Memory Access”
47Intermediate Debugging & Profiling ToolsUse cuda-gdb or Nsight Eclipse for step-by-step debugging.Missing sync can make debugging inconsistent.CUDA Debugger Docs
48Memory Footprint OptimizationReduce shared memory or register usage; measure occupancy.Overuse => occupancy drop.CUDA C Best Practices Guide, “Memory & Register Optimization”
49Thrust for High-Level OperationsReplace custom loops with Thrust transforms, sorts, reductions.Excessive device-host transfers if not structured well.Thrust Library
50Intro to cuBLASPerform basic vector/matrix ops with cuBLAS, compare to custom kernels.Type mismatches or library error handling.cuBLAS Library User Guide
51Intro to cuFFTImplement a simple 1D FFT on the GPU; measure performance.Incorrect sizing, padding => wrong results.cuFFT Library User Guide
52Code Optimization (Part 1)Loop unrolling or register usage tweaks; measure improvements.Over-optimizing => diminishing returns.CUDA C Best Practices Guide, “Kernel Optimization”
53Code Optimization (Part 2)Analyze PTX, apply instruction-level optimizations.PTX can vary across CUDA toolkit versions.PTX Tools, ptxas, cuobjdump
54Nsight Compute: Kernel AnalysisExamine occupancy, memory throughput, and instruction mix.Ignoring memory metrics => incomplete optimization approach.Nsight Compute Docs
55Intro to Device Libraries (cuRAND, etc.)Generate random numbers (cuRAND); run a Monte Carlo simulation.Misusing seeds or distribution params.cuRAND Library User Guide
56Progress CheckpointRecap concurrency (multi-stream), libraries, optimization.Fragmented knowledge => missed performance.Summarize library-based vs. custom kernels
57Robust Error Handling & DebuggingExpand error checking macros; advanced debugging with cuda-gdb.Release builds can hide errors if not checked.CUDA Runtime Error Handling
58Handling Large Data SetsChunk large arrays with streaming techniques.Possible out-of-range indices in chunk loops.CUDA C Best Practices Guide, “Large Data Handling”
59MPS (Multi-Process Service)Enable MPS for sharing GPU among multiple processes (if supported).Oversubscription => resource contention.NVIDIA MPS Documentation
60Capstone Project #3Multi-Stream Data Processing: Overlap transfers & kernels for real-time feeds.––
61GPU-Accelerated SortingUse Thrust’s sort; compare vs. CPU for large data.Memory bandwidth constraints.Thrust Sort Examples
62Stream Compaction & Parallel PatternsImplement parallel compaction (remove zeros) via Thrust or custom.Prefix sums must be correct or compaction fails.Thrust, Parallel Patterns
63Concurrency Patterns (Producer-Consumer)Pipeline kernels: one generating data, one consuming it.Missing sync can drop data.CUDA C Programming Guide, “Streams & Concurrency”
64Pinned + Unified Memory HybridUse pinned memory for input streaming, unified memory for intermediate results.Over-complicating memory usage => confusion.Unified vs. Pinned Memory Best Practices
65Collaborative Grouping TechniquesUse cooperative groups for advanced reductions.Not all GPUs support grid-level groups.CUDA C Programming Guide, “Cooperative Groups”
66Peer-to-Peer (P2P) & Multi-GPU ScalingSplit data across multiple GPUs if available.Mismatched driver/device IDs block P2P.Multi-GPU Programming
67GPU-Accelerated Graph Analytics (Intro)Simple BFS or PageRank with adjacency lists on the GPU.Random memory access => poor coalescing.NVIDIA Developer Blog (search for graph analytics)
68Memory Pool & Custom AllocatorsReuse device memory with a custom allocator to reduce cudaMalloc overhead.Not thread-safe under dynamic parallelism.cudaMallocAsync Docs
69Occupancy-Based Tuning for Large ProblemsMaximize occupancy on a large matrix multiplication.Register usage can limit occupancy.Nsight Compute Occupancy Analysis
70Progress CheckpointRecap concurrency patterns, advanced memory, multi-GPU.Small concurrency oversights => big issues.Review key lessons from Days 57–69
71Advanced Streams & OverlappingOverlap multiple kernels, data transfers, and CPU tasks.Missing sync => race conditions.Nsight Systems Docs
72CUDA Graphs: Complex WorkflowsMerge dependent kernels & copies into one CUDA graph.Missing finalization => incomplete runs.CUDA C Programming Guide, “Graph Best Practices”
73Dynamic Graph LaunchesBuild and launch graphs at runtime based on conditions.Too many small graphs => overhead.Nsight Documentation
74Multi-GPU Programming (Deeper Exploration)Distribute workload across two GPUs if hardware supports.Load imbalance if data not split evenly.Multi-GPU Programming
75Performance Metrics & Roofline AnalysisCollect memory throughput, FLOPS, chart on a roofline.Misreading memory/compute-bound => wrong optimization focus.NVIDIA Roofline Analysis Blog
76Mixed Precision & Tensor Cores (If Supported)Implement half-precision (FP16) matrix multiply on Tensor Cores.Precision trade-offs can break accuracy.CUDA C Programming Guide, “Tensor Core Programming”
77UM Advanced Topics (Prefetch, Advise)Use cudaMemAdvise, prefetch data to specific devices.Incorrect prefetch sizes => performance drop.CUDA Unified Memory
78Large-Scale Projects: Modular Kernel DesignSplit large kernels into smaller, manageable modules.Over-fragmentation => overhead from multiple launches.CUDA C Best Practices Guide, “Modular Kernel Design”
79Portability & Scalability Best PracticesAdjust code for various GPU architectures (SM versions).Hardcoding for a single GPU => poor portability.CUDA Toolkit Release Notes
80Capstone Project #4Multi-GPU Matrix Multiply: Split large matrix across 2 GPUs.––
81Cooperative Groups: Advanced PatternsTry a grid-level cooperative kernel needing all blocks to sync.Not all GPUs support grid-level sync.CUDA C Programming Guide, “Cooperative Launch”
82Large-Scale Batch ProcessingUse batched operations (cuBLAS batched GEMM) for efficiency.Wrong batch sizes => idle SMs.cuBLAS Documentation
83External Libraries (cuDNN, etc.)Integrate a small NN layer using cuDNN if possible.Version mismatches => runtime errors.cuDNN Library User Guide
84Progress CheckpointReflect on concurrency, multi-GPU, libraries.Missing synergy => suboptimal solutions.Short recap or quiz for Days 71–83
85Instruction Throughput ProfilingUse Nsight Compute to track instruction throughput for tight kernels.Ignoring special function units or double precision differences.Nsight Compute Docs
86Occupancy vs. ILPCompare effects of occupancy vs. ILP (Instruction-Level Parallelism).Forcing ILP might drop occupancy.CUDA C Best Practices Guide
87Custom Memory AllocatorsExtend your memory pool design with stream-ordered allocations.Race conditions if multiple streams allocate at once.cudaMallocAsync Docs
88Kernel Fusion & Loop FusionMerge multiple small kernels into a single kernel to reduce launch overhead.Oversized kernels can exceed register/shared limits.CUDA C Best Practices Guide, “Kernel Fusion”
89Algorithmic Optimizations (Tiling, Blocking)Refine tiling or blocking for matrix multiply, convolution, etc.Over-tiling => overhead > gains.GPU Gems, HPC papers on tiling strategies
90Minimizing Data TransfersUse pinned memory, async transfers, or kernel-side generation to limit PCIe overhead.Large single transfers might block concurrency.CUDA C Best Practices Guide, “Data Transfer”
91Enterprise-Level Code StructureExplore multi-file, multi-module approach with separate compilation.Linker errors if not using correct NVCC flags.CUDA C Programming Guide, “Separate Compilation and Linking”
92Advanced Debugging (Races & Deadlocks)Diagnose a race or deadlock in a complex multi-stream or multi-block scenario.Relying on __syncthreads() incorrectly => deadlock.CUDA Debugger Docs
93Real-Time GPU Computing TechniquesIf real-time constraints exist, explore low-latency execution patterns.GPU scheduling unpredictability if shared environment.NVIDIA Documentation on Real-Time GPU
94Host Multithreading + GPU CoordinationUse multiple CPU threads to launch kernels/manage streams concurrently.CPU thread contention can throttle the GPU.CUDA C Best Practices Guide, “Multi-threaded Host Code”
95CUDA Graph Updates & ReusabilityDynamically update parts of a CUDA graph without a full rebuild.Mishandling graph node handles => crashes.CUDA Graphs, advanced topics
96Precision & Numerical StabilityExamine rounding, float vs. double, iterative error accumulation.Small errors compound over iterations.Kahan Summation, HPC references
97Advanced P2P & Clustering (If Possible)Use GPU-GPU RDMA or multi-node scaling in a cluster environment.Not all hardware supports GPUDirect RDMA.GPUDirect RDMA Docs
98Progress CheckpointRecap advanced debugging, multi-threaded host, graphs, precision.Missing these => major issues in large apps.Summarize Days 85–97
99Graph API for Complex DAG WorkloadsBuild a multi-kernel DAG with conditional branches/loops using CUDA Graphs.Overcomplicated graph => overhead.CUDA Graph Examples
100Capstone Project #5CUDA Graph-Optimized Workload: Merge multiple kernels + copies into one graph.––
101GPU-Accelerated ML Frameworks (Intro)If possible, integrate a custom kernel/layer into TensorFlow or PyTorch.Version mismatches => build errors.PyTorch CUDA Extensions, TensorFlow Custom Ops
102CUDA + Other Parallel FrameworksExplore hybrid CPU/GPU parallelism (OpenMP, MPI).Partitioning complexities, oversubscription risk.MPI + CUDA Resources, HPC references
103Tuning GPU-Accelerated ML OpsProfile a small neural net or inference pipeline; identify GPU hotspots.Overlooking CPU-GPU sync or data pipeline bottlenecks.Nsight Systems for ML Frameworks
104Multi-GPU Scaling in MLDistribute training across multiple GPUs or data parallel approach.Communication overhead if poorly balanced.NCCL Library, multi-GPU references
105HPC: Memory Throughput & ComputationReview HPC patterns (PDE solvers, climate modeling) for GPU acceleration.Memory-bound kernels for large stencils.AMGX, HPC domain-specific papers
106HPC: Precision & Mixed PrecisionUse half or custom data types for HPC kernels if feasible.Must confirm numerical stability.HPC papers on mixed precision, e.g. SC conference proceedings
107Advanced Debugging Tools (cuda-memcheck, etc.)Use cuda-memcheck for memory leak/race detection in a bigger scenario.Errors may appear asynchronously.cuda-memcheck Docs
108Graphics Interop (OpenGL/DX)If relevant, share buffers between CUDA and graphics APIs.Handling context incorrectly => errors.CUDA Graphics Interop
109Large-Scale Code, MaintainabilityOrganize your code into modules/libraries; consider CMake for builds.Linker errors if ignoring separate compilation steps.Separate Compilation Guide
110HPC Tools & Libraries (MAGMA, etc.)Try MAGMA for advanced linear algebra on GPU.Library/hardware version mismatches.MAGMA
111Testing & Validation StrategiesImplement unit tests for GPU kernels using CPU reference checks.Race conditions might appear only at high thread counts.Google Test examples with CUDA
112Progress CheckpointReflect on HPC/ML techniques, debugging, multi-GPU scaling.Missing HPC/ML concepts => domain inefficiency.Recap Days 99–111; compile best practices
113Revisiting Key OptimizationsIdentify top 3 bottlenecks in your main code; systematically address them.Missing “low-hanging fruit” => suboptimal gains.Re-profile with Nsight, confirm improvements
114GPU Scheduling & CUcontext ExplorationInvestigate multiple contexts/users sharing GPU resources.Misusing contexts => driver crashes.CUDA Driver API, “Context Management”
115Final Performance Tweaks & Fine-TuningAdjust L1/Shared memory config if your GPU allows; fine-tune block dimensions.Over-optimizing => not portable across GPU models.Architecture-specific best practices (e.g., Turing, Ampere)
116Memory Hierarchy MasteryCreate a reference diagram of global, shared, local, constant, texture, etc.Overlooking local memory spills into global.CUDA C Programming Guide, memory hierarchy sections
117Detailed Profiling RecapRe-profile older mini-projects; apply new knowledge for more gains.Inconsistent metrics => unclear improvements.Nsight Systems, Nsight Compute
118Review of Common PitfallsMake a checklist of frequent issues: out-of-bounds, race conditions, divergence, etc.Forgetting final checks => final project problems.Personal “CUDA Pitfalls & Solutions” doc
119Prep for Final CapstoneCheck environment, references, library versions; plan scope carefully.Over-scoping => incomplete final project.Double-check docs & notes
120Capstone Project #6Final Project: End-to-End HPC or ML Application.––

Capstone Projects Summary

CapstoneProject & DescriptionCore SkillsImplementation & Optimization Tips
1 (Day 20)Image Convolution Pipeline
Implement a 2D convolution (edge detection) on the GPU.
- Grid/Block config
- Shared memory tiling
- Basic concurrency
- Optimize shared memory usage
- Use events for performance measurement
- Validate vs. CPU reference
2 (Day 40)Sparse Matrix-Vector Multiplication
Handle large sparse matrices; measure speed-up vs. CPU.
- Memory coalescing
- Atomic add for scatter
- Stream concurrency
- Use CSR format
- Handle boundary conditions carefully
- Profile with Nsight for memory/compute bottlenecks
3 (Day 60)Multi-Stream Data Processing
Overlap data transfers & kernel execution for real-time feeds.
- Stream usage
- Async transfers
- Concurrency patterns
- Pin host memory for async
- Keep multiple streams busy
- Monitor concurrency in Nsight
4 (Day 80)Multi-GPU Matrix Multiply
Split a large matrix across two GPUs if possible.
- Multi-GPU partitioning
- Peer-to-peer (if hardware allows)
- Advanced sync
- Ensure load balance
- Use P2P for direct memory copying
- Measure scaling efficiency
5 (Day 100)CUDA Graph-Optimized Workload
Convert a pipeline of kernels & copies into a single CUDA graph.
- CUDA Graph creation
- Graph instantiation & reuse
- Profiling graph approach
- Identify common subgraphs
- Update or re-launch partial graphs if workflow changes
- Compare timeline vs. standard stream
6 (Day 120)Final Project: End-to-End Application
HPC or ML (e.g., PDE solver or small model training) on the GPU
- Concurrency, memory mgmt, multi-GPU or libraries, debugging, final optimizations- Plan data management
- Thorough accuracy validation
- Use Nsight, cuda-gdb, timing events
- Aim for stable, well-commented, high-performance code

Additional Resources

  1. Official Documentation

  2. Keep Track of Your Environment

    • Note your CUDA version, driver version, and GPU architecture (compute capability).
    • Certain features (e.g., cudaMallocAsync, cooperative groups) require specific toolkit versions or newer GPUs.
  3. Profile Early and Often

  4. Maintain a Personal Cookbook

    • Collect error-handling macros, common patterns (e.g., parallel reductions, prefix sums, warp shuffles).
    • Keep a record of lessons learned, pitfalls, and solutions.
  5. Test Frequently

    • Write small reference tests or CPU comparisons to validate correctness.
    • For performance improvements, record baseline metrics before changes and compare after.
  6. Explore Community & Research


Happy coding, and best of luck on your 120-Day CUDA Journey!

Repository Activity

For the latest repository activity, see Repository Activity Log.

Daily Updates

AdepojuJeremy/CUDA-120-DAYS--CHALLENGE

A 120-day CUDA learning plan covering daily concepts, exercises, pitfalls, and references (including “Programming Massively Parallel Processors”). Features six capstone projects to solidify GPU parallel programming, memory management, and performance optimization skills.

Shell

962

148 commits

updated Mar 29, 2025

See the code

README

Cuda-120-Days-Challenge

A 120-day CUDA learning plan covering daily concepts, exercises, pitfalls, and references (including “Programming Massively Parallel Processors”). Features six capstone projects to solidify GPU parallel programming, memory management, and performance optimization skills.

120-Day CUDA Curriculum

A structured, day-by-day plan to master NVIDIA CUDA programming over 120 days. Each day includes:

  • Core Topic
  • Practical Exercise / Mini-Project
  • Debugging Pitfalls
  • Resource Suggestions

Six Capstone Projects are spread out at Days 20, 40, 60, 80, 100, and 120 to synthesize the skills acquired.


Day-by-Day CUDA Curriculum

DayCore TopicPractical Exercise / Mini-ProjectDebugging PitfallsResource Suggestions
1Introduction to GPU Computing & CUDA(daily-updates/day-01-intro-cuda.md)Write a simple “Hello GPU” kernel that prints a message from one thread.Missing <cuda_runtime.h> or incorrect compiler flags.CUDA C Programming Guide, Introduction
2Setting Up the Development EnvironmentInstall CUDA Toolkit & drivers; compile and run sample codes.Incompatible driver/toolkit versions.Official “Getting Started” Guide
3GPU vs. CPU Architecture FoundationsCompare GPU SMs and CPU cores; discuss throughput vs. latency.Mixing CPU vs. GPU roles can lead to design inefficiencies.CUDA C Programming Guide, “Hardware Model Overview”
4Thread Hierarchy: Grids & BlocksLaunch a kernel using different grid/block dimensions, experiment with thread indexing.Off-by-one errors in thread indexing.CUDA C Programming Guide, “Thread Hierarchy”
5Thread Hierarchy: Warps (Intro)Inspect warp size and how threads are grouped (no direct warp programming yet).Divergence issues in the same warp.CUDA C Best Practices Guide, “Warps and SIMT Model”
6Basic Kernel Launch & ExecutionWrite a kernel for element-wise addition on a small array.Mixing up cudaMemcpyHostToDevice vs. cudaMemcpyDeviceToHost.CUDA Samples, Vector Addition
7Memory Model (Global Memory Basics)Transfer data to global memory, run a simple computation, transfer results back.Mismatched data sizes or forgetting to free GPU memory.CUDA C Programming Guide, “Global Memory Access”
8Memory Allocation & PointersUse cudaMalloc/cudaFree; practice error checking.Memory leaks if forgetting to free device pointers.CUDA C Programming Guide, “Memory Allocation”
9Memory Alignment & CoalescingBenchmark coalesced vs. non-coalesced memory accesses in a kernel.Non-contiguous access patterns hurt performance.CUDA C Best Practices Guide, “Memory Coalescing”
10Shared Memory FundamentalsImplement tile-based matrix multiplication using shared memory.Race conditions without thread sync.CUDA C Programming Guide, “Shared Memory”
11Thread Synchronization (__syncthreads())Extend tile-based multiplication with sync calls; measure performance.Missing __syncthreads() => partial updates.CUDA C Programming Guide, “Synchronization”
12Bank Conflicts in Shared MemoryTest an access pattern that causes bank conflicts; measure performance impact.Overlooking bank conflict in shared memory accesses.CUDA C Programming Guide, “Shared Memory Bank Conflicts”
13Basic Atomic OperationsUse atomicAdd to sum an array in parallel.Large-scale sums using atomics can degrade performance.CUDA C Programming Guide, “Atomic Functions”
14Progress CheckpointQuick recap or quiz: global vs. shared memory usage.Not consolidating learning => repeated mistakes.Review Days 1–13 notes; create a “lessons learned” list
15Advanced Atomic OperationsExperiment with atomicCAS, atomicExch, etc.Overusing atomics => performance bottlenecks.CUDA C Programming Guide, “Atomic Functions”
16Kernel Configuration TuningAdjust block sizes for the same kernel; observe occupancy changes.Non-multiples of warp size can lower occupancy.CUDA Occupancy Calculator (within Nsight Compute)
17Host-Device Synchronization PatternsUse cudaDeviceSynchronize() for timing; measure kernel durations.Missing sync => partial results readback.CUDA C Programming Guide, “Device Synchronization”
18Error Handling & cudaGetErrorString()Implement robust error checks after each CUDA call.Ignoring errors => hard-to-trace bugs.CUDA Error Handling
19Unified Memory (UM) IntroUse cudaMallocManaged; run simple vector addition.Forgetting that UM still migrates data.CUDA C Programming Guide, “Unified Memory”
20Capstone Project #1Image Convolution Pipeline: 2D convolution (e.g., edge detection) on GPU.––
21Streams & Concurrency (Basics)Launch two kernels in different streams; check overlap.Default stream is blocking if concurrency not enabled.CUDA C Programming Guide, “Streams”
22Events & TimingUse CUDA events for precise kernel timing.Misplacing events => skewed time measurements.CUDA C Programming Guide, “Events”
23Asynchronous Memory CopyCopy data using streams asynchronously.Not using pinned host memory => limited async.CUDA C Programming Guide, “Asynchronous Transfers”
24Pinned (Page-Locked) MemoryCompare pinned vs. pageable host memory transfers.Excessive pinned memory => system performance hit.CUDA C Programming Guide, “Pinned Memory”
25Double Buffering TechniqueImplement a two-buffer pipeline to overlap compute and transfer.Improper sync => reading incomplete data.CUDA Concurrent Kernels Sample
26Constant MemoryUse constant memory for read-only data (e.g., coefficients).Over the constant memory limit or forgetting read-only usage.CUDA C Programming Guide, “Constant Memory”
27Texture & Surface Memory (Intro)Sample a small 2D texture; compare vs. global memory fetch.Missing texture binding/unbinding steps.CUDA C Programming Guide, “Texture Memory”
28Progress CheckpointRecap concurrency & memory (short quiz or multi-topic mini-project).Gaps in concurrency knowledge => suboptimal performance.Review Days 15–27 notes
29Texture Memory (Practical)Implement image-processing kernel (e.g., grayscale) using textures.Incorrect normalized coordinates => invalid fetch.CUDA C Programming Guide, “Texture Reference”
30Surface MemoryWrite operations using surfaces (e.g., output image buffer).Coordinate boundary checks are critical.CUDA C Programming Guide, “Surface Reference”
31Unified Memory Deep DiveUse cudaMallocManaged with multiple kernels; measure page-fault overhead.Poor data locality => excessive page migration.CUDA Unified Memory
32Stream Sync & DependenciesEnforce execution order with events or cudaStreamWaitEvent().Forgetting to record an event => faulty sync.CUDA C Programming Guide, “Stream Synchronization”
33Intro to CUDA GraphsConvert a kernel sequence into a CUDA graph; measure performance.Mistakes in graph capture => unexpected results.CUDA C Programming Guide, “Graphs”
34Nsight Systems / Nsight ComputeProfile a small app to find bottlenecks; read kernel timelines.Misreading profiling data => false conclusions.Nsight Systems / Nsight Compute
35Occupancy & Launch Config TuningUse the Occupancy Calculator to refine block size for better SM use.Overlooking shared memory => reduced occupancy.CUDA C Best Practices Guide, “Occupancy”
36Profiling & Bottleneck AnalysisProfile matrix multiplication or similar; identify memory vs. compute limits.Only measuring compute => ignoring memory throughput (or vice versa).Nsight Compute Metrics
37Intro to Warp-Level PrimitivesUse warp shuffle instructions for a small parallel reduce.Divergence or incorrect shuffle masks can ruin results.CUDA C Programming Guide, “Warp Intrinsics”
38Warp DivergenceWrite a kernel with branching; measure performance difference.Excessive branching => warp serialization.CUDA C Best Practices Guide, “Minimizing Divergence”
39Dynamic ParallelismLaunch kernels from within a kernel to handle subdivided tasks.Over-launching can deplete resources quickly.CUDA C Programming Guide, “Dynamic Parallelism”
40Capstone Project #2Sparse Matrix-Vector Multiplication for large sparse data sets.––
41Advanced Streams & Multi-Stream ConcurrencyLaunch multiple kernels in parallel using multiple streams.Oversubscribing GPU with too many streams.CUDA C Programming Guide, “Streams”
42Progress CheckpointRecap concurrency, warp ops, dynamic parallelism.Missing these => issues in advanced topics later.Short quiz or combined mini-project for Days 29–41
43Efficient Data Transfers & Zero-CopyMap host memory into device space (zero-copy); measure overhead vs. pinned.Improper use => performance losses.CUDA C Programming Guide, “Zero-Copy”
44Advanced Warp Intrinsics (Scan, etc.)Implement a warp-wide prefix sum with __shfl_down_sync.Misaligned warp sync => incorrect partial sums.CUDA C Programming Guide, “Shuffle and Cooperative Groups”
45Cooperative Groups (Intro)Use cooperative groups for flexible synchronization within blocks or grids.Not all GPUs support advanced groups fully.CUDA C Programming Guide, “Cooperative Groups”
46Peer-to-Peer Communication (Multi-GPU)Enable P2P for direct data transfers (if you have multiple GPUs).GPU compatibility issues block P2P.CUDA C Programming Guide, “Peer-to-Peer Memory Access”
47Intermediate Debugging & Profiling ToolsUse cuda-gdb or Nsight Eclipse for step-by-step debugging.Missing sync can make debugging inconsistent.CUDA Debugger Docs
48Memory Footprint OptimizationReduce shared memory or register usage; measure occupancy.Overuse => occupancy drop.CUDA C Best Practices Guide, “Memory & Register Optimization”
49Thrust for High-Level OperationsReplace custom loops with Thrust transforms, sorts, reductions.Excessive device-host transfers if not structured well.Thrust Library
50Intro to cuBLASPerform basic vector/matrix ops with cuBLAS, compare to custom kernels.Type mismatches or library error handling.cuBLAS Library User Guide
51Intro to cuFFTImplement a simple 1D FFT on the GPU; measure performance.Incorrect sizing, padding => wrong results.cuFFT Library User Guide
52Code Optimization (Part 1)Loop unrolling or register usage tweaks; measure improvements.Over-optimizing => diminishing returns.CUDA C Best Practices Guide, “Kernel Optimization”
53Code Optimization (Part 2)Analyze PTX, apply instruction-level optimizations.PTX can vary across CUDA toolkit versions.PTX Tools, ptxas, cuobjdump
54Nsight Compute: Kernel AnalysisExamine occupancy, memory throughput, and instruction mix.Ignoring memory metrics => incomplete optimization approach.Nsight Compute Docs
55Intro to Device Libraries (cuRAND, etc.)Generate random numbers (cuRAND); run a Monte Carlo simulation.Misusing seeds or distribution params.cuRAND Library User Guide
56Progress CheckpointRecap concurrency (multi-stream), libraries, optimization.Fragmented knowledge => missed performance.Summarize library-based vs. custom kernels
57Robust Error Handling & DebuggingExpand error checking macros; advanced debugging with cuda-gdb.Release builds can hide errors if not checked.CUDA Runtime Error Handling
58Handling Large Data SetsChunk large arrays with streaming techniques.Possible out-of-range indices in chunk loops.CUDA C Best Practices Guide, “Large Data Handling”
59MPS (Multi-Process Service)Enable MPS for sharing GPU among multiple processes (if supported).Oversubscription => resource contention.NVIDIA MPS Documentation
60Capstone Project #3Multi-Stream Data Processing: Overlap transfers & kernels for real-time feeds.––
61GPU-Accelerated SortingUse Thrust’s sort; compare vs. CPU for large data.Memory bandwidth constraints.Thrust Sort Examples
62Stream Compaction & Parallel PatternsImplement parallel compaction (remove zeros) via Thrust or custom.Prefix sums must be correct or compaction fails.Thrust, Parallel Patterns
63Concurrency Patterns (Producer-Consumer)Pipeline kernels: one generating data, one consuming it.Missing sync can drop data.CUDA C Programming Guide, “Streams & Concurrency”
64Pinned + Unified Memory HybridUse pinned memory for input streaming, unified memory for intermediate results.Over-complicating memory usage => confusion.Unified vs. Pinned Memory Best Practices
65Collaborative Grouping TechniquesUse cooperative groups for advanced reductions.Not all GPUs support grid-level groups.CUDA C Programming Guide, “Cooperative Groups”
66Peer-to-Peer (P2P) & Multi-GPU ScalingSplit data across multiple GPUs if available.Mismatched driver/device IDs block P2P.Multi-GPU Programming
67GPU-Accelerated Graph Analytics (Intro)Simple BFS or PageRank with adjacency lists on the GPU.Random memory access => poor coalescing.NVIDIA Developer Blog (search for graph analytics)
68Memory Pool & Custom AllocatorsReuse device memory with a custom allocator to reduce cudaMalloc overhead.Not thread-safe under dynamic parallelism.cudaMallocAsync Docs
69Occupancy-Based Tuning for Large ProblemsMaximize occupancy on a large matrix multiplication.Register usage can limit occupancy.Nsight Compute Occupancy Analysis
70Progress CheckpointRecap concurrency patterns, advanced memory, multi-GPU.Small concurrency oversights => big issues.Review key lessons from Days 57–69
71Advanced Streams & OverlappingOverlap multiple kernels, data transfers, and CPU tasks.Missing sync => race conditions.Nsight Systems Docs
72CUDA Graphs: Complex WorkflowsMerge dependent kernels & copies into one CUDA graph.Missing finalization => incomplete runs.CUDA C Programming Guide, “Graph Best Practices”
73Dynamic Graph LaunchesBuild and launch graphs at runtime based on conditions.Too many small graphs => overhead.Nsight Documentation
74Multi-GPU Programming (Deeper Exploration)Distribute workload across two GPUs if hardware supports.Load imbalance if data not split evenly.Multi-GPU Programming
75Performance Metrics & Roofline AnalysisCollect memory throughput, FLOPS, chart on a roofline.Misreading memory/compute-bound => wrong optimization focus.NVIDIA Roofline Analysis Blog
76Mixed Precision & Tensor Cores (If Supported)Implement half-precision (FP16) matrix multiply on Tensor Cores.Precision trade-offs can break accuracy.CUDA C Programming Guide, “Tensor Core Programming”
77UM Advanced Topics (Prefetch, Advise)Use cudaMemAdvise, prefetch data to specific devices.Incorrect prefetch sizes => performance drop.CUDA Unified Memory
78Large-Scale Projects: Modular Kernel DesignSplit large kernels into smaller, manageable modules.Over-fragmentation => overhead from multiple launches.CUDA C Best Practices Guide, “Modular Kernel Design”
79Portability & Scalability Best PracticesAdjust code for various GPU architectures (SM versions).Hardcoding for a single GPU => poor portability.CUDA Toolkit Release Notes
80Capstone Project #4Multi-GPU Matrix Multiply: Split large matrix across 2 GPUs.––
81Cooperative Groups: Advanced PatternsTry a grid-level cooperative kernel needing all blocks to sync.Not all GPUs support grid-level sync.CUDA C Programming Guide, “Cooperative Launch”
82Large-Scale Batch ProcessingUse batched operations (cuBLAS batched GEMM) for efficiency.Wrong batch sizes => idle SMs.cuBLAS Documentation
83External Libraries (cuDNN, etc.)Integrate a small NN layer using cuDNN if possible.Version mismatches => runtime errors.cuDNN Library User Guide
84Progress CheckpointReflect on concurrency, multi-GPU, libraries.Missing synergy => suboptimal solutions.Short recap or quiz for Days 71–83
85Instruction Throughput ProfilingUse Nsight Compute to track instruction throughput for tight kernels.Ignoring special function units or double precision differences.Nsight Compute Docs
86Occupancy vs. ILPCompare effects of occupancy vs. ILP (Instruction-Level Parallelism).Forcing ILP might drop occupancy.CUDA C Best Practices Guide
87Custom Memory AllocatorsExtend your memory pool design with stream-ordered allocations.Race conditions if multiple streams allocate at once.cudaMallocAsync Docs
88Kernel Fusion & Loop FusionMerge multiple small kernels into a single kernel to reduce launch overhead.Oversized kernels can exceed register/shared limits.CUDA C Best Practices Guide, “Kernel Fusion”
89Algorithmic Optimizations (Tiling, Blocking)Refine tiling or blocking for matrix multiply, convolution, etc.Over-tiling => overhead > gains.GPU Gems, HPC papers on tiling strategies
90Minimizing Data TransfersUse pinned memory, async transfers, or kernel-side generation to limit PCIe overhead.Large single transfers might block concurrency.CUDA C Best Practices Guide, “Data Transfer”
91Enterprise-Level Code StructureExplore multi-file, multi-module approach with separate compilation.Linker errors if not using correct NVCC flags.CUDA C Programming Guide, “Separate Compilation and Linking”
92Advanced Debugging (Races & Deadlocks)Diagnose a race or deadlock in a complex multi-stream or multi-block scenario.Relying on __syncthreads() incorrectly => deadlock.CUDA Debugger Docs
93Real-Time GPU Computing TechniquesIf real-time constraints exist, explore low-latency execution patterns.GPU scheduling unpredictability if shared environment.NVIDIA Documentation on Real-Time GPU
94Host Multithreading + GPU CoordinationUse multiple CPU threads to launch kernels/manage streams concurrently.CPU thread contention can throttle the GPU.CUDA C Best Practices Guide, “Multi-threaded Host Code”
95CUDA Graph Updates & ReusabilityDynamically update parts of a CUDA graph without a full rebuild.Mishandling graph node handles => crashes.CUDA Graphs, advanced topics
96Precision & Numerical StabilityExamine rounding, float vs. double, iterative error accumulation.Small errors compound over iterations.Kahan Summation, HPC references
97Advanced P2P & Clustering (If Possible)Use GPU-GPU RDMA or multi-node scaling in a cluster environment.Not all hardware supports GPUDirect RDMA.GPUDirect RDMA Docs
98Progress CheckpointRecap advanced debugging, multi-threaded host, graphs, precision.Missing these => major issues in large apps.Summarize Days 85–97
99Graph API for Complex DAG WorkloadsBuild a multi-kernel DAG with conditional branches/loops using CUDA Graphs.Overcomplicated graph => overhead.CUDA Graph Examples
100Capstone Project #5CUDA Graph-Optimized Workload: Merge multiple kernels + copies into one graph.––
101GPU-Accelerated ML Frameworks (Intro)If possible, integrate a custom kernel/layer into TensorFlow or PyTorch.Version mismatches => build errors.PyTorch CUDA Extensions, TensorFlow Custom Ops
102CUDA + Other Parallel FrameworksExplore hybrid CPU/GPU parallelism (OpenMP, MPI).Partitioning complexities, oversubscription risk.MPI + CUDA Resources, HPC references
103Tuning GPU-Accelerated ML OpsProfile a small neural net or inference pipeline; identify GPU hotspots.Overlooking CPU-GPU sync or data pipeline bottlenecks.Nsight Systems for ML Frameworks
104Multi-GPU Scaling in MLDistribute training across multiple GPUs or data parallel approach.Communication overhead if poorly balanced.NCCL Library, multi-GPU references
105HPC: Memory Throughput & ComputationReview HPC patterns (PDE solvers, climate modeling) for GPU acceleration.Memory-bound kernels for large stencils.AMGX, HPC domain-specific papers
106HPC: Precision & Mixed PrecisionUse half or custom data types for HPC kernels if feasible.Must confirm numerical stability.HPC papers on mixed precision, e.g. SC conference proceedings
107Advanced Debugging Tools (cuda-memcheck, etc.)Use cuda-memcheck for memory leak/race detection in a bigger scenario.Errors may appear asynchronously.cuda-memcheck Docs
108Graphics Interop (OpenGL/DX)If relevant, share buffers between CUDA and graphics APIs.Handling context incorrectly => errors.CUDA Graphics Interop
109Large-Scale Code, MaintainabilityOrganize your code into modules/libraries; consider CMake for builds.Linker errors if ignoring separate compilation steps.Separate Compilation Guide
110HPC Tools & Libraries (MAGMA, etc.)Try MAGMA for advanced linear algebra on GPU.Library/hardware version mismatches.MAGMA
111Testing & Validation StrategiesImplement unit tests for GPU kernels using CPU reference checks.Race conditions might appear only at high thread counts.Google Test examples with CUDA
112Progress CheckpointReflect on HPC/ML techniques, debugging, multi-GPU scaling.Missing HPC/ML concepts => domain inefficiency.Recap Days 99–111; compile best practices
113Revisiting Key OptimizationsIdentify top 3 bottlenecks in your main code; systematically address them.Missing “low-hanging fruit” => suboptimal gains.Re-profile with Nsight, confirm improvements
114GPU Scheduling & CUcontext ExplorationInvestigate multiple contexts/users sharing GPU resources.Misusing contexts => driver crashes.CUDA Driver API, “Context Management”
115Final Performance Tweaks & Fine-TuningAdjust L1/Shared memory config if your GPU allows; fine-tune block dimensions.Over-optimizing => not portable across GPU models.Architecture-specific best practices (e.g., Turing, Ampere)
116Memory Hierarchy MasteryCreate a reference diagram of global, shared, local, constant, texture, etc.Overlooking local memory spills into global.CUDA C Programming Guide, memory hierarchy sections
117Detailed Profiling RecapRe-profile older mini-projects; apply new knowledge for more gains.Inconsistent metrics => unclear improvements.Nsight Systems, Nsight Compute
118Review of Common PitfallsMake a checklist of frequent issues: out-of-bounds, race conditions, divergence, etc.Forgetting final checks => final project problems.Personal “CUDA Pitfalls & Solutions” doc
119Prep for Final CapstoneCheck environment, references, library versions; plan scope carefully.Over-scoping => incomplete final project.Double-check docs & notes
120Capstone Project #6Final Project: End-to-End HPC or ML Application.––

Capstone Projects Summary

CapstoneProject & DescriptionCore SkillsImplementation & Optimization Tips
1 (Day 20)Image Convolution Pipeline
Implement a 2D convolution (edge detection) on the GPU.
- Grid/Block config
- Shared memory tiling
- Basic concurrency
- Optimize shared memory usage
- Use events for performance measurement
- Validate vs. CPU reference
2 (Day 40)Sparse Matrix-Vector Multiplication
Handle large sparse matrices; measure speed-up vs. CPU.
- Memory coalescing
- Atomic add for scatter
- Stream concurrency
- Use CSR format
- Handle boundary conditions carefully
- Profile with Nsight for memory/compute bottlenecks
3 (Day 60)Multi-Stream Data Processing
Overlap data transfers & kernel execution for real-time feeds.
- Stream usage
- Async transfers
- Concurrency patterns
- Pin host memory for async
- Keep multiple streams busy
- Monitor concurrency in Nsight
4 (Day 80)Multi-GPU Matrix Multiply
Split a large matrix across two GPUs if possible.
- Multi-GPU partitioning
- Peer-to-peer (if hardware allows)
- Advanced sync
- Ensure load balance
- Use P2P for direct memory copying
- Measure scaling efficiency
5 (Day 100)CUDA Graph-Optimized Workload
Convert a pipeline of kernels & copies into a single CUDA graph.
- CUDA Graph creation
- Graph instantiation & reuse
- Profiling graph approach
- Identify common subgraphs
- Update or re-launch partial graphs if workflow changes
- Compare timeline vs. standard stream
6 (Day 120)Final Project: End-to-End Application
HPC or ML (e.g., PDE solver or small model training) on the GPU
- Concurrency, memory mgmt, multi-GPU or libraries, debugging, final optimizations- Plan data management
- Thorough accuracy validation
- Use Nsight, cuda-gdb, timing events
- Aim for stable, well-commented, high-performance code

Additional Resources

  1. Official Documentation

  2. Keep Track of Your Environment

    • Note your CUDA version, driver version, and GPU architecture (compute capability).
    • Certain features (e.g., cudaMallocAsync, cooperative groups) require specific toolkit versions or newer GPUs.
  3. Profile Early and Often

  4. Maintain a Personal Cookbook

    • Collect error-handling macros, common patterns (e.g., parallel reductions, prefix sums, warp shuffles).
    • Keep a record of lessons learned, pitfalls, and solutions.
  5. Test Frequently

    • Write small reference tests or CPU comparisons to validate correctness.
    • For performance improvements, record baseline metrics before changes and compare after.
  6. Explore Community & Research


Happy coding, and best of luck on your 120-Day CUDA Journey!

Repository Activity

For the latest repository activity, see Repository Activity Log.

Daily Updates

Significant stargazers

Huazhong

82 followers · starred Jan 2025

Chris Ohk

4,130 followers · starred Mar 2025

Alex McKinney

137 followers · starred Jan 2025

Toluclassics

100 followers · starred Jun 2025