How do Graphics Cards Work? Exploring GPU Architecture
Branch Education
0:00 How many calculations do you think your graphics card performs
0:03 every second while running video games with incredibly realistic graphics?
0:09 Maybe 100 million?
0:11 Well, 100 million calculations a second is
0:15 what’s required to run Mario 64 from 1996.
0:20 We need more power.
0:22 Maybe 100 billion calculations a second?
0:24 Well, then you would have a computer that could run Minecraft back in 2011.
0:30 In order to run the most realistic video games such as Cyberpunk 2077
0:36 you need a graphics card that can
0:39 perform around 36 trillion calculations a second.
0:43 This is an unimaginably large number,
0:46 so let’s take a second to try to conceptualize it.
0:50 Imagine doing a long multiplication problem once every second.
0:53 Now let’s say everyone on the planet does
0:57 a similar type of calculation but with different numbers.
1:01 To reach the equivalent computational power of this graphics card and its 36
1:07 trillion calculations a second we would
1:10 need about 4,400 Earths filled with people,
1:14 all working together and completing one calculation each every second.
1:20 It’s rather mind boggling to think
1:22 that a device can manage all these calculations,
1:25 so in this video we’ll see how graphics cards work in two parts.
1:30 First, we’ll open up this graphics
1:32 card and explore the different components inside,
1:35 as well as the physical design and architecture
1:38 of the GPU or graphics processing unit.
1:42 Second, we’ll explore the computational architecture
1:45 and see how GPUs process mountains of data,
1:49 and why they’re ideal for running video game graphics,
1:53 Bitcoin mining, neural networks and AI.
1:59 So, stick around and let’s jump right in.
2:08 This video is sponsored by Micron which
2:11 manufactures the graphics memory inside this graphics card.
2:14 Before we dive into all the parts of the GPU,
2:19 let’s first understand the differences between GPUs and CPUs.
2:24 Inside this graphics card,
2:26 the Graphics Processing Unit or GPU has over 10,000 cores.
2:31 However, when we look at the CPU
2:34 or Central Processing Unit that’s mounted to the motherboard,
2:38 we find an integrated circuit or chip with only 24 cores.
2:42 So, which one is more powerful?
2:45 10 thousand is a lot more than 24, so you would think the GPU is more powerful,
2:52 however, it’s more complicated than that.
2:55 A useful analogy is to think of a GPU as a massive
2:59 cargo ship and a CPU as a jumbo jet airplane.
3:03 The amount of cargo capacity is the amount
3:06 of calculations and data that can be processed,
3:09 and the speed of the ship or airplane is the rate
3:13 at which how quickly those calculations and data are being processed.
3:17 Essentially, it’s a trade-off between a massive number
3:21 of calculations that are executed at a slower
3:24 rate versus a few calculations that can be performed at a much faster rate.
3:30 Another key difference is that airplanes are a lot
3:33 more flexible since they can carry passengers, packages,
3:36 or containers and can take off and land
3:39 at any one of tens of thousands of airports.
3:42 Likewise CPUs are flexible in that they
3:45 can run a variety of programs and instructions.
3:49 However, giant cargo ships carry only containers with bulk
3:53 contents inside and are limited to traveling between ports.
3:58 Similarly, GPUs are a lot less flexible than CPUs
4:03 and can only run simple instructions like basic arithmetic.
4:08 Additionally GPUs can’t run operating systems
4:11 or interface with input devices or networks.
4:14 This analogy isn’t perfect,
4:16 but it helps to answer the question of “which is faster, a CPU or a GPU?”.
4:23 Essentially if you want to perform
4:26 a set of calculations across mountains of data,
4:28 then a GPU will be faster at completing the task.
4:31 However, if you have a lot less data that needs
4:35 to be evaluated quickly than a CPU will be faster.
4:39 Furthermore, if you need to run an operating system or support
4:43 network connections and a wide range of different applications and hardware,
4:48 then you’ll want a CPU.
4:50 We’re planning a separate video on CPU architecture,
4:53 so make sure to subscribe so you don’t miss it,
4:56 but let’s now dive into this graphics card and see how it works.
5:01 In the center of this graphics card is the printed circuit board or PCB,
5:06 with all the various components mounted on it, [Animator Note:
5:09 Highlight and list out the various parts that will be covered.] and we’ll
5:10 start by exploring the brains which is the graphics processing unit or GPU.
5:16 When we open it up, we find a large
5:20 chip or die named GA102 built from 28.3 billion transistors.
5:26 The majority of the area of the chip is taken
5:29 up by the processing cores which have a hierarchical organization.
5:33 Specifically, the chip is divided into 7 Graphics Processing Clusters or GPCs,
5:41 and within each processing cluster are 12 streaming multiprocessors or SMs.
5:48 Next, inside each of these streaming multiprocessors
5:51 are 4 warps and 1 ray tracing core,
5:55 and then, inside each warp are 32 Cuda or shading cores and 1 tensor core.
6:04 Across the entire GPU are 10752 CUDA cores,
6:09 336 Tensor Cores, and 84 Ray Tracing Cores.
6:13 These three types of cores execute all the calculations of the GPU,
6:19 and each has a different function.
6:21 CUDA cores can be thought of as simple
6:24 binary calculators with an addition button, a multiply button and a few others,
6:30 and are used the most when running video games.
6:34 Tensor cores are matrix multiplication and addition calculators and are
6:39 used for geometric transformations and working with neural networks and AI.
6:45 And ray tracing cores are the largest but the fewest
6:49 and are used to execute ray tracing algorithms.
6:53 Now that we understand the computational resources inside this chip,
6:58 one rather interesting fact is that the 3080,
7:02 3090, 3080 ti, and 3090 ti graphics cards all
7:07 use the same GA102 chip design for their GPU.
7:12 This might be counterintuitive because they have different prices
7:16 and were released in different years, but it’s true.
7:20 So, why is this?
7:22 Well, during the manufacturing process
7:24 sometimes patterning errors, dust particles,
7:27 or other manufacturing issues cause damage
7:30 and create defective areas of the circuit.
7:33 Instead of throwing out the entire chip because of a small defect,
7:37 engineers find the defective region and permanently
7:40 isolate and deactivate the nearby circuitry.
7:43 By having a GPU with a highly repetitive design,
7:47 a small defect in one core only damages that particular streaming
7:52 multiprocessor circuit and doesn’t affect the other areas of the chip.
7:57 As a result, these chips are tested and categorized
8:01 or binned according to the number of defects.
8:06 The 3090ti graphics cards have flawless GA102
8:10 chips with all 10752 CUDA cores working properly,
8:16 the 3090 has 10,496 cores working,
8:20 the 3080ti has 10,240 and the 3080 has 8704 CUDA cores working,
8:28 which is equivalent to having
8:31 16 damaged and deactivated streaming multiprocessors.
8:34 Additionally, different graphics cards differ by their maximum clock speed
8:40 and the quantity and generation of graphics memory that supports the GPU,
8:45 which we’ll explore in a little bit.
8:47 Because we’ve been focusing on the physical architecture of this GA102 GPU chip,
8:53 let’s zoom into one of these CUDA cores and see what it looks like.
8:58 Inside this simple calculator is
9:00 a layout of approximately 410 thousand transistors.
9:03 This section of 50 thousand transistors performs the operation
9:08 of A times B plus C which is called fused multiply and add or FMA and is
9:16 the most common operation performed by graphics cards.
9:20 Half of the CUDA cores execute FMA using 32-bit floating-point numbers,
9:25 which is essentially scientific notation, and the other half of the cores use
9:31 either 32-bit integers or 32-bit floating point numbers.
9:34 Other sections of this core accommodate negative
9:37 numbers and perform other simple functions like
9:40 bit-shifting and bit masking as well as collecting
9:44 and queueing the incoming instructions and operands,
9:47 and then accumulating and outputting the results.
9:50 As a result, this single core is just
9:54 a simple calculator with a limited number of functions.
9:58 This calculator completes one multiply and one
10:01 add operation each clock cycle and therefore
10:05 with this 3090 graphics cards and its 10496 cores and 1.7 gigahertz clock,
10:13 we get 35.6 trillion calculations a second.
10:16 However, if you’re wondering how the GPU
10:20 handles more complicated operations like division,
10:23 square root, and trigonometric functions, well,
10:27 these calculator operations are performed
10:29 by the special function units which are far
10:32 fewer as only 4 of them can be found in each streaming multiprocessor.
10:36 Now that we have an understanding of what’s inside a single core,
10:40 let’s zoom out and take a look at the other sections of the GA102 chip.
10:46 Around the edge we find 12 graphics memory controllers,
10:50 the NVLink Controllers and the PCIe interface.
10:54 On the bottom is a 6-megabyte Level 2 SRAM Memory Cache,
10:59 and here’s the Gigathread Engine which manages all
11:04 the graphics processing clusters and streaming multiprocessors inside.
11:08 Now that we’ve explored this GA102 GPU’s physical architecture,
11:12 let’s zoom out and take a look at the other parts inside the graphics card.
11:18 On this side are the various ports for the displays to be
11:22 plugged into, on the other side is the incoming 12 Volt power connector,
11:27 and then here are the PCIe pins that plug into the motherboard.
11:32 On the PCB, the majority of the smaller components
11:36 constitute the voltage regulator module which takes the incoming 12
11:40 volts and converts it to one point one volts
11:44 and supplies hundreds of watts of power to the GPU.
11:48 Because all this power heats up the GPU,
11:50 most of the weight of the graphics card is
11:53 in the form of a heat sink with 4 heat pipes
11:56 that carry heat from the GPU and memory chips
11:59 to the radiator fins where fans then help to remove the heat.
12:04 Perhaps some of the most important components, aside from the GPU,
12:09 are the 24 gigabytes of graphics
12:12 memory chips which are technically called GDDR6X
12:16 SDRAM and were manufactured by Micron which is the sponsor of this video.
12:20 Whenever you start up a video game or wait for a loading screen,
12:24 the time it takes to load is mostly spent moving all the 3D models
12:29 of a particular scene or environment
12:31 from the solid-state drive into these graphics memory chips.
12:35 As mentioned earlier,
12:36 the GPU has a small amount of data storage in its 6-megabyte shared Level 2
12:42 cache which can hold the equivalent of about
12:45 this much of the video game’s environment.
12:47 Therefore in order to render a video game,
12:50 different chunks of scene are continuously being
12:53 transferred between the graphics memory and the GPU.
12:57 Because the cores are constantly performing
12:59 tens of trillions of calculations a second,
13:02 GPUs are data hungry machines and need
13:05 to be continuously fed terabytes upon terabytes of data,
13:10 and thus these graphics memory chips are designed kind of like
13:15 multiple cranes loading a cargo ship at the same time.
13:20 Specifically, these 24 chips transfer a combined 384 bits at a time,
13:24 which is called the bus width and the total data that can be transferred,
13:30 or the bandwidth is about 1.15 terabytes a second.
13:34 In contrast the sticks of DRAM that support the CPU only have
13:39 a 64-bit bus width and a maximum bandwidth closer to 64 gigabytes a second.
13:45 One rather interesting thing is that you may think
13:48 that computers only work using binary ones and zeros.
13:52 However, in order to increase data transfer rates,
13:55 GDDR6X and the latest graphics memory,
13:58 GDDR7 send and receive data across the bus wires
14:03 using multiple voltage levels beyond just 0 and 1.
14:07 For example, GDDR7 uses 3 different encoding schemes to combine binary bits
14:13 into ternary digits or PAM-3 symbols with voltages of 0, 1, and negative 1.
14:20 Here’s the encoding scheme on how 3 binary bits are
14:24 encoded into 2 ternary digits and this scheme is combined
14:28 with an 11 bit to 7 ternary digit encoding scheme
14:33 resulting in sending 276 binary bits using only 176 ternary digits.
14:39 The previous generation, GDDR6X, which is the memory in this 3090 graphics card,
14:46 used a different encoding scheme,
14:48 called PAM-4, to send 2 bits of data using 4 different voltage levels, however,
14:54 engineers and the graphics memory industry agreed to switch to PAM-3
14:59 for future generations of graphics chips in order to reduce encoder complexity,
15:04 improve the signal to noise ratio, and improve power efficiency.
15:10 Micron delivers consistent innovation to push the boundaries on how much data
15:17 can be transferred every second and to design cutting edge memory chips.
15:21 Another advancement by Micron is the development of HBM,
15:25 or the high bandwidth memory, that surrounds AI chips.
15:29 HBM is built from stacks of DRAM memory
15:33 chips and uses TSVs or through silicon vias,
15:37 to connect this stack into a single chip,
15:40 essentially forming a cube of AI memory.
15:44 For the latest generation of high bandwidth memory, which is HBM3E,
15:49 a single cube can have up to 24 to 36 gigabytes of memory,
15:55 thus yielding 192 gigabytes of high-speed memory around the AI chip.
16:00 Next time you buy an AI accelerator system,
16:04 make sure it uses Micron’s HBM3E which
16:07 uses 30% less power than the competitive products.
16:11 However, unless you’re building an AI data center,
16:15 you’re likely not in the market to buy one of these systems which cost
16:19 between 25 to 40 thousand dollars and are on backorder for a few years.
16:25 If you’re curious about high bandwidth memory,
16:27 or Micron’s next generation of graphics memory take
16:30 a look at one of these links in the description.
16:33 Alternatively, if designing the next generation of memory chips interests you,
16:39 Micron is always looking for talented scientists
16:42 and engineers to help innovate on cutting
16:45 edge chips and you can find out more about working for Micron using this link.
16:51 Now that we’ve explored many of the physical
16:54 components inside this graphics card and GPU,
16:57 let’s next explore the computational architecture and see how applications like
17:02 video game graphics and bitcoin mining
17:05 run what’s called “embarrassingly” parallel operations.
17:08 Although it may sound like a silly name,
17:12 embarrassingly parallel is actually a technical
17:15 classification of computer problems where little
17:18 or no effort is needed to divide the problem into parallel tasks,
17:23 and video game rendering and bitcoin mining easily fall into this category.
17:29 Essentially, GPUs solve embarrassingly parallel
17:32 problems using a principle called SIMD,
17:35 which stands for single instruction multiple data where the same instructions
17:40 or steps are repeated across thousands to millions of different numbers.
17:45 Let’s see an example of how SIMD or single instruction
17:49 multiple data is used to create this 3D video game environment.
17:54 As you may know already,
17:56 this cowboy hat on the table is composed of approximately
18:01 28 thousand triangles built by connecting together around 14,000 vertices,
18:06 each with X, Y, and Z coordinates.
18:10 These vertex coordinates are built using a coordinate system called model space
18:15 with the origin of 0,0,0 being at the center of the hat.
18:20 To build a 3D world we place hundreds of objects,
18:24 each with their own model space into the world environment and, in order
18:28 for the camera to be able to tell
18:31 where each object is relative to other objects,
18:34 we have to convert or transform all the vertices from each
18:38 separate model space into the shared world coordinate system or world space.
18:43 So, as an example, how do we convert the 14 thousand
18:48 vertices of the cowboy hat from model space into world space?
18:52 Well, we use a single instruction which adds the position
18:56 of the origin of the hat in world space to the corresponding X,Y,
19:01 and Z coordinate of a single vertex in model space.
19:05 Next we copy this instruction to multiple data, which is all the remaining X,Y,
19:11 and Z coordinates of the other thousands
19:14 of vertices that are used to build the hat.
19:17 Next, we do the same for the table and the rest
19:20 of the hundreds of other objects in the scene,
19:22 each time using the same instructions
19:25 but with the different objects’ coordinates in world space,
19:29 and each objects’ thousands of vertices in model space.
19:32 As a result, all the vertices and triangles
19:36 of all the objects are converted to a common world
19:39 space coordinate system and the camera can now determine
19:43 which objects are in front and which are behind.
19:46 This example illustrates the power of SIMD or single
19:50 instruction multiple data and how a single instruction is applied
19:54 to 5,629 different objects with a total of 8.3 million
19:59 vertices within the scene resulting in 25 million addition calculations.
20:05 The key to SIMD and embarrassingly parallel programs is that every one
20:10 of these millions of calculations has no dependency on any other calculation,
20:15 and thus all these calculations can be distributed to the thousands
20:19 of cores of the GPU and completed in parallel with one another.
20:24 It's important to note that vertex transformation from model space to world
20:29 space is just one of the first steps of a rather
20:32 complicated video game graphics rendering pipeline and we have a separate
20:36 video that delves deeper into each of these other steps.
20:40 Also, we skipped over the transformations
20:43 for the rotation and scale of each object, but factoring in these values is
20:48 a similar process that requires additional SIMD calculations.
20:51 Now that we have a simple understanding of SIMD,
20:55 let’s discuss how this computational architecture
20:58 matches up with the physical architecture.
21:00 Essentially, each instruction is completed by a thread
21:04 and this thread is matched to a single CUDA core.
21:08 Threads are bundled into groups of 32 called warps,
21:11 and the same sequence of instructions is issued to all the threads in a warp.
21:17 Next warps are grouped into thread blocks
21:19 which are handled by the streaming multiprocessor.
21:22 And then finally thread blocks are grouped into grids,
21:26 which are computed across the overall GPU.
21:30 All these computations are managed or scheduled by the Gigathread Engine,
21:35 which efficiently maps thread blocks to the available streaming multiprocessors.
21:39 One important distinction is that within SIMD architecture,
21:44 all 32 threads in a warp follow the same
21:47 instructions and are in lockstep with each other,
21:50 kind of like a phalanx of soldiers moving together.
21:54 This lock step execution applied to GPUs up until around 2016.
21:59 However, newer GPUs follow a SIMT
22:03 architecture or single instruction multiple threads.
22:07 The difference between SIMD and SIMT is that while
22:10 both send the same set of instructions to each thread,
22:15 with SIMT, the individual threads don’t need to be
22:18 in lockstep with each other and can progress at different rates.
22:22 In technical jargon, each thread is given its own program counter.
22:26 Additionally, with SIMT all the threads within
22:30 a streaming multiprocessor use a shared 128 kilobyte L1
22:34 cache and thus data that’s output by one
22:38 thread can be subsequently used by a separate thread.
22:42 This improvement from SIMD to SIMT allows
22:46 for more flexibility when encountering warp divergence
22:49 via data-dependent conditional branching and easier reconvergence
22:53 for the threads to reach the barrier synchronization.
22:57 Essentially newer architectures of GPUs are more flexible
23:01 and efficient especially when encountering branches in code.
23:05 One additional note is that although you may think
23:09 that the term warp is derived from warp drives,
23:12 it actually comes from weaving and specifically the Jacquard Loom.
23:16 This loom from 1804 used programmable punch cards to select
23:22 specific threads out of a set to weave together intricate patterns.
23:27 As fascinating as looms are, let’s move on.
23:30 The final topics we’ll explore are bitcoin mining,
23:35 tensor cores and neural networks.
23:37 But first we’d like to ask you to ‘like’ this video,
23:41 write a quick comment below,
23:42 share it with a colleague, friend or on social media,
23:46 and subscribe if you haven’t already.
23:49 The dream of Branch Education is to make free and accessible,
23:53 visually engaging educational videos that dive
23:56 deeply into a variety topics on science, engineering, and how technology works,
24:02 and then to combine multiple videos into an entirely
24:06 free engineering curriculum for high school and college students.
24:10 Taking a few seconds to like, subscribe, and comment below helps us a ton!
24:16 Additionally, we have a Patreon page with AMAs and behind the scenes footage,
24:22 and, if you find what we do useful, we would appreciate any support.
24:28 Thank you.
24:29 So now that we’ve explored how single
24:32 instruction multiple threads is used in video games,
24:36 let’s briefly discuss why GPUs were initially used for mining bitcoin.
24:40 We’re not going to get too far into the algorithm
24:43 behind the blockchain and will save it for a separate episode,
24:47 but essentially, to create a block on the blockchain,
24:51 the SHA-256 hashing algorithm is run
24:53 on a set of data that includes transactions,
24:57 a time stamp, additional data, and a random number called a nonce.
25:02 After feeding these values through the SHA-256
25:05 hashing algorithm a random 256-bit value is output.
25:08 You can kind of think of this algorithm as a lottery
25:13 ticket generator where you can’t pick the lottery number,
25:16 but based on the input data,
25:18 the SHA-256 algorithm generates a random lottery ticket number.
25:23 Therefore, if you change the nonce value and keep
25:26 the rest of the transaction data the same,
25:28 you’ll generate a new random lottery ticket number.
25:31 The winner of this bitcoin mining lottery is the first randomly
25:35 generated lottery number to have the first 80 bits all zeroes,
25:39 while the rest of the 176 values don’t matter
25:43 and once a winning bitcoin lottery ticket is found,
25:46 the reward is 3 bitcoin and the lottery resets
25:49 with a new set of transactions and input values.
25:53 So, why were graphics cards used?
25:56 Well, GPUs ran thousands of iterations
25:59 of the SHA-256 algorithm with the same transactions,
26:04 timestamp, other data, but, with different nonce values.
26:07 As a result, a graphics card like this one could generate around
26:12 95 million SHA-256 hashes or 95
26:16 million randomly numbered lottery tickets every second,
26:20 and hopefully one of those lottery numbers would
26:23 have the first 80 digits as all zeros.
26:27 However, nowadays computers filled with ASICs
26:30 or application specific integrated circuits perform
26:34 250 trillion hashes a second or the equivalent of 2600 graphics cards,
26:41 thereby making graphics cards look like a spoon when mining
26:45 bitcoin next to an excavator that is an asic mining computer.
26:50 Let’s next discuss the design of the tensor cores.
26:53 It’ll take multiple full-length videos to cover generative AI,
26:57 and neural networks,
26:58 so we’ll focus on the exact matrix math that tensor cores solve.
27:04 Essentially, tensor cores take three matrices and multiply the first two,
27:08 add in the third and then output the result.
27:12 Let’s look at one value of the output.
27:14 This value is equal to the sum of values of the first row
27:19 of the first matrix multiplied by the values
27:21 from the first column of the second matrix,
27:24 and then the corresponding value of the third matrix is added in.
27:28 Because all the values of the 3 input matrices are ready at the same time,
27:33 the tensor cores complete all
27:35 of the matrix multiplication and addition calculations concurrently.
27:39 Neural Networks and generative AI require trillions to quadrillions of matrix
27:45 multiplication and addition operations and typically uses much larger matrices.
27:51 Finally, there are Ray Tracing Cores which we
27:54 explored in a separate video that’s already been released.
27:58 That’s pretty much it for graphics cards.
28:00 We’re thankful to all our Patreon
28:03 and YouTube Membership Sponsors for supporting our videos.
28:06 If you want to financially support our work,
28:09 you can find the links in the description below.
28:12 This is Branch Education, and we create 3D animations that dive deeply
28:17 into the technology that drives our modern world.
28:21 Watch another Branch video by clicking one
28:24 of these cards or click here to subscribe.
28:27 Thanks for watching to the end!