CUDA Debugging: compute-sanitizer, Error Checks, Float Tolerance — GPU Programming in C/CUDA | Ep 4

Veröffentlicht am: 14 August 2026
auf dem Kanal: Glass Box Computing
26
0

A CUDA kernel can fail and say nothing at all: nothing prints, the program exits 0, and the numbers look plausible. compute-sanitizer is how you catch it.

An access that lands a few elements past the end of an array touches memory nobody is checking. Three habits close that gap.

Read the error status after every CUDA call, and know that launch errors and runtime errors surface at different moments. Then run compute-sanitizer before you trust a kernel. Point it at a vector add with no bounds guard and it stops at the first out-of-range access — which is a read, not a write, because the unguarded line is C[i] = A[i] + B[i] and the thread reads A[i] before it writes anything. The report names an invalid global read of 4 bytes. Build with -lineinfo and the report appends the file and line to the instruction offset, so "at vecAdd(...)+0x70" becomes "at vecAdd(...)+0x70 in vecadd.cu:4". Leave it off and you get the kernel name and the offset only.

The third habit catches honest code. A parallel sum adds the same numbers in a different order than a sequential one, so correct kernels fail exact-equality checks routinely. Verify within a tolerance instead.

Part 4 of the course. The sanitizer capture here is from a Tesla T4, the free Colab GPU, so you can reproduce it exactly.

What you'll learn:
• Synchronous and asynchronous CUDA errors, and which probe catches which
• The CUDA_CHECK macro, wrapped around every call
• compute-sanitizer on a kernel with no bounds guard, and how to read the report
• Why -lineinfo appends the source file and line to the kernel name and instruction offset
• Float addition is not associative: tolerance-based verification instead of exact equality
• How FMA and summation order affect reproducibility

Chapters:
0:00 Two kinds of error
3:16 The launch returns nothing
5:37 One macro for every call
7:07 The unchecked-launch bug
8:50 Four sub-tools, one command
10:23 Run it under the sanitizer
16:55 The exact-equality mistake
18:34 FMA shifts the last bits too

▶ Full GPU Programming in C/CUDA playlist:    • GPU Programming in C/CUDA: A Beginner's Co...  
▶ New to C? Programming Fluency — C from the ground up:    • Programming with C: A Clarity-First Introd...  
▶ Data Structures in C:    • Data Structures in C  
📦 Code, labs and answers: https://github.com/glassboxcomputing/...
🔔 Subscribe to Glass Box Computing:    / @glassboxcomputing  
Computer science, from the inside out.

#CUDA #ComputeSanitizer #CUDADebugging #MemorySafety #FloatingPoint #CUDAProgramming #LearnCUDA #GPUProgramming #CUDAC #ParallelProgramming #NVIDIA #GPUComputing


Auf dieser Seite können Sie das Online-Video CUDA Debugging: compute-sanitizer, Error Checks, Float Tolerance — GPU Programming in C/CUDA | Ep 4 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Glass Box Computing 14 August 2026 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 26 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!