Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 13

Amdahl's Law: Calculating Theoretical Speedup

Recommended resources

Introduction

In our last lesson, we explored how explicit data parallelism, using SIMD, allows a single instruction to perform the same operation on many pieces of data at once. This, along with instruction-level parallelism, is a cornerstone of modern high-performance computing. A natural question then arises: if we can add more processors, or build wider SIMD units, can we make any program arbitrarily fast? Is there a limit to the speedup we can achieve?

This lesson introduces a fundamental principle that answers this question: Amdahl's Law. This law provides a simple but profound mathematical formula to predict the theoretical maximum speedup of a system when only a part of it is improved. For anyone interested in performance engineering, Amdahl's Law serves as a crucial reality check, highlighting why the inherently sequential part of any task ultimately governs the total performance gain.

Your learning objective for today is to state Amdahl's Law and calculate the theoretical speedup for a given parallelizable workload. This concept will shape your intuition about where to focus optimization efforts throughout your career.


The Ideal vs. The Reality of Speedup

Imagine you have a task that takes 100 seconds to run on a single processor. Ideally, if you could use 10 processors, you might expect the task to finish in 10 seconds—a 10x speedup. If you had 100 processors, you might hope for it to finish in 1 second—a 100x speedup. This concept is known as linear speedup.

Amdahl's law and speedup in concurrent and parallel processing explained with example

This video from Karan Jetli Live sets the stage by contrasting the ideal of linear speedup with the more realistic model presented by Amdahl's Law.

Watch from the beginning to the discussion on speedup to understand the concept of ideal, linear speedup. Then, continue from the introduction to Amdahl's Law, where the video explains that real-world programs have both serial and parallel components, which prevents linear speedup.

The critical insight, as the video explains, is that virtually no non-trivial program is 100% parallelizable. Most programs consist of:

  • A serial portion: Code that must be executed sequentially, one instruction after another. This can include tasks like initialization, reading configuration files, or final result aggregation.
  • A parallel portion: Code that can be divided among multiple processors or SIMD lanes, such as processing the pixels of an image or updating the elements of a large matrix.

No matter how many processors you throw at the parallel portion, the serial portion's execution time remains a fixed bottleneck. This is the essence of Amdahl's Law.


Formulating Amdahl's Law

Let's formalize this intuition. We can derive the law by thinking about the total execution time of a program before and after an enhancement. We'll use the following variables:

  • : The fraction of the program's original execution time that can be parallelized or enhanced. This value is between 0 and 1.
  • : The fraction of the program's execution time that is inherently serial and cannot be enhanced.
  • : The speedup factor for the enhanced portion. For example, if we make the parallel part run on 8 processors, .

Amdahl's Law in COA: Basics, Proof, and CPU Performance Explained

The "Amdahl's Law in COA" video by Engineering Funda provides a clear, step-by-step derivation of the formula.

Watch the segment from the explanation of components to follow the derivation of the overall speedup formula. The instructor uses a helpful analogy of old vs. new CPU time.

As explained in the video, we can express the overall speedup as the ratio of the old execution time to the new execution time.

  1. Old Execution Time: Let's normalize the total time before any improvements to 1 unit.

  2. New Execution Time: The new time is the sum of the time for the serial part (which doesn't change) and the time for the enhanced parallel part.

    • Time for the serial part =
    • Time for the enhanced part = (The original time divided by its speedup factor )

    So, the total new execution time is:

  3. Overall Speedup: The overall speedup, , is the ratio .

This is Amdahl's Law. It elegantly captures the relationship between the parallelizable fraction of a task, the improvement applied to that fraction, and the resulting overall system speedup.


The Law of Diminishing Returns

Let's apply the formula to build your intuition. Suppose you optimize a part of your code that accounts for 80% of the execution time (). You use 4 processors to make this part 4 times faster ().

Even though you made 80% of the code 4 times faster, your overall speedup is only 2.5x, not 4x. The remaining 20% of serial code holds you back.

What if you use an infinite number of processors ()? The term goes to zero.

For our example where , the maximum possible speedup is:

This is a profound result. Even with infinite processors, a program that is 80% parallel can never be more than 5 times faster. The 20% serial portion creates a hard ceiling on performance.

The graph below, based on Amdahl's Law, visualizes this effect. Notice how for any parallelizable fraction less than 100%, the speedup curve flattens out, approaching a horizontal asymptote defined by .

Amdahl's law

This graph illustrates the theoretical speedup of a system according to Amdahl's Law. Each curve represents a different fraction of the program that can be parallelized (from 50% to 99%). The x-axis is the speedup applied to the parallel part (e.g., number of processors) on a logarithmic scale. The y-axis is the overall speedup. It clearly shows that the serial portion imposes a strict limit on the maximum achievable speedup.


Solving Problems with Amdahl's Law

As a performance engineer, you'll often use Amdahl's Law to reason about potential optimizations. For instance, you might need to determine how much of a program must be parallelized to meet a performance target.

1 What is Amdahl's Law? 2 What Kinds of Problems Do We ...

This tutorial from the University of Florida provides concise examples for three common types of problems involving Amdahl's Law.

Please read the entire document. Pay close attention to the three problem types it outlines: Predicting overall speedup given the enhanced fraction and its improvement. Finding the required improvement for the enhanced part to achieve a target overall speedup. Determining what fraction of the code must be enhanced to meet a performance goal.

Let's work through an example of our own, relevant to your AI goals.

Scenario: You are optimizing an AI inference pipeline. Profiling shows that 95% of the time is spent in a large matrix multiplication (GEMM) kernel, which is highly parallelizable. The remaining 5% is spent in serial setup and file I/O.

Question: What is the overall speedup if you run the GEMM kernel on a GPU that makes it 64 times faster?

  • Identify variables:

    • The fraction that can be enhanced, .
    • The speedup of the enhancement, .
  • Apply Amdahl's Law:

Conclusion: Even though the core GEMM operation is 64 times faster, the overall pipeline speedup is only about 15.4x. The 5% serial portion dramatically limits the end-to-end gain. This illustrates why optimizing the entire system, including data loading and preprocessing, is critical in real-world applications.

Now, consider the maximum theoretical speedup for this pipeline:

No matter how powerful the GPU, this pipeline can never be more than 20 times faster than the original, single-processor version, unless you also reduce the 5% serial portion.


Conclusion

In this lesson, we have formalized the intuition that serial bottlenecks limit parallel performance. Amdahl's Law gives us the tool to quantify this limit precisely. As someone aiming for a career in low-level optimization, this law is not just an academic formula; it's a guiding principle for your work. It teaches you to be a detective, to use profilers to find the parts of a program where your optimization efforts will yield the greatest returns—the parts with the largest .

Key Takeaways:

  • Amdahl's Law states that the maximum speedup from an improvement is limited by the fraction of time that the improvement can be used.
  • The formula is , where is the parallelizable fraction and is the speedup of that fraction.
  • The performance of any program is ultimately constrained by its serial portion.
  • The theoretical maximum speedup with infinite processors is .
  • This principle dictates that performance engineers must focus on optimizing the "common case"—the parts of the program that consume the most time.

We have now examined parallelism on a CPU (ILP, SIMD) and the theoretical bounds of that parallelism (Amdahl's Law). But GPUs are the kings of parallelism in AI. What makes their design so different from CPUs? In our next lesson, we will explore the fundamental design philosophies that distinguish latency-oriented CPUs from throughput-oriented GPUs, setting the stage for our deep dive into modern GPU architecture.