Table of Contents
Hardware selection was simple before the AI application explosion: CPU for most work, GPU if you need graphics processing. Now it’s significantly more complex — you also need to know when to use a TPU, and when running on a GPU is actually slower than CPU (and why).
TL;DR
CPU has a few powerful cores, excellent at sequential logic and complex control flow. GPU has thousands of weak cores, excellent at doing massive amounts of identical computation simultaneously. TPU is Google’s ASIC designed specifically for neural network matrix multiplication — on specific workloads, both performance and energy efficiency far exceed GPU. Choosing wrong isn’t just a performance problem; at scale the cost differences are substantial.
CPU: General-Purpose King, But Not Universal
Modern CPUs (Intel Xeon, AMD EPYC) are designed to let each core execute arbitrary instruction sequences as fast as possible. This requires sophisticated mechanisms:
Out-of-order execution: CPUs don’t strictly execute in program order — as long as data dependencies allow, they execute future instructions early.
Branch prediction: CPUs guess if/else branch outcomes and start executing ahead, rolling back on wrong predictions. This dramatically reduces latency, but wrong predictions have costs (Spectre/Meltdown exploited this).
Cache hierarchy: L1/L2/L3 caches keep data as close to cores as possible, avoiding main memory waits (DRAM is roughly 100x slower than L1 cache).
These mechanisms make CPUs excellent at complex control flow: web servers, database queries, complex business logic. But for tasks requiring massive identical computation simultaneously, CPU core counts (typically 8–64) become the bottleneck.
CPU-appropriate AI workloads:
- Small model fast inference (batch size 1 real-time serving)
- Pre/post-processing (tokenization, data cleaning)
- CPU inference for small transformer models is sometimes comparable to GPU and significantly cheaper
GPU: Training Workhorse, But Often Misunderstood
GPU design philosophy is the opposite of CPU: use thousands of simple compute cores to execute the same operation simultaneously.
An NVIDIA H100 has 16,896 CUDA cores (plus many more Tensor Cores). These cores aren’t good at complex logic, but for regular operations like matrix multiplication, their massive parallel execution capability gives throughput that far exceeds CPU.
GPU-appropriate scenarios:
- Deep learning training (massive matrix multiplication)
- Batch inference (large batch sizes that can fill GPU cores)
- Scientific computing (fluid dynamics simulation, molecular dynamics)
- Graphics rendering (the original design purpose)
Common GPU misuse:
- Real-time inference for individual requests (batch size 1) — GPU can be slower than CPU because data transfer overhead exceeds compute time
- Control-flow heavy logic (many if/else branches) — GPU’s SIMT architecture degrades severely under branch divergence
graph LR
A[Task Type] --> B{Complex control flow?}
B -->|Yes| C[CPU preferred]
B -->|No| D{Large batch?}
D -->|Yes| E[GPU preferred]
D -->|No| F[CPU may be cheaper]
TPU: Google’s ASIC for TensorFlow
TPUs (Tensor Processing Units) are AI accelerators Google has been building internally since 2016. Not a general-purpose accelerator — purpose-built for the most common operation in neural network training and inference: matrix multiplication.
TPU’s key design: the Systolic Array
Traditional GPUs doing matrix multiplication have each compute unit reading data from memory. Systolic arrays let data “flow through” an array of compute units — data passes between units, each doing computation as data passes through, without repeated memory reads/writes. This dramatically reduces memory bandwidth pressure.
TPU-appropriate scenarios:
- Large-scale deep learning training (Google trains PaLM and Gemini with TPU Pods)
- Batch inference for JAX/TensorFlow workloads
- Models with dense matrix operations and simple control flow
TPU limitations:
- No native PyTorch support; requires XLA compilation
- Not suitable for small batch, high control-flow models
- Only accessible through Google Cloud TPU; can’t purchase hardware
Real Cost Comparison
This is the part most articles skip. Using Google Cloud pricing as an example (2024 pricing, subject to change):
| Hardware | Specs | Hourly Cost | Best For |
|---|---|---|---|
| n2-standard-8 CPU | 8 vCPU, 32GB RAM | ~$0.38 | Small model inference, pre/post-processing |
| T4 GPU | 16GB VRAM | ~$0.35–$0.70 | Medium model inference |
| A100 GPU | 40/80GB VRAM | ~$2.93–$3.67 | Large model training and inference |
| H100 GPU | 80GB VRAM | ~$6–$10 | Latest large model training |
| TPU v4 | 32GB HBM | ~$3.22 | Large-scale JAX/TF training |
The key is utilization: if your GPU utilization is only 30%, you’re wasting 70% of your spend. The gpu_util field in nvidia-smi is the first metric to check.
Which Scenario Gets Which Hardware
Online inference service (low latency requirements):
- Small batch services: CPU may be sufficient, or T4 GPU
- Low-latency large model serving: A100/H100, but verify GPU utilization
Training large models:
- JAX/TF workloads: TPU v4/v5 on Google Cloud is the optimal choice
- PyTorch workloads: H100 clusters
Local development and experimentation:
- Apple Silicon M-series chips’ unified memory architecture (CPU and GPU sharing memory) gives surprisingly strong advantages for medium-sized model inference
- Consumer GPUs (RTX 4090) match A100 training efficiency for workloads that fit in VRAM at a fraction of the cost
Summary
CPU vs GPU vs TPU selection is ultimately a function of “your workload’s computation pattern” and “cost budget.” No single hardware is optimal in all scenarios. What engineers need to do is understand which pattern their workload falls into, then match appropriate hardware — not reach for GPU by default because “GPU runs AI.”
References
Answers come from this article only. Click any prompt below or open the chat at the bottom right.
🇺🇸 English
Picking the wrong processor for an AI workload isn't just a technical footnote — at scale, it's the difference between a reasonable cloud bill and lighting money on fire. Back before the AI boom, hardware choices were easy. CPU for almost everything, GPU if you needed graphics. Now? You've also got to know when a TPU makes sense, and — here's the counterintuitive part — when running on a GPU is actually *slower* than a plain CPU.
Let me give you the whole picture in one breath, then we'll unpack it.
A CPU has a handful of very powerful cores. It's brilliant at sequential logic and complicated decision-making. A GPU flips that: thousands of weak little cores, all doing the same math at the same time. And a TPU is Google's custom chip, built for one thing — the matrix multiplication at the heart of neural networks — and it's pushed that one thing to the extreme, beating GPUs on both speed and energy efficiency for the right jobs.
So let's start with the CPU. Think Intel Xeon, AMD EPYC. The whole design goal is to let each core rip through any arbitrary sequence of instructions as fast as physically possible. And to pull that off, CPUs do some genuinely clever things.
First, out-of-order execution. The chip doesn't stubbornly run your instructions in the exact order you wrote them. If the data's ready, it'll reach ahead and do future work early. Second, branch prediction. When your code hits an if-else, the CPU *guesses* which way it'll go and starts running down that path before it even knows the answer. Guess right, you save a ton of time. Guess wrong, you roll back and pay a penalty — and fun fact, this is exactly the mechanism that Spectre and Meltdown exploited. And third, the cache hierarchy — those L1, L2, L3 caches that keep data hugging close to the core. Why does that matter? Because reaching all the way out to main memory is roughly a hundred times slower than hitting L1. A hundred times.
All of this makes the CPU a monster at complex control flow — web servers, database queries, tangled business logic. But when the job is "do this same simple calculation a million times at once," you run into a wall: a CPU only has maybe eight to sixty-four cores. That's your bottleneck.
So where does a CPU shine for AI? Small models doing fast, real-time inference — one request at a time. All the pre- and post-processing, like tokenization and data cleaning. And honestly, for small transformer models, CPU inference is sometimes right there with a GPU in speed, and dramatically cheaper.
Now the GPU. Its design philosophy is the mirror image of the CPU. Instead of a few genius cores, you get thousands of simple ones, all executing the same operation simultaneously. An NVIDIA H100 packs nearly seventeen thousand CUDA cores, plus a whole set of dedicated Tensor Cores on top. Each one is bad at complex logic — but for regular, predictable math like matrix multiplication, that army of cores delivers throughput a CPU can't touch.
That makes GPUs perfect for deep learning training, which is just matrix multiplication at enormous scale. For batch inference, where big batches keep all those cores busy. For scientific computing — fluid dynamics, molecular simulations. And of course graphics rendering, which is what they were born to do.
But here's where people get burned. If you're serving individual real-time requests — batch size of one — a GPU can actually be *slower* than a CPU. Why? Because the time spent shuffling data over to the GPU and back is longer than the computation itself. You paid the shipping cost for a tiny package. The other trap is control-flow-heavy code, lots of branching if-else logic. GPUs use what's called a SIMT architecture, and when different cores want to take different branches — what's called branch divergence — performance falls off a cliff.
There's a simple decision tree here. Is your task heavy on complex control flow? Go CPU. If not — does it run in large batches? Big batches, go GPU. Small batches? A CPU might just be cheaper.
Which brings us to the TPU — Tensor Processing Unit. Google's been building these in-house since 2016. It is not a general-purpose accelerator. It's purpose-built for the single most common operation in training and inference: matrix multiplication.
The secret sauce is something called a systolic array. Picture a normal GPU doing matrix math — every compute unit is constantly reading data from memory, doing its bit, writing back. A systolic array does something more elegant: the data *flows through* a grid of compute units, passing from one to the next, and each unit does its little piece of the calculation as the data streams past. No constant trips back to memory. And that slashes the memory bandwidth pressure that usually bottlenecks these workloads.
So TPUs are fantastic for large-scale training — Google trains PaLM and Gemini on TPU Pods. Great for batch inference on JAX or TensorFlow. Great for dense matrix models with simple control flow. The catches? No native PyTorch support — you go through XLA compilation. It's poor at small-batch, branch-heavy models. And you can't buy one; it's Google Cloud rental only.
Now let's talk money, because this is the part most articles skip. Rough Google Cloud numbers, and prices move, but for orientation:
A plain eight-vCPU CPU instance runs you under forty cents an hour — good for small-model inference and pre/post-processing. A T4 GPU, somewhere around thirty-five to seventy cents an hour, solid for medium models. An A100, you're looking at roughly three to three-and-a-half dollars an hour, that's your large-model training and inference tier. An H100, the newest big gun, six to ten dollars an hour. And a TPU v4 sits around three-twenty an hour, for large-scale JAX and TensorFlow training.
But here's the thing that actually determines your bill: utilization. If your expensive GPU is only running at thirty percent, you are literally paying for seventy percent of nothing. The very first number to go check is the GPU utilization field in `nvidia-smi`. Before you optimize anything else, look at whether you're even using what you're renting.
So how do you map all this to real scenarios? For online inference with tight latency needs: small services can often live on a CPU, or a modest T4. For low-latency large-model serving, reach for an A100 or H100 — but verify that utilization number. For training large models: JAX or TensorFlow, TPU v4 or v5 on Google Cloud is your sweet spot; PyTorch, go with H100 clusters.
And don't sleep on local development. Apple Silicon — the M-series chips — has this unified memory architecture where the CPU and GPU share the same memory pool, and it's surprisingly strong for medium-sized model inference. And a consumer RTX 4090 can match A100 training efficiency for anything that fits in its VRAM, at a tiny fraction of the cost.
So let me leave you with the three things that actually matter. One: these chips aren't better or worse, they're *different shapes* — CPU for complex logic, GPU for massive parallel sameness, TPU for matrix math taken to the extreme. Two: the GPU is not automatically the AI answer. For single small requests, it can lose to a CPU, and a chip running at thirty percent utilization is burning your budget. And three: the real skill isn't knowing the hardware specs — it's recognizing which computation pattern your workload actually is, and matching to that. Don't reach for a GPU just because "GPUs run AI." Match the shape of the work to the shape of the chip, and the cost takes care of itself.
🇹🇼 中文
同樣一段運算,放到 CPU 上是一種跑法,換到 GPU 又是另一回事,有時候搬到 TPU 還能再快上一截。為什麼會這樣?
答案其實很單純:每一種晶片,都是為了不同「類型的計算」而最佳化的。CPU 處理通用任務,GPU 擅長大量平行的數學運算,TPU 則專門針對機器學習的工作負載做了優化。正因為三者鎖定的計算型態不同,同一個問題落在它們身上,表現自然差很多。
先看 CPU。它是通用型處理器,設計目標就兩個字:彈性。網頁伺服器、資料庫、作業系統、應用程式邏輯——這些全是它的守備範圍。這類工作有個共同特徵,就是每一步都可能不一樣。收到一個請求、檢查身份、查資料、套用商業規則、回傳結果,整個過程充滿了分支判斷跟決策。CPU 就是為這種工作而生的。所以它的策略是:用少量但強大的核心,讓每個核心都能有效率地應付各式各樣不同的任務。
再看一種完全相反的工作負載:對大量資料,反覆執行同一種數學運算。這種場景其實到處都是——圖形渲染,每個像素可以各自獨立計算;科學計算,同一個數值運算套到一整個龐大資料集上;影片處理;還有機器學習,同一種數學被重複套用到一大批輸入上。這正是 GPU 出場的地方。跟 CPU 比起來,GPU 塞了多出非常多的算術運算單元,所以特別適合這種高吞吐量的平行工作。
要理解 GPU 為什麼對 AI 這麼有用,得先聊聊矩陣乘法。矩陣,其實就是一格一格排好的數字,比如一個兩列三行的方格。矩陣乘法,就是把兩個尺寸相容的方格結合成一個新方格,做法是一列對一行,數字相乘再相加。聽起來很簡單,但當矩陣變得非常巨大時,它就變成海量而重複的計算。而這種數學,在機器學習裡不斷出現。當一個神經網路處理輸入時,底層做的很多事情就是矩陣乘法:輸入是一大組數字,模型權重是另一大組數字,模型透過矩陣乘法把兩者結合,產生下一組輸出,然後在一層又一層之間,反覆重複這個過程。這就是為什麼 GPU 對 AI 這麼有用——它超級擅長把同一種運算,平行地做很多很多次。
那要理解 TPU,還得先認識一個詞:張量,tensor。這個字聽起來很嚇人,其實它只是一堆熟悉概念的推廣。一個數字,叫純量;一列數字,叫向量;一格數字,就是矩陣;再往上,更高維度的數字陣列,就是張量。舉個例子,一張彩色影像就能用張量來表示——它有高度、寬度,還有色彩通道。如果你把很多張影像放進同一批一起處理,那就變成一個更大的張量。所以從純量、向量、矩陣到張量,本質上就是維度一路往上疊。
這就帶到了 TPU,也就是 Tensor Processing Unit,張量處理單元。CPU 是通用的,GPU 高度平行但還算通用,而 TPU 就更專用了。它是專門為機器學習工作負載設計的,尤其是大型神經網路訓練跟推論這種張量密集的任務。比如說,當你在服務一個大型語言模型,推論過程中有一大部分就是龐大的張量運算;當你在訓練一個 transformer 模型,這種在巨大張量上做的矩陣乘法,佔比更是壓倒性地高。這類任務,正是 TPU 能發光的地方。
那問題來了——既然 TPU 這麼強,為什麼不乾脆全部都用 TPU?因為專用化本身就是一種取捨。硬體越專用,效率可以越高,但彈性也越低。CPU 幾乎什麼都能做得還不錯;GPU 對許多平行工作負載都很優秀;TPU 對符合它設計初衷的機器學習任務可以極度高效,但也就僅限於此。所以實務上,現代系統往往是用不同的晶片去負責工作裡的不同環節:CPU 負責控制流程跟整體調度,TPU 或 GPU 則接手大規模的平行運算。
所以講到最後,其實可以收斂成三個要點。第一,CPU、GPU、TPU 之間沒有絕對的優劣,只有合不合適,它們分別對應三種計算型態——CPU 是彈性,GPU 是平行吞吐量,TPU 是專用。第二,關鍵在於看懂你手上的工作負載到底屬於哪一種計算:是充滿分支決策的通用任務,是同一種數學重複做很多次,還是機器學習的張量運算。第三,真正該做的判斷,是先理解工作負載,再對齊合適的硬體,而不是一句「AI 就是要用 GPU」把所有情境一概而論。搞懂這件事,你對晶片的選擇,就會從跟風變成真正的工程決策。
Tags
Related Articles
LLM Inference in Three Layers: Decoding, Workflow, and Reasoning
LLM output quality is determined at three distinct layers: token-level decoding strategy, task-level workflow design, and model-level reasoning capability. Knowing which layer your problem lives in is the fastest path to fixing it.
Titans: Learning to Memorize at Test Time (Paper Analysis)
Titans introduces a neural memory module that updates itself via gradient descent at inference time, breaking the context-length ceiling of Transformers while staying near-linear in complexity.
After a 1,000,000x AI Compute Leap: What Jeff Dean Sees Next
Jeff Dean breaks down where the million-fold AI compute gains actually came from — specialized hardware, distributed training systems, and architecture efficiency — and where the next phase is headed.