GPU Execution, Memory and Code Generation

Kernel performance follows from how threads, memory transactions and machine instructions map onto a real device. This stage builds the execution model needed to predict coalescing, divergence, resource limits and compilation behavior before using a profiler.

Section 2 of 10 · 10 units · about 39 hours

0/10

By the end you can Predict warp membership, addresses, transactions, bank mapping, divergence, occupancy limits and generated-code targets for three unfamiliar kernels, then verify the mapping with device properties, PTX and SASS inspection.

Units

Build it

Mini project · about 12 to 16 hours

Execution and memory mapping with a PTX and SASS evidence bundle

Build the execution model in kernellab: an explicit-memory baseline, grid-stride tails, a block-local publication test, a source to SASS bundle, a native extension and a capability manifest. Predictions precede profiles throughout, and unsupported features are audited statically. The baseline, manifest and selector carry into later timing work.

  1. 1Write an explicit-memory single-precision vector add in kernels/cuda/map.cu. Check every result against an independent host reference, and keep the tests.
  2. 2Predict sector, bank and occupancy behavior before running, using TensorTonic Occupancy Calculator, Coalescing Counter and Bank Conflict Analyzer. Check predictions with event timings and compiler resource reports, and keep the derivation sheet.
  3. 3Convert the baseline to a grid-stride loop with checked tails, including empty inputs. Pair uniform and divergent kernels, annotate the retained branch and reconvergence in PTX and SASS, and keep the annotated bundle.
  4. 4Build a two-warp block-local publication test with a barrier, release store and acquire load. Check the payload on the host, write the scope and progress audit, and keep racy variants as analyzed cases only.
  5. 5Bundle source, PTX, cubin and SASS for the bounded kernel with compiler resource tables. Test one disassembly-backed paired timing hypothesis with event timing, and keep the bundle with the hypothesis report.
  6. 6Build an inference-only vector-add extension with an explicit shape and device contract. Test views, alignment and rejections plus lifetime on a non-default stream, and keep the rejection matrix.
  7. 7Write a capability manifest from device queries and a selector that falls back to the baseline, with dispatch tests and automatic against forced-baseline timing. Audit TMA, clusters, wgmma (Hopper) and tcgen05 (Blackwell) statically unless your GPU has them.
What you hand in
  • kernels/cuda/map.cu with the baseline, index map, grid-stride tails and host reference tests.
  • The derivation sheet with sector, bank and occupancy predictions beside measured evidence and resource reports.
  • The publication test with audit, SASS bundle with hypothesis, extension with rejection matrix, and capability manifest.
How to check it
  • Self-grade with the rubric below
How it's graded

Mapping correctness

Pass: The baseline matches the host reference, the index map is verified, and tails pass with an empty path.

Great: An injected defect is kept as a regression that the reference catches.

Prediction before measurement

Pass: Sector, bank and occupancy derivations precede runs and are reconciled with measured evidence.

Great: The paired hypothesis names the disassembly lines it depends on and a falsifying signal.

Synchronization and dispatch

Pass: Your publication test passes through release and acquire, and dispatch tests cover fallback branches.

Great: The audit separates initialization from publication, and paths your GPU cannot run are marked as static audit.

Resources

  • Programming Massively Parallel Processors, 4th edition - Chapters 2 to 6Wen-mei Hwu, David Kirk and Izzat El Hajj

    Read Chapters 2 to 6: data-parallel kernels, multidimensional grids, compute architecture and scheduling, memory architecture and data locality, and performance considerations. Work the chapter exercises on warps, occupancy, memory and coalescing, and predict three altered launch or address patterns before running them.

  • MIT 6.S894 Accelerated Computing (Fall 2025) - Lectures 2 to 5 and Labs 2 and 3MIT

    Use Lecture 2 (Throughput Processors), Lectures 3 and 4 (Memory, Parts 1 and 2) and Lecture 5 with its continuation (scratchpads, bank conflicts, register shuffles, overlap) for why the hardware looks as it does. Do Lab 2 (Massively-Parallel Mandelbrot, with its FMA-latency and warp-scheduler probes) and Lab 3 (Wave Simulation, with its coalesced-load and memory-latency probes) from the public lab repositories, built with nvcc for your own GPU instead of the course service. The labs were written for an RTX 4000 Ada, so recompute any SM count or bandwidth the questions assume.

  • CUDA Programming GuideNVIDIA

    Read the Basics and Programming Model chapters plus the sections on memory, synchronization, hardware implementation and compute capabilities used by your kernels. Record the toolkit documentation version alongside every claim.

  • CUDA C++ Best Practices GuideNVIDIA

    Study Assess, Parallelize, Optimize, Deploy; Getting the Right Answer; memory optimization; execution configuration; instruction optimization; and deployment compatibility. Convert recommendations into hypotheses, not universal rules.

  • NVIDIA CUDA Pro Tips: grid-stride loops and vectorized memory accessNVIDIA

    Read the grid-stride SAXPY loop and its scalability and debugging discussion (April 22, 2013), plus the scalar-copy SASS and vector-type alignment discussion in Increase Performance with Vectorized Memory Access (August 4, 2025). Skip the latter article's full vector-copy kernels: their tail-thread condition can omit remainders. These fill the pool's grid-stride and vector-width coverage gaps.

  • PyTorch custom C++/CUDA operators and CUDA semanticsPyTorch

    Custom C++ and CUDA Operators: build system, backend registration, Testing an operator and mutable schema; CUDA semantics 2.14: CUDA streams. These fill the native tensor-boundary gap in the CUDA-only pool. Stop before fake-kernel and autograd implementation; harden the tutorial's CUDA example for empty inputs, same-device checks, device guards, indexing width and launch errors.

  • GPU MODE Foundations LecturesGPU MODE

    Use Lectures 2, 3, 4, 5, 8, 37 and 41 for PMPP review, CUDA setup, architecture, optimization checklists, SASS and documentation reading. Reproduce only the examples that test a prediction from this stage.

  • TensorTonic Language Modeling from Scratch - GPU analysis problemsTensorTonic

    Solve GPU Occupancy Calculator, Shared-Memory Bank Conflict Analyzer and Global-Memory Coalescing Counter after the matching units, and check each answer against your own derivation.

  • Parallel Thread Execution ISANVIDIA

    Read the PTX purpose, machine model, state spaces, memory consistency and target directives. Compile two tiny kernels, map source to PTX and SASS, and explain what PTX does and does not guarantee across devices.

  • AI Performance Engineering - GPU FundamentalsWafer

    A curated index. Use Section 1 only to find a CUDA, PTX or architecture source the other entries lack.

  • CUDA Binary Utilities 13.4NVIDIA

    Sections 1.1 to 1.2, 2.1.1 to 2.1.3, 3.1.1 and 3.1.4 for cubin extraction, resource reports and line-correlated SASS. The existing compiler and PTX references lack a worked binary-tool workflow.