0PricingLogin
CUDA Academy · Lesson

Guarding Against Out-of-Range

The if (i < n) bounds check.

You Often Launch Too Many

Thread counts come in fixed block sizes, so you almost always launch a few extra threads beyond your array length. Those spares need handling.

What Goes Wrong

An extra thread computes an index past the end of the array. If it writes there, it touches memory it does not own, causing a silent out-of-bounds bug.

All lessons in this course

  1. The Classic Index Formula
  2. Guarding Against Out-of-Range
  3. Rounding Up the Block Count
  4. Grid-Stride Loops
← Back to CUDA Academy