L1 Beginner · Module 2: Why GPUs: hardware first principles

2.2Parallelism and what "parallelizable" means

A task is parallelizable when its pieces do not wait on each other. This chapter gives you the vocabulary, Amdahl's law to bound the payoff, and a precise answer to which parts of LLM inference parallelize and which never will.

Runs on a CPU or in the browser~15 min

By the end you will be able to

  • ✓Distinguish data parallelism, task parallelism and pipelines
  • ✓Spot dependencies that force work to run in order
  • ✓Use Amdahl's law to bound speedup from a serial fraction
  • ✓Explain how much parallel work a GPU needs, and where an LLM step finds it

Work is parallelizable when its pieces can run at the same time without waiting on each other’s results. The question is never “is this program parallel?” but “where are the dependencies?”.

Three kinds of parallelism

  • Data parallelism. The same operation on many independent items. Adding two vectors: element ii never needs element jj. This is what GPUs are built for.
  • Task parallelism. Different operations that do not depend on each other, such as tokenizing one request while another is decoding.
  • Pipelining. A chain of stages where each item must pass through in order, but different items can occupy different stages at once, like an assembly line. Pipeline parallelism across GPUs (14.3) works this way.

Dependencies

A dependency is any place where one result is needed to compute another. Three patterns come up constantly:

PatternExampleParallel?
Map: each output from its own inputyi=SiLU⁡(xi)y_i = \operatorname{SiLU}(x_i)Fully. nn items, nn workers, one step.
Reduction: many inputs into one∑ixi\sum_i x_i, softmax denominators, dot productsPartly. A tree finishes in log⁡2n\log_2 n steps (5.1).
Recurrence: step tt needs step t−1t-1token t+1t+1 needs token ttNot at all, along that chain.

A matrix multiply is a mix: each of the M×NM \times N outputs is independent (a map), and each output is a dot product (a reduction). That gives a lot of parallel work, which is why matmuls run so well on GPUs.

Amdahl’s law

If a fraction pp of the work parallelizes perfectly and the rest 1−p1-p must run serially, then on NN workers the speedup is

S(N)=1(1−p)+pN→  N→∞  11−p.S(N) = \frac{1}{(1-p) + \dfrac{p}{N}} \quad\xrightarrow{\;N \to \infty\;}\quad \frac{1}{1-p}.

The serial part sets a hard ceiling. From the lab below:

Parallel fraction pp64 workers1,024 workers16,896 workersLimit
0.98.8×9.9×10.0×10×
0.9939.3×91.2×99.4×100×
0.99960.2×506×944×1,000×
0.9999964.0×1,014×14,454×100,000×

How much parallel work is enough?

Lanes are only half the story. To hide memory latency, a GPU needs many more threads resident than it has lanes (2.5). An H100 can hold 2,048 threads per SM × 132 SMs = 270,336 threads at once. A kernel that launches fewer than about that many threads leaves part of the GPU idle.

Now look at LLM generation:

  • Across decode steps: a recurrence. Token t+1t+1 depends on token tt. One request’s steps can never run in parallel.
  • Within one step: about 7.5 billion independent multiply-adds for an 8B model. Plenty.
  • Across requests: different users’ requests are independent. Putting them in one batch multiplies the work per step.

Lab: Amdahl in numbers 🟢

labs/m02/2.2/amdahl.py
def amdahl(p: float, n: int) -> float:
return 1 / ((1 - p) + p / n)
Terminal window
python labs/m02/2.2/amdahl.py
output (excerpt)
parallel fraction 1 8 64 1024 16896 limit
0.9 1.0 4.7 8.8 9.9 10.0 10
0.99 1.0 7.5 39.3 91.2 99.4 100
0.999 1.0 7.9 60.2 506.2 944.2 1000

Sources

repo · BGEBEFORE-GPU-ENGINEERINGBEFORE-GPU-ENGINEERINGPhase 1: what parallelizable means, dependencies, and Amdahl's law.
book · FREGLYAI Systems Performance EngineeringChris FreglyGPU architecture chapters: how many threads a GPU needs in flight.

Check your understanding

0 / 4 answered
  1. 1.Which of these is a recurrence that cannot be parallelized along its chain?

  2. 2.95% of a program parallelizes perfectly. What is the maximum speedup on unlimited workers?

  3. 3.How many steps does a tree reduction of 1,024 numbers take with enough workers?

  4. 4.Why does batching requests help decode use a GPU?