Memory Layout and Data Movement on Accelerators
An accelerator is a chip designed for a specific type of computational workload, and an AI accelerator is designed for AI workloads. GPUs are the dominant type.
Same Model, Different Speed
Two programs can run the same model and feel very different in speed and running cost. Part of the reason is the software they are written in. A large part, however, is the hardware underneath them. Some optimization techniques work on any machine, while others only pay off once you understand the machine you are running on.
This article starts from the hardware side. It looks at the chips that run AI workloads and asks what those chips are built to do. The question it returns to again and again is simple: when a computation has a particular shape, which chip design uses its resources well?
What Makes a Chip an AI Accelerator
An accelerator is a chip designed for a specific type of computational workload. An AI accelerator is a chip designed for AI workloads.
The word specific is the key to the definition. A general-purpose processor is built to handle a wide mix of tasks. An accelerator gives up some of that breadth in exchange for doing one kind of work well. Within the family of AI accelerators, the dominant type today is the GPU, the graphics processing unit.
GPUs are not special because they are fast at everything. They are special because their design fits the arithmetic that AI models repeat constantly. The source also points to NVIDIA as the biggest economic driver of the AI boom in the early 2020s, which reflects how central this chip type became.
The link between models and hardware is older than the current boom. A shortage of sufficiently powerful computers was one factor in the first AI winter in the 1970s. The return of interest in deep learning in 2012 was closely tied to compute. One commonly cited reason for the influence of the AlexNet paper is that it was the first to successfully use GPUs to train neural networks. Before that, training a model at AlexNet's scale generally meant running on thousands of CPUs. A couple of GPUs were far more affordable for PhD students and researchers than thousands of CPUs, and that accessibility helped set off the deep learning research boom.
Hardware is also shaped by the kinds of data a computation handles. The source identifies three shapes. A scalar is a single value. A vector is an ordered list of values. A tensor generalizes these to higher-dimensional arrays. Compute units are specialized for one or more of these shapes, and chips often mix them. GPUs include tensor cores, and TPUs are built around tensor operations.
Two Designs for Spreading Work
The central difference between a CPU and a GPU is their purpose. A CPU is designed for general-purpose use, meaning it is meant to handle a wide mix of tasks. A GPU is designed for parallel processing, meaning it is meant to do many pieces of work at the same time. Most of the other differences between the two follow from that single choice.
A CPU has a few powerful cores. Many of them handle multi-threaded workloads well, but they are at their best when a task needs high single-thread performance. Running an operating system, managing input and output operations, and handling complex sequential processes all fall into this category.
A GPU takes the opposite approach. It has thousands of smaller, less powerful cores. Those cores are optimized for work that can be broken into many small, independent calculations, such as graphics rendering and machine learning. Each core is weaker than a CPU core, but the sheer number of them is what matters when the work splits cleanly.
Why Matrix Multiplication Splits Cleanly
GPUs are optimized for tasks that can be broken into many smaller, independent calculations. The operation that makes up most machine learning workloads is matrix multiplication, and it is highly parallelizable. The key property is independence. If one piece of the answer does not need another piece's result, the two pieces can be worked out at the same time on different cores.
The same logic scales up. A real model multiplies matrices far larger than two by two, which means far more independent entries. This is why a chip with thousands of cores can keep many of them busy on one multiplication.
Multiplying two 2 by 2 matrices entry by entry
Multiply A = [[1, 2], [3, 4]] by B = [[5, 6], [7, 8]]. Each entry of the result C is a row of A combined with a column of B.
- 1Entry C11
Take row 1 of A and column 1 of B: $C_{11} = 1 \times 5 + 2 \times 7 = 19$.
- 2Entry C12
Take row 1 of A and column 2 of B: $C_{12} = 1 \times 6 + 2 \times 8 = 22$. This entry uses the same row of A as C11 but a different column of B.
- 3Entry C21
Take row 2 of A and column 1 of B: $C_{21} = 3 \times 5 + 4 \times 7 = 43$.
- 4Entry C22
Take row 2 of A and column 2 of B: $C_{22} = 3 \times 6 + 4 \times 8 = 50$.
- 5Check dependence
No entry of C is used as an input to any other entry. Each one is computed directly from the original numbers in A and B, so all four can be computed at the same time.
C = [[19, 22], [43, 50]]. Four independent entries means four pieces of work that a parallel chip can assign to different cores.
Tracing a Batch on Each Chip
Consider what happens as a batch of independent matrix entries arrives at each kind of chip, starting with the CPU. The CPU has a few powerful cores, so the batch is spread across a small number of strong workers. Each worker takes on a share of the entries. Because each core is powerful, it handles its share with high single-thread performance. The batch is finished by a handful of workers rather than a crowd.
Now run the same batch on a GPU. The same entries are spread across thousands of smaller cores. Each core is less powerful, but because the entries are independent, none of those cores has to wait for another. At any moment, many entries are in progress together. The state of the batch changes from a few entries being worked on slowly to a large set being worked on at once.
Notice what changed and what did not. The work itself is the same, and the answer is the same. What changed is how the work is spread across hardware. That is the core idea behind matching a chip to a workload: the shape of the computation determines which design makes good use of its resources.
Why Inference Hardware Is Tuned Differently
Many chips can handle both training and inference, but one clear trend is the rise of chips specialized for inference. Inference means running a trained model to produce outputs. A survey by Desislavov and colleagues (2023) reports that inference can exceed the cost of training in commonly used systems, and that inference accounts for up to 90 percent of machine learning costs for deployed AI systems. For anyone deploying models, that makes inference hardware a central decision.
Inference hardware is often optimized for lower precision and faster memory access. The reason is that inference aims to minimize latency, meaning the delay before an output is produced. A chip that is ideal for building a model is not automatically ideal for serving it, because the priorities change once the model is in use.
Weighing Three Hardware Characteristics
A chip's specification sheet holds many details, and only some of them matter for a given use case. Across use cases, three characteristics stand out. They should be weighed together rather than read one at a time.
Computational capability describes how much work the chip can do. Memory size and bandwidth describe how much data it can hold and how quickly that data can move. Power consumption describes the energy it draws while doing that work. Because each one is a different kind of limit, improving one does not automatically improve the others. A chip that looks strong on computation may still be a poor fit if its memory cannot keep up with the work, and a chip that looks efficient may not have the capability a workload needs.
Mistakes When Choosing a Chip
Common mistake Assuming a GPU is faster at every task
What it looks likeRunning an operating system or handling a long chain of dependent sequential steps on a GPU.
Why it failsGPUs are designed for parallel processing. CPUs are the better fit for work that needs high single-thread performance, such as running an operating system and managing input and output.
Do this insteadMatch the chip to the shape of the work. A GPU is strong when the work splits into many independent calculations.
Common mistake Believing more cores always help
What it looks likeExpecting a few powerful cores to behave like thousands of small ones on the same batch.
Why it failsAdding cores only helps when the work can be divided into independent pieces. GPU cores are individually weaker than CPU cores, so their advantage depends on the number of independent calculations.
Do this insteadAsk whether the computation splits cleanly into independent pieces before counting cores.
Common mistake Treating training and inference hardware as identical
Why it failsInference is often tuned for lower precision and faster memory access because it aims to minimize latency. Inference can also account for up to 90 percent of machine learning costs for deployed systems.
Do this insteadWhen choosing hardware for deployed models, weigh inference priorities such as latency and cost separately.
Common mistake Judging a chip by one specification alone
Predicting Speed on Independent Work
What do you think happens?
A batch contains 1,000 independent matrix entries. Which chip is likely to finish the batch sooner?
Reveal answer
The GPU, because the entries are independent and can be spread across thousands of cores at once.
Each GPU core is weaker than a CPU core. The advantage comes from the number of cores working at the same time. Since no entry waits for another, many entries can be in progress together.
Return to the 2 by 2 example. Does computing C21 require the result of C11, C12, or C22? What does your answer imply about whether the four entries can run together?
Hints
- Look at which numbers each entry uses. Only the original entries of A and B are used.
- If no entry depends on another entry's output, the dependency chain is empty and the entries are independent.
Putting the Pieces Together
A CPU and a GPU differ in purpose before they differ in anything else. The CPU is built for a wide mix of tasks with a few powerful cores. The GPU is built for parallel work with thousands of smaller cores. Matrix multiplication, the core operation of most machine learning workloads, splits into independent entries, which is exactly the shape a GPU is built to exploit. Inference hardware is often tuned for lower precision and faster memory access, and the three characteristics of computation, memory, and power should be weighed together when choosing a chip.
Key Takeaways
- An accelerator is a chip designed for a specific type of computational workload, and an AI accelerator is designed for AI workloads. GPUs are the dominant type.
- CPUs have a few powerful cores suited to general-purpose and sequential work, while GPUs have thousands of smaller cores suited to many independent calculations.
- Matrix multiplication is highly parallelizable because each output entry can be computed independently, so many workers can run at the same time.
- Inference hardware is often optimized for lower precision and faster memory access, since inference aims to minimize latency and can account for up to 90 percent of machine learning costs.
- Computational capability, memory size and bandwidth, and power consumption should be weighed together when choosing a chip.