Logo/
Dmitrii Klepikov

Shared by Dmitrii Klepikov

Log in

Make a lecture like this from your own PDF

Drop a PDF, slides or notes here. You'll sign up, then yours starts.

0:00 / 4:38

0:00 / 4:38The Performance Loop
GPU Fundamentals for AI Inference
Dmitrii Klepikov

Shared by Dmitrii Klepikov

Summary

Full transcript

0:00If you are new to the world of AI hardware, the speed of a model can feel like magic. But optimizing a GPU is actually a rigorous scientific loop. We never start by just changing code. We begin by fixing a stable workload—the exact input and hardware state—then we inspect the system timeline to find the 'limiter'. Is the chip waiting for data, or is it working through a mountain of math? We form a hypothesis, test the smallest possible change, and measure the results. This evidence-based approach is how we move from guessing to engineering.

0:33To talk to a GPU, you need to speak its language of hierarchy. When we run an AI function, we call it a 'Kernel'. That kernel is broken into a Grid of Thread Blocks. The most important unit for performance is the 'Warp'—a group of 32 threads that execute instructions in lockstep. Think of it like a formation of dancers; if one person stops to tie their shoe, the whole group pauses. This is called 'divergence', and it’s why we try to keep the work identical across all 32 lanes in a warp.

1:04GPUs aren't actually faster at single tasks than CPUs; they are just better at hiding their downtime. When one warp needs to fetch a piece of data from the main memory, it might have to wait for hundreds of clock cycles. Instead of sitting idle, the GPU's scheduler immediately swaps in another warp that is ready to work. This is 'Latency Hiding'. To do this effectively, we need high 'Occupancy'—essentially keeping enough spare work on the chip so the 'kitchen' never stops cooking while waiting for a delivery.

1:35The most expensive thing a GPU does is move data from 'Global Memory' or VRAM. To be efficient, we use 'Coalescing'. Imagine a warp where all 32 threads want to read a single number. If those numbers are sitting right next to each other in memory, the GPU can grab them all in a single 32-byte transaction. But if the threads are looking at scattered addresses, the GPU has to make multiple slow trips. This is why we prefer 'Structure of Arrays'—it lines up our data so the GPU can grab exactly what it needs in one go.

2:08Closer to the math units is 'Shared Memory'. It’s a fast scratchpad managed by the programmer. It's divided into 32 'Banks'. As long as every thread in a warp asks for data from a different bank, it’s lightning fast. But if two threads ask for different numbers from the same bank, they collide—this is a 'Bank Conflict'. We often 'pad' our data, like adding an extra column to a table, just to shift the addresses so they line up with different banks. It’s a small memory cost for a massive speed win.

2:39Every GPU has two ceilings: its math speed and its memory bandwidth. We use the 'Roofline Model' to see which one we’re hitting. It looks at 'Arithmetic Intensity'—how many math operations we do for every byte of data we move. If we do a lot of math on a little data, we are 'Compute Bound'. If we spend all our time moving data and very little time on math, we are 'Memory Bound'. Knowing your position on the roofline tells you exactly what to fix next.

3:08Let’s look at a real-world project called NIRC, a neural rendering pipeline. Normally, a model might load data, do math, and save the result back to memory for every single layer. NIRC uses 'Operator Fusion'. It pulls the data into the GPU's fast internal registers and shared memory, then executes multiple layers of a neural network without ever touching the slow main memory. By keeping the work 'GPU-resident', we eliminate the 'tax' of memory movement, making complex rendering possible in real-time.

3:41Optimizing for speed is dangerous if you break the model's accuracy. In an LLM-guided project, we used AI to propose faster code, but we needed a 'Judge' to catch mistakes. We sampled the 'Primary Render Parameter Space'—testing thousands of random lighting and camera conditions. We used the FLIP metric to detect errors the human eye might miss. If the faster version had an 'exceedance rate' higher than 1%, it was rejected. Remember: finding an optimization is easy; proving it's safe to ship is the real challenge.

4:13We’ve covered the performance loop, the execution hierarchy, and the memory pyramid. Whether you are fusing kernels like in NIRC or building a validation judge for new AI code, the principles remain the same. Respect the warp, watch your memory banks, and always let the data lead your optimization. The GPU is a powerful tool, and with these engineering discipline, you now have the keys to unlock its full potential.

Ask AI about this video

Answers cite the source. Free account, no credit card.