Unit 2 of 10 · about 4 hours · explain, derive

Warps, SMs, block residency and latency hiding

A launch describes logical parallelism, not simultaneous execution. Latency hiding depends on ready work at the scheduler, not just the number of threads launched.

You'll be able to

  • Predict warp membership and inactive positions for multidimensional and nonmultiple-of-32 blocks.
  • Distinguish resident, eligible and issuing warps, and explain how scheduling hides dependency latency.
  • Explain why a block stays on one SM but its warps do not all execute at once.

Covers

Warp formation, active lanes and partial warpsStreaming multiprocessors, block scheduling and residencyWarp scheduling, dependency latency and latency hiding
1

Read

In this order, only the parts listed

0 of 2 done

  1. PMPP, 4th edition: block and warp schedulingProgramming Massively Parallel Processors, 4th edition - Chapters 2 to 6

    Sections 4.1 to 4.2, 4.4 and 4.6

  2. MIT 6.S894 Fall 2025 Lab 2: FMA latency and instruction-level parallelismMIT 6.S894 Accelerated Computing (Fall 2025) - Lectures 2 to 5 and Labs 2 and 3

    Background: A Closer Look at the Hardware; Part 0 (Prelab): Instruction Latency of an FMA, through Prelab Question 3

    Use the GPU material only. The RTX 4000 Ada scheduler counts and clocks describe the course machine, not your GPU. Stop before Using ILP in a Simple Program.

2

Focus on

  • Linearize within a block with the x coordinate fastest. Warps never combine threads from different blocks.
  • All warps of a block reside on one SM. A normal launch does not promise a particular block-to-SM assignment or block order.
  • A resident warp can be stalled. Another eligible warp or independent instructions within the same warp can cover the wait without reducing the instruction's dependency latency.
Common mistakes · 3
  • Counting CUDA cores as simultaneously resident threads. Residency and execution throughput are different limits.
  • Assuming one block per SM because the grid has as many blocks as SMs. Correctness cannot depend on that scheduling choice.
  • Calling an independent-chain benchmark's elapsed cycles per FMA the latency of a dependent FMA. It measures a different quantity.
3

Try it yourself

Closed-book, before checking anything

Draw the warp map for dim3 block(16, 3, 1). Warp 0 contains both complete rows with y coordinates 0 and 1; warp 1 contains the 16 threads of row 2 and has 16 unused positions. Two such blocks allocate four warps, not three. Verify the map with a kernel that writes each thread's linear index, warp index and lane index to a separate output slot.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Can the final 16 threads of two 48-thread blocks share one warp?Answer

    No. Each block independently allocates two warps; the unused positions of its final warp cannot be filled by another block.

  2. 2.Why can an SM stall with many resident warps?Answer

    All those warps may be waiting on dependencies, memory or synchronization, leaving no eligible instruction to issue.

  3. 3.Does interleaving independent FMA chains make a dependent FMA finish sooner?Answer

    No. It exposes independent work during the wait and may improve throughput; the producer-to-consumer dependency latency is unchanged.

5

Practice

  • MIT 6.S894 Fall 2025 Lab 2: FMA prelab Questions 1 to 3

    Complete fma_latency, fma_latency_interleaved and fma_latency_no_interleave

    Build in your own harness with nvcc -O3 -arch=native fma_latency.cu -o fma_latency, not Telerun. Use long dependent chains, consume their results, and inspect SASS for retained FMAs. Reset inputs between variants and use bounded finite values. The starter prints whole-snippet cycles, so divide by the retained FMA count and account for timer overhead. Repeat interleaved trials and report medians, hardware and toolkit; no course latency or speedup is a target. This is an investigative lab, not an autograded correctness suite.

You're done when

You predict the two-block warp map correctly and can explain the prelab's dependent-chain and independent-chain measurements using the actual SASS, without claiming a fixed speedup.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 9 more in the section
  • Programming Massively Parallel Processors, 4th edition - Chapters 2 to 6Wen-mei Hwu, David Kirk and Izzat El Hajj · primary

    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 · required

    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.

Also in this section

  • CUDA Programming GuideNVIDIA · required

    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 · required

    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.

  • Parallel Thread Execution ISANVIDIA · reference

    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.

  • GPU MODE Foundations LecturesGPU MODE · support

    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 · support

    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.

  • AI Performance Engineering - GPU FundamentalsWafer · reference

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

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

    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.

  • CUDA Binary Utilities 13.4NVIDIA · reference

    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.

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

    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.