# CPU vs GPU Benchmarks Series

> Comparing the number-crunching capabilities of AMD Threadripper PRO 3995WX and Nvidia RTX 3090 across matrix multiplication, convolution, and other compute-intensive tasks.

[Blog](https://www.unum.cloud/blog.md) [HPC](https://www.unum.cloud/blog?tag=HPC)

Comparing the number-crunching capabilities of AMD Threadripper PRO 3995WX and Nvidia RTX 3090 across matrix multiplication, convolution, and other compute-intensive tasks.

- By

  Ash Vardanian

- Published

  Jan 25, 2022

We haven’t published any articles this year yet, as we wanted to start with something big. So here we begin a series of posts and live meetups on General-Purpose Computing on Graphics Processing Units. Or, GPGPU, for short.

## The Question

Almost every data scientist we know starts the day with `import numpy as np` and `import pandas as pd`, and those libraries were designed for CPUs, mostly running on a single core. Meanwhile, the most expensive chip in their workstation is often a GPU that only wakes up when a neural network is being trained.

That is starting to change. Nvidia’s [RAPIDS](https://rapids.ai/) project and the [CuPy](https://cupy.dev/) library promise drop-in GPU replacements for the whole stack: CuPy for NumPy, cuDF for Pandas, cuGraph for NetworkX, cuML for scikit-learn. In the best case, you change one import and your notebook runs many times faster. In the worst case, you change one import, everything breaks, and what still works runs slower.

So the question of this series is simple. **If you have a top-of-the-line CPU and a top-of-the-line GPU in the same box, which one should run your datascience code?** For which operations, at what data sizes, and with how much pain? We will answer it with benchmarks: the same code on the same machine.

## Contents

The intention was to benchmark the most commonly used libraries for datascience and suggest most relevant tools for 2022. Here is what we came up with:

1. NumPy vs CuPy, [here](https://www.unum.cloud/blog/cupy.md).
2. Pandas vs Modin vs Spark vs Arrow vs cuDF, [here](https://www.unum.cloud/blog/pandas.md).
3. NetworkX vs RetworkX vs cuGraph, [coming soon](https://bit.ly/3mG4q0f).
4. TensorFlow vs PyTorch vs JAX, [coming soon](https://bit.ly/3mG4q0f).

The first part covers dense arrays. NumPy is the foundation that everything else in scientific Python is built on, and CuPy mirrors its interface closely enough that the same function can run on either, just by swapping the module. We take matrix multiplications, decompositions, correlations, sorting, medians and moving averages, and see how five different backends handle them.

The second part moves from arrays to tables. Here the operations are parsing, filters and group-bys, and the data is no longer a neat block of floats: it has strings, missing values and categories. Pandas is single-threaded, Modin and Spark try to spread it across CPU cores, Arrow gives it a columnar memory layout, and cuDF moves it to the GPU.

The third part is about graphs, the least GPU-friendly workload we know. Graph algorithms jump through memory in patterns that depend on the data itself, which is the opposite of what GPUs like. We compare the pure-Python NetworkX, the Rust-based RetworkX and Nvidia’s cuGraph.

The last part is the home turf of GPUs: deep learning. Every framework runs on CUDA there, so the question is no longer CPU vs GPU, but how much each framework leaves on the table.

Along the way, we will also go below Python, into C++ and CUDA, to see how close hand-written code gets to the hardware limits listed below.

## Hardware

Enough has been said about CPU vs GPU hardware differences, so we won’t cover the basics. Let’s check the specifics. We took the most potent pieces a person could buy in a retail store and put them head to head.

![AMD Threadripper PRO 3995WX](https://www.unum.cloud/blog/cpu-vs-gpu/HERO.jpg)

Our CPU of choice in 2022 is [AMD Threadripper PRO 3995WX](https://www.amd.com/en/products/cpu/amd-ryzen-threadripper-pro-3995wx):

- priced at around $7,000 on [Amazon](https://www.amazon.com/AMD-Ryzen-Threadripper-PRO-3995WX/dp/B08V5HPXVY/).
- equipped with 64 cores, 128 threads, and 256 MB of L3 cache.
- TDP: 280 Watts.

![Nvidia RTX 3090](https://www.unum.cloud/blog/cpu-vs-gpu/gpu.jpg)

Our GPU is [Nvidia RTX 3090](https://www.nvidia.com/ru-ru/geforce/graphics-cards/30-series/rtx-3090/), Founders Edition:

- with a recommended price of $1,500, these GPUs are now 3x the price on the market.
- equipped with 10,496 CUDA cores at 1.4 GHz base clock and 24 GB of GDDR6X memory.
- TDP: 350 Watts.

> A complete review of the host machine was given in the [Yahoo Cloud Serving Benchmark](https://www.unum.cloud/blog/ycsb-udisk.md#our-toys).

A non-PRO version of the CPU would cost a couple thousand less but reaches the same numbers in the following benchmarks. All in all, those devices are comparable in price, power consumption, and novelty. Aside from the basic GPU specs, we must remind you that RTX 30 cards come with 2nd Gen Ray Tracing Cores and 3rd Gen Tensor Cores. The first ones are irrelevant for this story, and the Tensor Cores come with an asterisk.

Peak Tensor Core throughput TFLOPS, TOPS for INT8, bars relative to V100

| TFLOPS, TOPS for INT8, bars relative to V100 | V100 | A100 | A100 sparse |
| - | - | - | - |
| FP64 | 8 | 20 | |
| FP32 on V100, TF32 on A100 | 16 | 160 | 310 |
| FP16 | 125 | 310 | 625 |
| INT8 | 60 | 625 | 1,250 |

Ampere Tensor Core capability: peak throughput of A100 against V100, dense and sparse, as published by Nvidia.

One of the primary features of newer tech is support for rarely seen `i8` and `i4` matrices. Those are increasingly popular in AI inference, especially if you don’t adopt them yourself, but try the Triton Server. Those may also become popular in AI training, but none of the big frameworks (PT, TF, JAX) support sub-byte matrices yet.

The chart above shows the datacenter A100. The GeForce version of the same architecture is cut differently. According to Nvidia’s [GA102 whitepaper](https://www.nvidia.com/content/PDF/nvidia-ampere-ga-102-gpu-architecture-whitepaper-v2.pdf), the RTX 3090 peaks at 142 dense `f16` TFLOPS with `f16` accumulation, but only 71 when accumulating in `f32`, as most training does. Its `tf32` peak is 35.6 TFLOPS, matching rather than exceeding its regular `f32` CUDA cores. For integers, it reaches 284 `i8` and 568 `i4` TOPS, twice as much for sparse matrices. That’s the asterisk.

### On Paper

Here is how the two compare on public spec sheets. The CPU compute figures are ours, derived from the Zen 2 microarchitecture: two 256-bit FMA units per core give 32 single-precision or 16 double-precision operations per cycle, at the 2.7 GHz base clock.

| | Threadripper PRO 3995WX | RTX 3090 |
| - | - | - |
| Cores | 64 cores, 128 threads | 10,496 in 82 SMs |
| Clock, base and boost | 2.7 and 4.2 GHz | 1.4 and 1.7 GHz |
| Peak `f32` | \~5.5 TFLOPS | 35.6 TFLOPS |
| Peak `f64` | \~2.8 TFLOPS | 0.56 TFLOPS |
| Memory | 8-channel DDR4-3200, up to 2 TB | 24 GB GDDR6X |
| Memory bandwidth | 204.8 GB/s | 936 GB/s |
| Largest cache | 256 MB L3 | 6 MB L2 |
| TDP | 280 W | 350 W |

A few things stand out.

The GPU has 6.4x more single-precision compute, but only 4.6x more memory bandwidth. So for workloads limited by memory rather than math, the gap is smaller than the core counts suggest.

In double precision, the tables turn. Consumer Ampere GPUs execute `f64` at 1/64 of the `f32` rate, so on paper the Threadripper is 5x faster than the RTX 3090. If your simulation needs doubles, a GeForce card is the wrong tool.

Capacity is the other side of bandwidth. Our machine has 1 TB of RAM, about 42x more than the 24 GB on the card. Anything that doesn’t fit in VRAM has to be streamed over PCIe 4.0 x16, which moves around 32 GB/s in each direction, almost 30x less than the GPU’s own memory bandwidth.

### In the Datacenter

Data centers see a different pair. The A100 from the chart above has HBM2 memory with 1,555 GB/s of bandwidth in its 40 GB version, and full-rate double precision: 9.7 TFLOPS on regular cores and 19.5 on Tensor Cores. On the CPU side, the AMD EPYC 7763 (Milan) packs 64 Zen 3 cores and the same 8 channels of DDR4-3200, while Intel’s Xeon Platinum 8380 (Ice Lake) has 40 cores with two AVX-512 FMA units each.

So the balance shifts in favor of the GPU when doubles are involved, and its bandwidth advantage grows from 4.6x to 7.6x. We use the workstation because its parts are available off the shelf, but keep in mind that the `f64` conclusions will not transfer to a server with an A100.

## What Makes a Workload GPU-Friendly

GPUs only shine when a workload has the right shape. Here is our checklist.

**Lots of independent work.** A GPU schedules threads in groups of 32, called warps, that execute the same instruction in lockstep. When threads in a warp take different branches, the branches run one after another. Element-wise math over millions of values is ideal. Code full of `if` statements that depend on the data is not.

**Enough math per byte.** Every processor has a balance point: the number of operations it can perform per byte fetched from memory. For the RTX 3090 it’s about 38 `f32` operations per byte, for the Threadripper about 27. Adding two arrays of floats performs one operation per 12 bytes moved, so it is limited by memory on both, and the best the GPU can do is its 4.6x bandwidth advantage. Multiplying two N⨉N matrices performs 2N³ operations on 12N² bytes, so already at N=512 it is limited by compute, and the GPU can bring its full 6.4x, or more with lower-precision Tensor Cores. This is known as the [Roofline model](https://doi.org/10.1145/1498765.1498785), and it’s the first thing we check when a number looks too good or too bad.

**Using the whole CPU is not a given.** Here is the twist that makes the practical gap larger than the specs suggest. NumPy only uses multiple cores inside BLAS routines, like matrix multiplications. Sorting, medians, cumulative sums and element-wise operations run on a single core out of 64, which can’t come close to saturating 8 memory channels.

**Data that stays on the device.** Copying an array to the GPU, doing one pass over it and copying it back is usually slower than doing the pass on the CPU, as the PCIe bus is the slowest link in the chain. GPU libraries pay off when the whole pipeline stays in VRAM. This is why RAPIDS libraries share memory with each other through the `__cuda_array_interface__` and DLPack, instead of going through the host.

**Big enough batches.** Every GPU kernel launch costs microseconds, no matter how little work it does. A 100⨉100 matrix fits in the CPU caches and is gone before the GPU wakes up. The smaller the data, the smaller the speedup, and below some size the CPU wins.

**Algorithms without long dependency chains.** Sorting, reductions and matrix products parallelize beautifully. Iterative algorithms, where each step depends on the previous one, like many matrix decompositions, leave most of the GPU idle.

## How We Benchmark

The experiments in this series run on the same liquid-cooled workstation we used for the [YCSB benchmark](https://www.unum.cloud/blog/ycsb-udisk.md#our-toys), under Ubuntu 20.04. It has one CPU socket, so there are no NUMA effects, and 1 TB of DDR4-3200 in all 8 memory channels. Only one of its RTX 3090 cards is used.

Every benchmark is a Python function that receives a `backend` module and calls only its functions. Pass `numpy` and it runs on the CPU; pass `cupy` and it runs on the GPU. The code is identical, so the difference between the two is the difference between the libraries and the hardware under them.

For the first part, we sweep square `f32` matrices from 512⨉512 to 16K⨉16K. The largest one takes exactly 1 GiB, so everything fits into the GPU memory, and we only measure the compute, not the capacity. On the CPU side, we build separate Conda environments with NumPy linked to three different BLAS implementations: BLIS, OpenBLAS and Intel MKL. On the GPU side, we use CuPy from RAPIDS 21.12 with CUDA 11.5, with TF32 math on the Tensor Cores disabled and enabled. We also turn on the CUB and cuTENSOR accelerators, which CuPy may leave off by default. Speedups are reported relative to NumPy on BLIS, and plotted on log-log scales, as they span three orders of magnitude.

## A Sneak Peek

We won’t spoil all of part one, but here is the fastest CPU configuration against the fastest GPU one, across the matrix sizes we tried:

- **Sorting**: from 88x at 512⨉512 up to 1,009x at 16K⨉16K in favor of the GPU.
- **Medians**: 11x to 99x.
- **Moving averages**: 11x to 59x.
- **Matrix multiplication**: 8x to 25x.
- **Pearson correlations**: 1.1x to 2.5x.
- **Singular value decomposition**: 0.5x to 0.8x, meaning the CPU wins.

All six line up with the checklist above. The biggest wins come from operations that NumPy runs on a single core and that GPUs solve with specialized parallel algorithms, like Radix sort. Matrix multiplication gains are more modest, because on the CPU side it is one of the very few NumPy functions that actually uses all 64 cores. Even there, the measured gap is larger than the 6.4x on paper, so the CPU libraries are clearly not running at the peak, one more thing to dig into in C++. And the SVD, with its long dependency chains, is where the CPU still wins.

## What’s Next

2022 is shaping up to be an interesting year for hardware. Intel’s Alder Lake has already brought DDR5 and PCIe 5.0 to desktops, and the server CPUs expected this year are set to follow. AMD has announced the Instinct MI200 accelerators, and Nvidia has promised its own Arm-based Grace CPU for 2023. The benchmarks will stay the same, so we can re-run them when the new hardware lands.

In the meantime, the parts of this series will be published one by one, with live meetups to discuss them. If you have a workload you think belongs in this comparison, tell us!

---

Let’s [**start!**](https://www.unum.cloud/blog/cupy.md)
