Unit 11 of 11 · about 3 hours · measure

Seeded defects: races, divergent barriers, partial warps, stale buffers and masks

Primitives fail in ways that look like performance problems. This unit turns the section's bugs into a diagnostic checklist before the mini-project.

You'll be able to

  • Inject race, divergent-barrier, partial-warp, stale-buffer and mask defects and describe each signature.
  • Attribute asynchronous errors with sanitizer, event and timeline evidence instead of blanket synchronization.
  • Write regression tests that fail on each defect and pass on the fix.

Covers

Race, divergent barrier, partial warp, stale buffer and mask defects
1

Read

In this order, only the parts listed

0 of 3 done

  1. Failure-injection requirementsGPU Microbenchmark and Kernel Suite - CUDA Core

    Milestone D and the failure-injection requirements: out-of-bounds, partial-warp, missing synchronization, bank conflict, uncoalesced stride, divergent barrier, stale stream buffer, wrong mask, overflow and tile-edge defects with tooling diagnosis and regressions

  2. Divergence, completion and single-pass hazardsProgramming Massively Parallel Processors, 4th edition - Chapters 6 and 9 to 12

    Chapter 10, Sections 10.4 (control-divergence hazards) and 10.7 (hierarchical completion); Chapter 11, Section 11.7 (printed p. 256): single-pass atomic, fence and barrier deadlock risk

  3. Asynchronous error attributionCUDA C++ Programming Guide (v13.4.2)

    Section 2.5.4.2: cudaGetLastError versus cudaPeekAtLastError, printable error names, and the CUDA_LAUNCH_BLOCKING=1 trick to serialize launches while debugging

2

Focus on

  • Each defect has a signature. Races vary run to run, divergent barriers hang or race silently, partial warps corrupt tails only, stale buffers corrupt after reuse, and wrong masks corrupt masked rows only.
  • Attribute first: serialize with CUDA_LAUNCH_BLOCKING=1 to find the owning kernel, confirm with sanitizer evidence, and never ship a global synchronization as the fix.
  • A defect that never fires in tests still ships. Write the adversarial size, skew, reuse and mask cases from the project list as regression tests.
Common mistakes · 3
  • Declaring victory after 100 clean trials. A race needs size, block-count and stream-interleaving variation before the claim means anything.
  • Sprinkling cudaDeviceSynchronize after every call. It hides lifetime bugs and deletes the overlap built in the streams unit, so scope every fix to the owning stream or event.
  • Testing only friendly values. Pair each defect test with an adversarial-value twin, since order and mask bugs hide at friendly magnitudes.
3

Try it yourself

Closed-book, before checking anything

Seed all five defects (race, divergent barrier, partial warp, stale buffer, wrong mask) in your section kernels, diagnose each with cited tool evidence, fix each without a global synchronization, and keep the regression tests green.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.A scan hangs only at large lengths. What are the first suspects?Answer

    A divergent barrier or a global-sync-across-blocks assumption that deadlocks past one wave. Check barrier uniformity and any assumed block execution order.

  2. 2.Results are correct on powers of two but wrong at length 1000. What are the suspects?Answer

    Tail guards in loads, shuffle masks over partial warps, the block-sums tail, or the scan fix-up range. All share the shape of untested remainders.

  3. 3.Corruption appears only when two streams run together. What are the suspects?Answer

    A missing event dependency, buffer reuse before the consumer finishes, or accidental default-stream ordering. All are lifetime and ordering bugs, not kernel bugs.

  4. 4.How do you attribute an asynchronous error to its kernel?Answer

    Synchronize per stream and read the last-error APIs at each boundary, then set CUDA_LAUNCH_BLOCKING=1 to serialize launches. Fix at the owning boundary.

5

Practice

You're done when

All five seeded defects are diagnosed with cited tool evidence, fixed without global synchronization, and covered by regression tests.

Only when you can do this without notes.

Leads to

Notes

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

    Read thread coarsening in Chapter 6, then Chapters 9 (histogram), 10 (reduction), 11 (prefix sum) and 12 (merge, optional). Work the exercises that test work, depth, contention and boundary handling.

  • GPU Microbenchmark and Kernel Suite - CUDA CoreRoadmap-Final · support

    Complete the CUDA vector map, reduction, transpose and stable softmax requirements plus seeded access, synchronization, mask, stream and numerical failures. Preserve library and framework baselines.

  • CUDA C++ Programming Guide (v13.4.2)NVIDIA · reference

    Use Section 2.3.4 for coalesced access, the transpose example and bank-conflict padding; Section 2.5 for streams, events, synchronization and the stream-capture intro; and Section 4.2 for graph creation, update and capture constraints. This is the API reference beside the book chapters.

Also in this section

  • AI Systems Performance Engineering - Chapters 11 and 12Chris Fregly (O'Reilly) · required

    Read Chapter 11 on streams, events, inter-kernel pipelining and stream-ordered allocation, and Chapter 12 on CUDA graphs and dynamic scheduling. Skip device-initiated launch beyond the vocabulary.

  • Efficient Matrix Transpose in CUDA C/C++NVIDIA · required

    Rebuild copy, naive transpose, coalesced transpose and padded shared-memory variants. Update deprecated details for the installed toolkit and compare requested transactions, bank behavior and achieved bandwidth on odd as well as friendly shapes.

  • Optimizing Parallel Reduction in CUDANVIDIA · required

    Implement the optimization sequence from interleaved addressing through sequential addressing, first-add-during-load, unrolling and warp-level completion. Correct outdated assumptions and retain the stage where each optimization stops helping.

  • Single-pass Parallel Prefix Scan with Decoupled Look-backNVIDIA Research · depth

    Read after two-pass scans pass. Derive the state and progress argument, then implement or inspect a bounded version only if the available hardware and time support meaningful comparison.

  • Online Normalizer Calculation for SoftmaxOnline Softmax Authors · required

    Derive the running maximum and normalizer recurrence, test extreme and all-masked rows, and compare materialized, two-pass and online implementations before using the recurrence inside attention.

  • LeetGPU - CUDA Primitive ChallengesAlphaGPU · required

    Solve challenge 3 Matrix Transpose, 4 Reduction, 5 Softmax, 13 Histogramming and 16 Prefix Sum in CUDA. Add 70 Segmented Prefix Sum or 72 Stream Compaction only after the required set. Keep local source, hidden-shape assumptions, hardware, raw timings and correctness evidence outside the leaderboard.

  • GPU MODE - Reductions and ScansGPU MODE · support

    Use Lectures 9, 20, 21 and 24 after the PMPP implementations. Reproduce one faster scan or reduction idea and show the exact shape and device regime where it changes the bottleneck.

  • MIT 6.S894 Accelerated Computing (Fall 2025) - Lectures 6, 7 and 9 and Lab 7MIT · support

    Use Lecture 6 for host-device copies and streams, and Lectures 7 and 9 for map, stencil, reduce, compaction, scan, segmented scan, histogram and merge. Do Lab 7 (Run-Length Compression, with its scan and shuffle warm-ups) built for your own GPU.