1.8 GPU vs CPU architecture

NCA-AIIO · Essential AI Knowledge (38% of the exam) · Official objective: “Compare and contrast GPU and CPU architectures.”

Why GPUs, with many cores running in parallel, suit AI better than CPUs for the heavy math.

Key points

  1. NVIDIA's CUDA guide says a CPU is designed to run a serial sequence of operations as fast as possible. A GPU is designed to run thousands of threads in parallel, trading lower single-thread performance for much greater total throughput. GPUs devote more transistors to data processing, while CPUs devote more to caching and flow control.

    What NVIDIA says (2)

    “a GPU is designed to excel at executing thousands of threads in parallel, trading off lower single-thread performance to achieve much greater total throughput.”

    — CUDA Programming Guide: Introduction

    “GPUs are specialized for highly parallel computations and devote more transistors to data processing units, while CPUs dedicate more transistors to data caching and flow control.”

    — CUDA Programming Guide: Introduction

  2. A core is a processing unit. A thread is one sequence of instructions. NVIDIA says a CPU has a few cores with lots of cache memory, handling a few software threads at a time. A GPU has hundreds of cores that handle thousands of threads simultaneously.

    What NVIDIA says (5)

    “GPUs are specialized for highly parallel computations and devote more transistors to data processing units, while CPUs dedicate more transistors to data caching and flow control.”

    — CUDA Programming Guide: Introduction

    “a CPU is designed to excel at executing a serial sequence of operations (called a thread) as fast as possible and can execute a few tens of these threads in parallel”

    — CUDA Programming Guide: Introduction

    “Architecturally, the CPU is composed of just a few cores with lots of cache memory that can handle a few software threads at a time.”

    — What's the Difference Between a CPU and a GPU?

    “a GPU is designed to excel at executing thousands of threads in parallel, trading off lower single-thread performance to achieve much greater total throughput.”

    — CUDA Programming Guide: Introduction

    “In contrast, a GPU is composed of hundreds of cores that can handle thousands of threads simultaneously.”

    — What's the Difference Between a CPU and a GPU?

  3. A tensor is a multi-dimensional array of numbers, the basic data type of deep learning. NVIDIA says deep learning is accelerated by dedicated Tensor Cores in its GPUs. Its mixed-precision guide notes math runs much faster in reduced precision on GPUs with Tensor Core support.

    What NVIDIA says (2)

    “Tensor Cores were introduced in the NVIDIA Volta™ GPU architecture to accelerate matrix multiply and accumulate operations for machine learning and scientific applications.”

    — GPU Performance Background User's Guide

    “Third, math operations run much faster in reduced precision, especially on GPUs with Tensor Core support for that precision.”

    — NVIDIA Mixed Precision Training Guide

  4. NVIDIA defines accelerated computing as using specialized hardware to dramatically speed up work with parallel processing. It offloads demanding work that can bog down CPUs, which typically run tasks one after another. The CPU still runs the parts of the program that are serial.

    What NVIDIA says (4)

    “A GPU provides much higher instruction throughput and memory bandwidth than a CPU within a similar price and power envelope.”

    — CUDA Programming Guide: Introduction

    “Accelerated computing is the use of specialized hardware to dramatically speed up work, using parallel processing that bundles frequently occurring tasks.”

    — What Is Accelerated Computing?

    “a CPU is designed to excel at executing a serial sequence of operations (called a thread) as fast as possible and can execute a few tens of these threads in parallel”

    — CUDA Programming Guide: Introduction

    “It offloads demanding work that can bog down CPUs, processors that typically execute tasks in serial fashion.”

    — What Is Accelerated Computing?

  5. Memory bandwidth is how fast data moves between memory and the processor. NVIDIA's CUDA guide says a GPU provides much higher instruction throughput and memory bandwidth than a CPU within a similar price and power envelope.

    What NVIDIA says (1)

    “A GPU provides much higher instruction throughput and memory bandwidth than a CPU within a similar price and power envelope.”

    — CUDA Programming Guide: Introduction

  6. CUDA treats a server as two kinds of processors. The CUDA Programming Guide calls the CPU and its directly connected memory the host and host memory, and a GPU and its memory the device and device memory. Host code on the CPU uses CUDA APIs to copy data between host and device memory and to start GPU code.

    What NVIDIA says (3)

    “The CPU and the memory directly connected to it are called the host and host memory , respectively.”

    — CUDA Programming Guide: Programming Model

    “A GPU and the memory directly connected to it are referred to as the device and device memory , respectively.”

    — CUDA Programming Guide: Programming Model

    “The host code, which is the code that runs on the CPU, can use CUDA APIs to copy data between the host memory and device memory, start code executing on the GPU, and wait for data copies or GPU code to complete.”

    — CUDA Programming Guide: Programming Model

  7. CUDA reuses the word 'kernel' for historical reasons. The Programming Guide says a function invoked for execution on the GPU is called a kernel. Launching a kernel can be thought of as starting many threads that execute the kernel code in parallel on the GPU.

    What NVIDIA says (2)

    “The code an application executes on the GPU is referred to as device code , and a function that is invoked for execution on the GPU is, for historical reasons, called a kernel .”

    — CUDA Programming Guide: Programming Model

    “A kernel launch can be thought of as starting many threads executing the kernel code in parallel on the GPU.”

    — CUDA Programming Guide: Programming Model

  8. A kernel launch often has millions of threads. The Programming Guide groups them into thread blocks, and the blocks make up a grid. All threads of a block run on a single streaming multiprocessor (SM), so they can communicate and synchronize efficiently through on-chip shared memory.

    What NVIDIA says (3)

    “A block of threads is referred to, perhaps unsurprisingly, as a thread block .”

    — CUDA Programming Guide: Programming Model

    “All threads of a thread block are executed in a single SM.”

    — CUDA Programming Guide: Programming Model

    “Threads within a thread block all have access to the on-chip shared memory, which can be used for exchanging information between threads of a thread block.”

    — CUDA Programming Guide: Programming Model

  9. SIMT means Single-Instruction Multiple-Threads. The Programming Guide says threads in a block are organized into warps of 32. All threads in a warp execute the same instruction at the same time. If some threads follow a branch and others do not, the others are masked off while the branch runs.

    What NVIDIA says (3)

    “Warps and SIMT # Within a thread block, threads are organized into groups of 32 threads called warps .”

    — CUDA Programming Guide: Programming Model

    “All threads in the warp execute the same instruction simultaneously.”

    — CUDA Programming Guide: Programming Model

    “If some threads within a warp follow a control flow branch in execution while others do not, the threads which do not follow the branch will be masked off while the threads which follow the branch are executed.”

    — CUDA Programming Guide: Programming Model

  10. The CUDA Programming Guide says the GPU can be considered a collection of SMs organized into groups called GPCs. Each SM contains many functional units. This contrasts with a CPU, which typically has several cores and a memory controller.

    What NVIDIA says (2)

    “For the purposes of CUDA programming, the GPU can be considered to be a collection of Streaming Multiprocessors (SMs) which are organized into groups called Graphics Processing Clusters (GPCs).”

    — CUDA Programming Guide: Programming Model

    “A CPU typically has several cores and a memory controller which connects to the system memory.”

    — CUDA Programming Guide: Programming Model

  11. Amdahl's Law puts an upper bound on speedup for a fixed problem size. NVIDIA's guide says the larger the parallelizable portion P, the greater the potential speedup. If P is small, adding processors does little. With 50% serial work, the run can never be more than about twice as fast, however many GPUs you add.

    What NVIDIA says (3)

    “Strong scaling is usually equated with Amdahl’s Law, which specifies the maximum speedup that can be expected by parallelizing portions of a serial program.”

    — CUDA C++ Best Practices Guide

    “For most purposes, the key point is that the larger the parallelizable portion P is, the greater the potential speedup.”

    — CUDA C++ Best Practices Guide

    “Conversely, if P is a small number (meaning that the application is not substantially parallelizable), increasing the number of processors N does little to improve performance.”

    — CUDA C++ Best Practices Guide

  12. Host and device have separate memories, so data must be copied between them. NVIDIA's guide says these transfers are costly and should be minimized, and the complexity of the work should justify moving the data. A relatively slow kernel can still be worth it if it avoids one or more transfers.

    What NVIDIA says (2)

    “These transfers are costly in terms of performance and should be minimized. (See Data Transfer Between Host and Device .) This cost has several ramifications: The complexity of operations should justify the cost of moving data to and from the device.”

    — CUDA C++ Best Practices Guide

    “Even a relatively slow kernel may be advantageous if it avoids one or more transfers between host and device memory.”

    — CUDA C++ Best Practices Guide

  13. CPUs and GPUs differ in threading model and have separate memories. NVIDIA's guide says applications built with these differences in mind can treat host and device as one cohesive heterogeneous system, with each doing the work it does best: sequential work on the host, parallel work on the device.

    What NVIDIA says (1)

    “Applications composed with these differences in mind can treat the host and device together as a cohesive heterogeneous system wherein each processing unit is leveraged to do the kind of work it does best: sequential work on the host and parallel work on the device. 3.2.”

    — CUDA C++ Best Practices Guide

Key terms

Try it

Sample question

What trade-off does a GPU make compared with a CPU?

Show the answer

Answer: It gives up some single-thread performance to run thousands of threads in parallel for much greater total throughput.

NVIDIA's CUDA guide says a CPU is designed to run a serial sequence of operations as fast as possible. A GPU is designed to run thousands of threads in parallel, trading lower single-thread performance for much greater total throughput. GPUs devote more transistors to data processing, while CPUs devote more to caching and flow control.

What NVIDIA says (2)

“a GPU is designed to excel at executing thousands of threads in parallel, trading off lower single-thread performance to achieve much greater total throughput.”

— CUDA Programming Guide: Introduction

“GPUs are specialized for highly parallel computations and devote more transistors to data processing units, while CPUs dedicate more transistors to data caching and flow control.”

— CUDA Programming Guide: Introduction

Practice 1.8 (13 questions) Full Essential AI Knowledge guide

← 1.7 The AI development and deployment life cycle · 2.1 Hardware for training workloads →