How does a GPU organize work?
A kernel is the function you ask the GPU to run. A thread is one execution of that function. Blocks group threads, and a grid contains the blocks in one launch.
See the connection
One launch. Eight blocks. Many threads.
Follow one worker through the example: block 2, thread 5.
Thread 5 → item 261
2 × 128 + 5 = 261
Next: Session 7 opens the same block to show its four warps.
Give each thread an item
Suppose you want to add 1,000 pairs of numbers. Choose 128 threads per block for this example.
Eight blocks launch 1,024 threads. Each thread calculates its item number, then checks that the item exists:
item = block_number * 128 + thread_number
if item < 1000:
output[item] = input_a[item] + input_b[item]
This is pseudocode. The last 24 threads skip the addition.
Block 2, thread 5 handles item 261: 2 × 128 + 5. Numbering starts at zero.
Work is not hardware
A thread is not a reserved physical core. The GPU schedules these threads on its available hardware. Blocks should not assume they finish in numerical order.
Try it yourself
How many 128-thread blocks cover 2,050 items?
Check your answer
Seventeen. They launch 2,176 threads, so 126 skip the work after the bounds check. Changing the grouping does not change which additions are required.