Race a CPU against a T4 on the same vector operation
Colab T4 · freenotebook60 minrequiredGoal · Produce a plot of CPU versus GPU throughput for elementwise add and matmul as problem size grows, and identify the crossover point.
- 1Open a Colab notebook with a T4 runtime; run !nvidia-smi and record the GPU name and memory.
- 2In PyTorch, time a + b for float32 tensors of size 1e3 to 1e8 on CPU and on cuda; use torch.cuda.synchronize() before stopping the timer.
- 3Repeat for square matmul with N from 64 to 4096.
- 4Convert timings to GFLOP/s and GB/s and plot both devices on a log-log axis.
- 5Mark the size where the GPU overtakes the CPU and write one sentence on why small sizes lose.
- 6Compare your best matmul number to the T4 spec (8.1 TFLOPS FP32, 65 TFLOPS FP16 tensor core) and compute the percentage of peak reached.
- Deliverable
- Notebook with the two plots and a markdown cell containing the crossover sizes and percentage-of-peak figures.
- Check
- GPU matmul at N=4096 is at least 10x faster than CPU; elementwise add at N=1e3 is slower on GPU than CPU (launch overhead dominates).
- Fallback
- Kaggle notebooks with a T4 or P100 give the same experiment if Colab GPU quota is exhausted.