🥊 The Ultimate Showdown: CPU vs GPU
💡 Story Time: Imagine you run a bakery. A CPU is like having 1 master chef — incredibly skilled, can do anything, handles complex decisions. A GPU is like having 10,000 helper elves — each does one simple thing, but together they bake MILLIONS of cookies at once!
Here's what makes them different:
// SERIAL (CPU-style): Add two arrays one by one
void addArrayCPU(float* a, float* b, float* c, int n) {
for (int i = 0; i < n; i++) { // One at a time: 0, 1, 2, ...
c[i] = a[i] + b[i]; // 1,000,000 iterations = slow!
}
}
// PARALLEL (GPU-style): ALL threads add at the SAME time!
__global__ void addArrayGPU(float* a, float* b, float* c) {
int i = threadIdx.x + blockIdx.x * blockDim.x;
c[i] = a[i] + b[i]; // Thread 0 does c[0], Thread 1 does c[1]...
} // ALL happen simultaneously!
📊 Performance comparison on matrix multiply (4096×4096):
This is why AI training lives on GPUs. Training GPT-4 on CPUs would take thousands of years. On GPU clusters? Months.
📋 Instructions
Study the comparison below and fill in the missing values by printing the correct CPU vs GPU specs:
```
=== CPU vs GPU Comparison ===
CPU Cores: 16
GPU Cores: 10496
CPU Clock: 3.8 GHz
GPU Clock: 1.4 GHz
CPU Memory: 64 GB RAM
GPU Memory: 80 GB VRAM
Best for CPU: Complex sequential logic
Best for GPU: Parallel math operations
```
Use printf() for each line. The first line is already started. For the header use printf("=== CPU vs GPU Comparison ===\n"); then print each spec line.