6.2.5 · D1GPU Architecture

Foundations — Warps and warp scheduling

1,928 words9 min readBack to topic

This page assumes nothing. Before you read Warps and warp scheduling proper, we build every word, symbol, and picture it leans on. Read top to bottom; each block earns the next.


0. What is a "thread" here?

Before warps, we need the atom they are made of.

Threads never live alone. They come in a nested set of containers, which we draw next.

  • A grid is the whole army of threads for one launch.
  • A block is a team inside the grid — threads in the same block can talk via fast shared memory.
  • A warp is the smallest squad the hardware actually moves: 32 threads glued together.

This nesting is exactly the subject of Thread-Blocks-and-Grids; here we only need to see the boxes.


1. threadIdx — a thread's name tag

blockDim — how big is the block?


2. Flattening: from a name tag to a line position

The hardware lines all threads up single-file. To find a thread's spot in that line we read the block row by row (x fastest, then y, then z). This is called row-major order.

The picture shows why row-major matters: it decides which threads land in the same warp. A single warp is a slice of 32 consecutive line positions — so a warp can span the boundary between two rows.


3. The number 32, floor, and ceiling

Now we can define the warp arithmetically.

Two new symbols appeared. Meet them:


4. Lockstep, SIMT, and the mask

But branches exist — sometimes some threads should skip an instruction. The hardware handles this with a mask.


5. Stalls, cycles, and latency hiding


6. Occupancy — the readiness meter

Two symbols support it:

  • SM (Streaming Multiprocessor): one physical engine on the GPU that holds many warps and contains the schedulers. Think of it as one factory floor; the whole GPU has many.
  • Warp scheduler: the traffic controller inside an SM that each cycle picks a ready warp to issue.

Why occupancy can't be pushed to 1 for free: each warp claims registers (Register-Pressure) and shared memory. More warps → less per warp. That trade-off is the bridge from these foundations into the real tuning story.


Prerequisite map

Thread one worker one index

threadIdx and blockDim coordinates

Linear index row-major flatten

Floor and ceiling rounding

Warp 32 consecutive threads

Lockstep and SIMT

Active mask on-off switches

Warp divergence serial replay

Cycle clock tick

Latency L waiting

Stall no progress

Latency hiding swap warps

Occupancy fullness meter

Warps and warp scheduling


Equipment checklist

Self-test: cover the right side and answer each aloud before you read on.

What is a thread, in one sentence?
One worker running one copy of the program on its own data slice.
What do threadIdx and blockDim describe?
A thread's coordinate label, and how many threads sit along each axis of the block.
Flatten thread (3,2,0) in a (16,4,1) block.
.
What does do, and what does do?
Floor rounds down; ceiling rounds up.
Which one gives a thread's warp ID, and which gives the warp count?
Floor gives the warp ID; ceiling gives the number of warps.
How many warps for a block of 136 threads?
.
What does "lockstep / SIMT" mean?
All 32 threads run the same instruction on the same clock tick, each with its own data.
What is the active mask?
A 32-bit on/off switch deciding which threads act on the current instruction.
Why is divergence slow?
Both branches run one after the other with opposite masks, since a warp runs only one instruction at a time.
What is a stall, and how is it hidden?
A warp unable to progress; another ready warp is swapped in for free to fill the empty cycles.
Give the formula for warps needed to hide latency with instructions between waits.
.
Define occupancy.
Active warps per SM divided by max warps per SM.