Pick a depth. Each prompt opens in your AI pre-loaded with the lesson. Click a row to preview the prompt.
Amdahl's Law is the uncomfortable arithmetic behind why a huge kernel-level speedup so often produces a disappointing end-to-end result: overall speedup is capped by the fraction of total time you actually sped up, not by how much faster that fraction got. If your fused kernel makes the compute portion of a step 3x faster but that portion was only 50% of step time to begin with, your best-case overall speedup is roughly 1.6x, not 3x — the other 50% (dataloader stalls, communication, host-device sync) is untouched and now dominates. This is why profiling-first (the previous task) and Amdahl's Law are really the same idea from two angles: profiling tells you which fraction is addressable, and Amdahl's Law tells you the ceiling on what optimizing that fraction alone can buy you. It's also why real optimization work is iterative — you fix the biggest bottleneck, watch a new one become the biggest, and repeat.
The demo computes Amdahl's speedup for a range of addressable fractions and per-fraction speedups, making the diminishing-returns table concrete instead of an abstract law.
local_speedup, roughly how fast the addressable 60% portion needs to get to hit an overall 2x speedup.def amdahl_speedup(addressable_fraction, local_speedup):
return 1 / ((1 - addressable_fraction) + addressable_fraction / local_speedup)
print(f"{'fraction':>10s} {'local 2x':>10s} {'local 5x':>10s} {'local inf':>10s}")
for frac in (0.9, 0.7, 0.5, 0.3, 0.1):
s2 = amdahl_speedup(frac, 2)
s5 = amdahl_speedup(frac, 5)
s_inf = amdahl_speedup(frac, 1_000_000) # approximates a "free" fraction
print(f"{frac:10.0%} {s2:9.2f}x {s5:9.2f}x {s_inf:9.2f}x")python3 main.py