GPU Lab / interactive book
GPU mapSource ↗

CHAPTER 6

How can work continue during a wait?

Trace a load dependency, then see when another ready warp can start its next instruction.

Start with the operation

PyTorch

import torch

x = torch.tensor([1., 2., 3., 4., 5.], device="cuda")
y = x * 2
z = y * 2
print(z.cpu())
Desktop setup

The five inputs from the opening chapters are scaled twice: y contains the first products and z the second. You choose the tensors and operations; PyTorch selects implementations, allocates the results and arranges their launches. Copying z to the CPU lets Python print its values.

A calculation may have to wait for a loaded input. We will model that dependency with two repetitions of LD → MUL → ST: load, multiply, store. This is a deliberately chosen instruction stream, not a compiler trace of the PyTorch program. The model does not compute its tensor values or infer how PyTorch assigns them to warps.

Run the examples below in your browser with no installation or GPU required. The browser simulates the calculation; it does not execute PyTorch or GPU code. To run the PyTorch snippet itself, use a Python environment with PyTorch and an NVIDIA GPU.

Idea 1 of 2

Follow one warp through a load wait

Definitions

Streaming multiprocessor (SM)
A GPU unit on which a block’s threads run, grouped into warps. This model begins with warps assigned to one SM.
Cycle
One discrete step of this teaching machine, not a measured duration on a GPU.
Load latency
The number of model cycles from issuing a load until its value is ready for the dependent multiply.

Begin with one warp on an SM. A load starts a wait; its dependent multiply cannot start until the value is ready. In the diagram, ready means the next instruction can start; waiting means its input is still unavailable.

The chosen sequence is LD, MUL, ST, LD, MUL, ST. The teaching machine starts at most one instruction each cycle; an idle cycle starts none. A latency of 6 means a load started at cycle 0 becomes usable at cycle 6. Watch what can happen between those two events. The model ends when the last store starts; it does not model a later wait for the store to complete.

Try it

With one warp, predict where idle cycles appear. Run and step past the first load. Change only load latency to 1, run again, and explain what happened to the waits.

Predict the result, then press Run.

Idea 2 of 2

Give the scheduler another ready warp

One warp left gaps while waiting for data. Could the SM use those gaps for another warp? That requires other work already on the SM and ready to continue.

Definitions

Resident warp
A warp already assigned resources on an SM. Every warp in this experiment is resident from the start.
Instruction issue
Selecting a ready warp and starting its next instruction. An issue slot is one opportunity to do that; this teaching machine has one per cycle.
Scheduler
The mechanism that chooses which ready resident warp issues next. This teaching scheduler searches in round-robin order after the last warp selected.
Issue-slot use
Issued instructions divided by elapsed model cycles. This describes how many teaching issue slots were used.

All resident warps begin ready at cycle zero. After each issue, the scheduler searches from the next warp, skipping waiting and completed warps. When one waits for its load, another may have an instruction ready. The cards show each warp immediately before the selected cycle issues.

Keep latency fixed and change only the number of resident warps. Each extra warp adds another six instructions, so the total work changes too. Compare idle slots and issue-slot use; elapsed cycles for these different workloads do not give a speedup.

This teaching SM starts with its warps already resident and does not calculate resource limits or competition for memory bandwidth. Its single issue slot and fixed load latency describe this experiment, rather than a particular GPU.

Try it

Predict whether two ready warps can fill every wait at latency 6. Run, inspect an idle cycle if one remains, then change only the warp count to 4. Explain the difference using readiness and the extra work.

Predict the result, then press Run.

Optional: place the warps in the bigger picture

The experiments began with warps already resident. This separate ownership map puts their blocks on two SMs. It uses three blocks of 64 threads, rather than the five tensor inputs in the opening. Inspect the block with two warps: warp membership follows thread indices, while available resources constrain which blocks can reside on an SM.

Inside a GPU: SMs → blocks → warps → threads

Separate placement example: 3 blocks, 64 threads per block.

GPU
SM 0
Block A64 threads · 2 warps · stays on this SM
Warp 0 · 32 threads

Threads 0–31 within block A

012345678910111213141516171819202122232425262728293031
Warp 1 · 32 threads

Threads 32–63 within block A

Block C64 threads · 2 warps · stays on this SM
Warp 0 · 32 threads

Threads 0–31 within block C

Warp 1 · 32 threads

Threads 32–63 within block C

SM 1
Block B64 threads · 2 warps · stays on this SM
Warp 0 · 32 threads

Threads 0–31 within block B

Warp 1 · 32 threads

Threads 32–63 within block B

Each block here contains two warps. A lane is a thread’s position within its warp; each tile shows a thread’s index within block A. Warps never combine threads from different blocks. This shows one possible placement, not a chip floor plan or an execution timeline. Placement and how much work can execute at once depend on available resources.

Blocks can make progress independently. The SM can choose ready warps from any of the blocks it holds. Another block can run while some threads in the first are waiting or some lanes are unused, when resources allow. A block does not have to finish before another can start.

In chapter 1’s four-thread exercise, each block uses one partially filled warp: 4 of 32 lanes have threads. The other 28 positions do not prevent another block from running, and cannot be filled with threads from another block.

Try a new case

Apply it

A resident warp is waiting on a load, and another resident warp is ready. Must the next issue slot be idle? Explain what this model can tell you, and whether doubling the resident warp count proves a speedup.

Compare your answer

The ready warp can issue: the scheduler skips the waiting warp. Adding resident warps also adds six instructions per warp in this experiment. Compare issue-slot use and idle slots, but do not turn the elapsed cycles of different workloads into a speedup. Actual residency and performance need resource and hardware evidence beyond this model.

References

Use these official references to check the concepts and code on this page.

These browser exercises do not run an installed PyTorch or CUDA toolkit. For optional local execution, choose documentation matching your installed tools. Links open online in a new tab; the questions and answer comparisons below work offline.

Use the documentation

Use the references to explain each answer, then apply it to this page’s example. No installation is needed.

Install GPU Lab

Give GPU Lab its own icon and window. All lessons and simulators work offline once the course is saved.

Use your browser’s install option:

If your browser has no install option, try Chrome or Edge.

App status

Version

Checking for updates

Offline access

Not saved for offline use

Save all lessons, browser simulators, diagrams and example files. Desktop execution needs separate PyTorch or CUDA/GPGPU-Sim tools; their installations are not part of this offline download. External links need internet access.