Inside an Nvidia GPU
An Nvidia GPU is made up of multiple Streaming Multiprocessors, or SMs. An SM itself is composed of two, four, eight, or a higher power of two, (sub-) partitions. Each partition has a single instruction scheduler, and supports "warps" of thirty-two "threads". (Here the word "thread" is used completely differently to a thread on a CPU. Nvidia wishes us to think of threads making up a piece of cloth on a mechanical weaving loom. Thence also the term "warp".)
The threads in a warp execute the same instruction simultaneously in lockstep. This is an example of single instruction multiple data operation, but is more flexible than the SIMD operation of the vector units of Intel/AMD CPUs. In particular, masking a warp is easy, so that it can actually execute on any number of threads up to its full 32.
Threads are combined into thread blocks, with a maximum of 1024 threads per block. The whole of a thread block will execute on a single SM, and can communicate internally, whereas communication with other thread blocks is not readily possible. Threads within a block may execute either simultaneously or sequentially, as they may require multiple warps.
A Turing SM contains sixty-four FP32 cores, sixty-four INT32 cores, and two FP64 cores, amongst other things. It is divided into four partitions. So a partition, which executes 32-thread warps, has just sixteen FP32 and sixteen INT32 cores. It can issue FP32 warps every other cycle, as the first half of the warp can start on the first cycle, and then the second half on the next cycle, as each core can accept new operands each cycle. It can issue INT32 warps in the gaps. Each SM can process sixteen thread blocks simultaneously, and thirty-two warps simultaneously. More recent GPUs have thirty-two cores per warp which can execute either FP32 or INT32 instructions.
Although the maximum number of warp instructions which an SM can start each clock cycle is four, one per partition, it is useful for it to be able to process more than four streams of warps. This is because one warp might be stalled on a data dependency (some instructions take more than a single cycle to complete, even if new data can be accepted every cycle) or memory operation. At this point instructions from a different warp can be processed. This is similar to hyperthreading on CPUs.
One difference between hyperthreading and warp scheduling is in the sharing of registers and what Nvidia calls `shared memory' (a tiny pool of very fast memory shared by everything on an SM). For most generations of Nvidia GPU, each partition has 16,384 registers, and the whole SM 65,536 registers. If one has a thread block of 1024 threads, each thread cannot use more than 64 registers even if it exclusively occupies an SM. Threads in smaller blocks can use up to 256 registers.
The bundling of threads into thread blocks is done when the PTX is compiled, and thus can consider the capacity of the precise hardware it is to be run on. So to is the mapping of the virtual registers of PTX onto a mixture of physical registers and, potentially, memory areas for register spills.
A Comparision
For processing single-precision data, the following comparision between an RTX5060 and an eight core Zen 5 (9700X) is possible.
| RTX5060 | Zen 5 | |
|---|---|---|
| memory bus width | 128 bits | 128 bits |
| memory type | GDDR7/28000 | DDR5/5600 |
| maximum b/w | 448GB/s | 90GB/s |
| maximum memory | 8GB | 128GB |
| last level cache | 32MB | 32MB |
| SMs / cores | 30 | 8 |
| Total power | 145W | 65W |
| Data per SM/core | ||
| 32 bit registers | 65,536 | 32 for each of 2 hyperthreads |
| 32 bit items per reg | 1 | 16 |
| FMA units | 128 (scalar) | 2 (vector length 16) |
| load/store units | 16 | 2 (vector length 16) |
| Other notable units | 2 FADD(vector length 16) | |
| Max instr per clock | 4 | 8 |
| L1 cache | 128KB | 48KB |
| L2 cache | none | 1MB |
| Base clock | 2.3GHz | 3.8GHz |
| Giga FMA32/s | 128*2.3 =294 | 2*16*3.8 =121 |
| max mem b/w | 15GB/s | 12GB/s |
So if one considers the CPU core to be equivalent to the GPU SM, and the GPU's threads to be equivalent to lanes of the CPU's vector register, these devices are not that dissimilar in performance. One can find bigger GPUs, but bigger Zen 5s also exist.
However, the GPU's SM can out-perform the CPU's core, and the GPU has more SMs than the CPU has cores.
Equating the GPU's core with the CPU's core in not helpful. The GPU 'core' has a peak performance of two FP32 FLOPS/Hz (starting one FMA per cycle). The CPU core has a peak performance of ninety-six FP32 FLOPS/Hz (starting two FMAs and two adds each cycle, each on vectors of length sixteen).
In both cases there is a large penalty if code does not parallelise in the required manner. For purely serial code, the CPU is likely to win, as it has a higher clock speed and is better at branch prediction, speculation, and out-of-order instruction execution.
(The Zen 5 would win easily in FP64 performance. It suffers a factor of two penalty, and the RTX a factor of sixty-four. It also wins in memory capacity. The biggest RTX 5xxx currently available, the 5090, has just 32GB.)
Comparisons between GPUs and CPUs are never easy. One should try to avoid comparing the whole of a GPU to a single CPU core, and one should try to compare things of similar price and power requirements.
Mappings
The language of OpenMP is of teams, threads and vectors. How does this map to the SMs, partitions and warps of Nvidia's hardware? There are many possible answers.
A GTX 1650 contains 14 SMs with 64 cores per SM. Nvidia's C compiler reports this to OpenMP as 14 teams of 992 threads each. The mapping of OpenMP teams to SMs seems obvious. The mapping of 992 threads per SM is not. This is 31 warps, and each SM is actually divided into four partitions. It seems therefore as though the partitions are mostly executing eight warps, though one has just seven.
In contrast, GCC sees this device as having 42 teams of 8 threads. This would suggest three teams of 8 threads per SM. But an SM has 64 cores, and 3*8 is only 24. GCC uses vectorisation to create threads for warps. The vector length is unclear, but is probably 32. So this might be six warps per partition.
LLVM's clang is more ambitious, and reports 3200 teams with 96 threads in each team. I do not pretend to understand this, especially as nothing is divisible by 14.
How many threads should be in a thread block to make best use of an SM? The maximum is 1024, and, if the SM has four warp schedulers, the minimum is at least 4x32=128 if the SM is processing a single thread block. But with just one warp per partition, there is no opportunity for a partition to hide stalls by switching to a different warp. Efficient use of the SM requires thread blocks with many threads, or multiple thread blocks.
But each thread may request up to 256 registers, and the SM has 65,536 registers. If more than 256 threads are to be assigned to one SM, they must limit themselves to 128 (or 64, or 32) registers each. Register usage per thread is set at PTX compile time.
A thread block may also use "shared memory", a small pool of very fast memory local to each SM. Again the amount used is set at PTX compile time, and the sum of the requirements of all blocks executing on an SM cannot exceed the SM's capacity. (Typically 64KB or a little more.)