GPU vs CPU design philosophy
6.2.1· Hardware › GPU Architecture
Overview
GPU (Graphics Processing Unit) aur CPU (Central Processing Unit) ki design philosophy mein jo fundamental difference hai, woh computation ke do bilkul alag approaches ko reflect karta hai: latency optimization versus throughput optimization. Is distinction ko samajhna modern computing architecture ke liye bahut zaroori hai.

CPU Design Philosophy: Latency Minimize Karo
CPUs Is Tarah Kyun Bane Hain
First principles se CPU design priorities ki derivation:
-
Starting assumption: General-purpose code mein data dependencies hoti hain
- Instruction aksar ke result par depend karta hai
- Jo sequential hona chahiye usse parallelize nahi kar sakte
-
Implication: Sequential code ko FAST execute karna hoga
- Agar task time hai (n instructions, har ek leta hai)
- reduce karne ka ek hi tarika hai: reduce karo
-
kaise reduce karein?
- Memory latency dominate karti hai: DRAM access ≈ 100ns vs compute ≈ 1ns
- Solution: Bade L1/L2/L3 caches add karo (modern CPUs par 64MB tak)
- Cache hit memory access ko 100ns se 1-4ns tak reduce kar deta hai
-
Control flow ki unpredictability
- Average par har 5-7 instructions mein branches aati hain
- Wrong branch = pipeline flush = wasted cycles
- Solution: Branch predictor (>95% accuracy) + speculative execution
-
Instruction-level parallelism (ILP)
- Sequential code mein bhi independent instructions hoti hain
- Solution: Out-of-order execution independent instructions ko dhundh kar simultaneously run karta hai
CPU Die Area Budget
Chaliye derive karte hain ki ek modern CPU apna transistor budget kaise use karta hai:
Total transistors ≈ 10-20 billion (e.g., Intel Core i9)
- Compute cores: 8-16 cores × 0.5B transistors = 4-8B (compute + local logic)
- Har core mein: ALUs, FPUs, registers
- Cache hierarchy (SRAM, ~6 transistors/bit):
- L1: 32KB × 16 cores = 512KB
- L2: 256KB × 16 cores = 4MB
- L3: 32MB (shared)
- Total SRAM ≈ 36.5MB →
- Control logic: 3-4B transistors
- Branch predictors, instruction schedulers, memory controllers
Key observation: Die area ka ek bada hissa caches aur control logic par kharch hota hai taaki ek single thread ko jaldi serve kiya ja sake — actual arithmetic bahut kam portion mein hoti hai. (Note: transistor count aur die area alag hote hain, kyunki SRAM cells dense lekin bahut zyada hote hain; design intent clear hai — CPUs latency reduction ke liye bhaari "payment" karte hain.)
GPU Design Philosophy: Throughput Maximize Karo
GPUs Is Tarah Kyun Bane Hain
Graphics workload se derivation:
-
Starting assumption: Graphics mein millions of pixels/vertices par independently operate karna padta hai
- Pixel ka color calculation pixel par depend nahi karta
- Embarrassingly parallel workload
-
Implication: Hazaron tasks simultaneously run kar sakte hain
- Agar hamare paas independent tasks hain, total time:
- Jahaan = parallel processors ki number
- minimize karne ke liye, maximize karo (chahe badh jaaye!)
-
Design constraint: Fixed transistor budget
- Simple core: transistors
- Complex core: (cache, control logic ki wajah se) Cores ki number:
-
Caches ke bina memory latency handle karna
- 1000s cores par per core cache bahut expensive hai
- Solution: Hardware threading (warp scheduling)
- Jab ek warp memory ka wait karta hai, turant doosre ready warp par switch karo
- DRAM latency ke saikdon cycles ko poori tarah hide karne ke liye — often dozens of warps (hundreds se ~2048 threads tak) per SM — bahut saare resident warps chahiye
-
Branch divergence problem
- Koi branch predictor nahi → wrong branches expensive hain
- Solution: SIMT (Single Instruction Multiple Threads)
- Ek warp ke saare threads (32 threads) same instruction execute karte hain
- Agar branches diverge karein, execution serialize ho jaati hai (performance loss)
GPU Die Area Budget
Total transistors ≈ 50-80 billion (e.g., NVIDIA A100)
- Compute cores: hazaron CUDA cores → compute-oriented transistor budget ka majority
- CPU ke mukable bahut zyada transistors actual math kar rahe hain
- Cache (SRAM, ~6 transistors/bit): pure chip mein total ~40MB
- — poore chip ke relative chhota, aur per-core bilkul tiny
- Control logic: warp schedulers, memory controllers
- Koi branch predictors NAHI, koi out-of-order logic NAHI
Key observation: CPU ke comparison mein, GPU ka bahut bada hissa arithmetic units ko dedicated hai, na ki caches aur speculative control logic ko.
Fundamental Tradeoffs
| Characteristic | CPU | GPU | Kyun? |
|---|---|---|---|
| Core count | 8-64 | 1000s-10000s | Transistor budget trade-off |
| Core complexity | Bahut high | Bahut low | Latency vs. throughput |
| Cache per core | MB-scale | KB-scale | Area constraint |
| Clock speed | 3-5 GHz | 1-2 GHz | Scale par power/thermal limits |
| Threading | 1-2 per core | dozens of warps per SM | Latency hiding mechanism |
| Branch handling | Prediction + speculation | Divergence serialization | Control complexity cost |
| Best workload | Sequential, unpredictable | Parallel, regular | Design optimization target |
Kab Kya Choose Karein
CPU-optimal tasks:
- Operating system kernels (unpredictable, I/O-heavy)
- Database query planning (sequential decision tree)
- Compilation (complex, data-dependent)
- Web serving (latency-sensitive, irregular)
GPU-optimal tasks:
- Graphics rendering (millions of independent pixels)
- Deep learning training (matrix multiplications, highly parallel)
- Scientific simulations (regular grids par PDEs)
- Cryptography (millions of candidates independently hash karna)
Hybrid approach (modern reality):
- Control logic, task scheduling, preprocessing ke liye CPU use karo
- Parallel kernels GPU par offload karo
- Example: Video encoding mein CPU scene analysis, GOP structure ke liye use hota hai; GPU motion estimation, DCT transforms ke liye
Recall 12-saal ke bachchon ko explain karo
Imagine karo ki homework ke liye 1000 math problems solve karne hain. Tumhare paas do choices hain:
Choice 1 (CPU): Tumhara super-smart tutor jo har trick jaanta hai. Woh shortcuts use karke, similar problems yaad karke, aur aage ka guess karke har problem 6 seconds mein solve kar sakta hai. Total time: 1000 × 6s = 100 minutes.
Choice 2 (GPU): 500 first-graders ka ek classroom. Har ek slower hai — problem mein 10 seconds lagte hain kyunki woh shortcuts nahi jaante. Lekin saath mein kaam karke, woh ek saath 500 problems solve karte hain! Total time: (1000 ÷ 500) × 10s = 20 seconds!
Catch kya hai? Problems similar aur independent honi chahiye. Agar har problem pichle answer par depend karti hai, toh sirf tutor help kar sakta hai — first-graders bas wait karte rahenge!
Connections
- 6.1.01-von-Neumann-architecture — CPUs isko extend karte hain; GPUs isse break karte hain (Harvard-style separate instruction/data paths)
- 6.2.02-CUDA-programming-model — Software GPU ki parallel philosophy ko kaise expose karta hai
- 6.2.03-memory-hierarchy-GPU — GPU ki caching strategy CPU se kaise alag hai
- 6.3.01-SIMD-vs-SIMT — Instruction-level parallel execution model
- 9.1.02-Amdahls-law — Parallel speedup ki mathematical limit
- 9.2.01-parallel-programming-models — Software patterns jo CPU vs GPU strengths se match karte hain
#flashcards/hardware
CPU aur GPU ke beech fundamental design difference kya hai? :: CPU latency optimize karta hai (single task ke liye time minimize) complex control logic, large caches, branch prediction use karke. GPU throughput optimize karta hai (tasks per second maximize) hazaron simple cores aur hardware threading use karke.
Transistor budget se derive karo ki GPUs mein CPUs se 10× zyada cores kyun hote hain :: Agar simple core ko transistors lagte hain aur complex core (cache, branch prediction ke saath) ko , toh fixed budget ke saath: GPU ke paas cores hain jabki CPU ke paas cores hain.
Arithmetic intensity kya hai aur yeh kyun matter karta hai? :: . GPU mein high compute-to-bandwidth ratio hai (~10-100 ops/byte). Agar workload ka kam ho, toh woh memory-bound hai aur GPU advantage khatam ho jaata hai. Example: vector addition mein hai (1 op, 12 bytes) = memory-bound.
Amdahl's Law aur uski implication batao :: jahaan