Unit 7 of 12 · about 4 hours · measure

Compute Sanitizer: out-of-bounds, races, initialization and synchronization

Differential tests can miss an invalid access or intermittent race. Sanitizers add execution evidence, but each tool checks only a defined class of hazards.

You'll be able to

  • Choose memcheck, racecheck, initcheck or synccheck for a specific failure hypothesis.
  • Reduce a seeded defect to a source-attributed diagnostic and retain a regression test.
  • Distinguish a clean supported check from an unsupported or incomplete check.

Covers

Out-of-bounds and misaligned access diagnosis with memcheckRace, initialization and synchronization diagnostics
1

Read

In this order, only the parts listed

0 of 2 done

  1. Correctness before performance profilingAI Systems Performance Engineering - Chapters 6 to 8

    Chapter 6, Debugging Functional Correctness with NVIDIA Compute Sanitizer

  2. Compute Sanitizer 2026.3: tool scope and reportsCompute Sanitizer

    Compilation Options; Memcheck Tool - What is Memcheck, Understanding Memcheck Errors and Padding; Racecheck Tool - What is Racecheck and Using Racecheck; Initcheck Tool - Using Initcheck and Initcheck Address Space Selection; Synccheck Tool - Using Synccheck and Understanding Synccheck Reports

    Stop before tensor-core-specific guardrails and advanced barrier APIs. Use the address spaces supported by your installed version; older initcheck versions only cover global memory.

2

Focus on

  • Build optimized diagnostic binaries with -lineinfo and check every CUDA API result. Debug builds can change scheduling and resources, so they are not performance baselines.
  • Run memcheck first. Racecheck primarily checks shared-memory hazards; initcheck defaults to global memory; synccheck checks barrier usage the architecture does not support, not general data-race freedom. From compute capability 7.0 a block barrier inside divergent code is not a synccheck error.
  • A logical tensor overrun can remain inside an allocation or land in another valid allocation. Allocation padding improves detection; shape and sentinel tests are still necessary.
  • Use --error-exitcode 1 for automation. Keep source line, access type, thread/block coordinates, tool version and the smallest failing input with each regression.
Common mistakes · 3
  • Interpreting zero racecheck reports as proof of correct cross-stream or global-memory ordering.
  • Treating a skipped kernel, unsupported operation or timed-out run as a clean sanitizer result.
  • Adding unconditional device synchronization as a permanent fix instead of expressing the required dependency and lifetime.
3

Try it yourself

Closed-book, before checking anything

In separate tiny CUDA programs, seed a one-past-the-end write, an uninitialized global read and a shared-memory neighbor read without a barrier. Build them for your own GPU with -arch=native and -lineinfo and run memcheck with --padding 32, initcheck and racecheck; each reports its defect. For synccheck, seed __syncwarp(0x0000ffff) called by all 32 threads of a warp and build it with -G: synccheck reports "Barrier error detected. Invalid arguments." An -O3 build reports nothing, because the compiler removed the barrier (the SASS has no WARPSYNC). A __syncthreads() reached by half the block is not a synccheck error on compute capability 7.0 and later; run racecheck on it and read the race it reports. All of this was observed with Compute Sanitizer 2026.3 and CUDA 13.4 on an RTX 3050 6 GB. Repair each defect, rerun the tool and the output tests, and bound every run with a timeout.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Why does memcheck precede racecheck or synccheck?Answer

    Those tools do not replace memory-access checking. Invalid accesses can also make later diagnostics confusing or incomplete.

  2. 2.Why might a one-element tensor overrun escape memcheck?Answer

    It can remain within a larger allocation or enter a neighboring valid allocation. The tool does not know every logical tensor boundary.

  3. 3.Does zero reported errors prove all possible inputs and schedules are correct?Answer

    No. It applies only to executed paths within the tool's supported checks. Independent tests and ordering arguments remain necessary.

You're done when

Each supported seeded defect produces the expected class of report, its repair passes the same diagnostic and reference tests, and unsupported or incomplete checks remain explicitly open.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 10 more in the section
  • AI Systems Performance Engineering - Chapters 6 to 8Chris Fregly · primary

    Read Chapters 6 to 8: GPU architecture and occupancy, profiling and tuning memory access, and occupancy, warp efficiency and instruction-level parallelism, with their Nsight Systems, Nsight Compute and roofline workflows. Treat every quoted speedup as a hypothesis for your own hardware.

  • Compute SanitizerNVIDIA · required

    Run memcheck plus applicable racecheck, initcheck and synccheck cases against seeded defects. Preserve minimal reproducers and regression tests, and distinguish unsupported checks from a clean result.

Also in this section

  • AI Systems Performance Engineering companion code - Chapters 6 to 8Chris Fregly · required

    Use selected baseline and optimized pairs from code/ch06, code/ch07 and code/ch08 plus the shared benchmark and verification machinery. Run only hardware-compatible paths, inspect the tests first, retain raw artifacts and document any guard or unavailable feature.

  • Nsight Systems User GuideNVIDIA · required

    Learn capture, statistics, CUDA API and GPU timeline views, NVTX ranges and report export. Produce one trace that attributes a host gap, transfer or synchronization cost without using the kernel profiler first.

  • Nsight Compute Profiling GuideNVIDIA · required

    Study the profiling model, replay, metric collection, sections, roofline and source correlation. Collect the smallest counter set that can falsify your bottleneck hypothesis and record profiler overhead.

  • Roofline: An Insightful Visual Performance ModelUC Berkeley · required

    Read the original model and construct one roofline plot with explicit peak assumptions, useful operations and bytes. Add measured points and explain gaps from launch, resource, cache or instruction effects.

  • CUTLASS GEMM Performance Measurement MethodologyNVIDIA · support

    Apply the environment, clock, warmup, timing, verification and reporting guidance to the benchmark harness. Generalize the method beyond GEMM and document every intentional deviation.

  • CS336 Assignment 2 - Section 2.1 ProfilingStanford University · support

    Do the benchmarking_script, nsys_profile, mixed_precision_accumulation and memory_profiling problems on a model size that fits your GPU instead of the handout's B200 settings. Keep raw timings, traces and memory snapshots.

  • TensorTonic Language Modeling from Scratch - Measure Kernel Timeline UtilizationTensorTonic · support

    Solve the timeline-utilization problem after the timeline unit, then repeat the calculation on a trace you captured yourself.

  • GPU Microbenchmark and Kernel Suite - Harness and InstrumentationRoadmap-Final · support

    Complete Milestones A and B: correct references, synchronized timing, raw samples, noise characterization, environment capture, operation and byte models, timeline traces and profiler evidence.

  • PyTorch 2.14 numerical accuracy and tensor testingPyTorch · reference

    Read the numerical-accuracy introduction, Extremal values, non-finite inputs and Ampere precision sections, plus the assert_close contract and make_tensor parameters. These supply current comparison semantics missing from the pool's project checklist.

  • CUDA 13.4 Floating Point and IEEE 754NVIDIA · reference

    Read sections 2.2, 3.1 to 3.2 and 4.4 for reduction order and single-precision flush-to-zero flags. Do not use the historical CPU-has-no-FMA statements as current hardware facts.