<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sanika Dhuri on Medium]]></title>
        <description><![CDATA[Stories by Sanika Dhuri on Medium]]></description>
        <link>https://medium.com/@sanika8356?source=rss-fca6ae6461b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*y_VnaeDyNWjn7XZP</url>
            <title>Stories by Sanika Dhuri on Medium</title>
            <link>https://medium.com/@sanika8356?source=rss-fca6ae6461b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:59:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sanika8356/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A Beginner’s Guide to the GPU Roofline]]></title>
            <link>https://medium.com/@sanika8356/a-beginners-guide-to-the-gpu-roofline-7973891b4913?source=rss-fca6ae6461b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/7973891b4913</guid>
            <category><![CDATA[cuda]]></category>
            <category><![CDATA[llm-inference]]></category>
            <category><![CDATA[gpu-computing]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[nvidia-gpu]]></category>
            <dc:creator><![CDATA[Sanika Dhuri]]></dc:creator>
            <pubDate>Fri, 27 Nov 2026 09:54:57 GMT</pubDate>
            <atom:updated>2026-11-27T09:54:57.748Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Why a chip that can do 989 trillion math operations a second often uses less than 1% of that and how to find out what is holding it back.</em></p><h3>The mystery of the missing 99%</h3><p>Open the spec sheet of NVIDIA’s H100 GPU and one number jumps out: <strong>989 trillion</strong> math operations per second. That is nearly a thousand trillion.</p><p>Now give that GPU a very simple job, like adding two long lists of numbers, and it uses less than <strong>1%</strong> of that speed. Watch a chatbot write an answer, one token (roughly a word) at a time and the GPU is still at well under <strong>1%</strong> for each one.</p><p>The GPU isn’t broken and it isn’t slow. Something else is holding it back, and a simple picture called the <strong>roofline</strong> shows exactly what.</p><p>By the end you will know where data lives inside an H100 and why fetching it is slow, what the two speed limits of a GPU are, how to tell which one a program will hit, and what you can do to get more out of the chip. If a term slips past you, there is a short glossary at the end.</p><h3>Part 1: What is a GPU?</h3><p>Say you want to add two lists of a million numbers each, pair by pair:</p><pre>c[0] = a[0] + b[0]<br>c[1] = a[1] + b[1]<br>...<br>c[999999] = a[999999] + b[999999]</pre><p>Notice something: no addition needs the result of another one. They are all independent.</p><p>A <strong>CPU</strong> has a few powerful cores, usually somewhere between 8 and 64 on a typical machine. Each one is great at complicated tasks, but only a few things run at any moment. A <strong>GPU</strong> has thousands of simpler cores. Each one is weaker, but they all work at once, so a million independent additions get done in big parallel batches.</p><p>Deep learning is mostly this kind of work: the same small calculation, repeated over huge piles of numbers. That’s why we run it on GPUs.</p><h3>Part 2: Inside the H100</h3><p>A quick word on names. <strong>NVIDIA</strong> is the company, <strong>Hopper</strong> is the name of a chip design and the <strong>H100</strong> is a product built on that design. It comes in a few versions and every number in this article is for the <strong>H100 SXM</strong>.</p><p>Here is the chip from above</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8H-HukDMLSPY-a_do93Jw.jpeg" /></figure><p>It has three parts:</p><ul><li><strong>SMs (Streaming multiprocessors): </strong>132 identical blocks, all running at once. <strong>All the math happens inside them.</strong></li><li><strong>L2 cache:</strong> 50 MB of fast storage shared by every SM.</li><li><strong>HBM (high bandwidth memory):</strong> The 80 GB main memory, mounted right beside the chip. <strong>Your data starts here.</strong></li></ul><p>That gap, between where the data lives (HBM) and where the math happens (the SMs), is the reason for everything else in this article.</p><h3>Inside one SM</h3><p>Let’s zoom into a single SM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y1kt2H8X-5otyj0NrWrJOQ.png" /></figure><p>Each of the 4 sections has 32 <strong>CUDA cores</strong>, which do simple math one add or multiply at a time, one <strong>tensor core</strong>, which multiplies small blocks of numbers in a single step and is where most of the H100’s speed comes from and a <strong>register file</strong>, the fastest storage there is. Each thread’s registers are private to it.</p><p>On top of that, the whole SM shares one block of fast memory, split into the <strong>L1 cache</strong> (filled automatically by the hardware) and <strong>shared memory</strong> (where you choose what goes in, so threads can share data).</p><h3>Part 3: How data travels and what it costs</h3><p>The math happens only in the SMs, but your data starts in HBM. So every program does the same three things: it <strong>loads</strong> data in, <strong>computes</strong> and <strong>stores</strong> the results back.</p><p>Data usually travels like this (a simplified picture):</p><p>HBM → L2 → L1 / shared memory → registers → cores</p><p>Each step closer to the math is faster, but holds a lot less.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z0XBM-SxdF1Fb3BvL1pFlw.png" /><figcaption>The closer to the math units, the smaller and faster the memory. Wait times are rough figures from published microbenchmarks of Hopper-class chips.</figcaption></figure><p>A useful way to think about it: a chef keeps a few ingredients in their hands, a few more on the counter and the rest in a warehouse across the road. Everything is fast until you have to go to the warehouse.</p><p>Is 360 nanoseconds a lot? It is a tiny sliver of a second. But look at what the GPU could do in that time:</p><p><strong>989 trillion operations per second × 360 nanoseconds ≈ 356 million operations.</strong></p><p><strong>In the time of a single trip to HBM, the H100 could have done hundreds of millions of calculations!!</strong></p><p>The GPU hides a lot of this wait by running thousands of threads, so while some wait for data, others compute. What it can’t hide is that a huge amount of data has to flow through a pipe of limited width. That brings us to the two speed limits.</p><h3>Why not just one big, fast memory?</h3><p>Because the fast kind and the big kind are built differently.</p><p>The fast kind, called <strong>SRAM</strong>, is what registers and caches are made of. Each bit needs about six transistors, which takes up a lot of space on the chip, so only a few megabytes fit near the math units.</p><p>The big kind, called <strong>DRAM</strong>, is what HBM is made of. Each bit needs just one transistor and a tiny capacitor, so far more fits (gigabytes), but it is slower and sits farther away from the math.</p><h3>Part 4: The GPU’s two speed limits</h3><p>A GPU does only two things: it <strong>calculates</strong> and it <strong>waits for data</strong>. That gives two states:</p><ul><li><strong>Compute-bound:</strong> the math units are the bottleneck. They are working flat out and data arrives faster than they can use it.</li><li><strong>Memory-bound:</strong> memory is the bottleneck. The math units finish quickly and sit idle, waiting for the next data.</li></ul><p>Each state has a speed limit. Let’s work out both.</p><h3>Two small terms</h3><ul><li>A <strong>FLOP</strong> is one floating-point operation: one add or one multiply on floating-point numbers 3.5 × 2.0 is one FLOP.</li><li><strong>FLOP/s</strong> is a speed: FLOPs per second. One TFLOP/s (“teraflop”) is a trillion of them per second.</li></ul><h3>Limit 1: Peak compute (how fast can the GPU do math?)</h3><p>Peak compute is the maximum rate at which a GPU can perform calculations, measured in FLOPs per second.</p><p>The H100 SXM has a peak throughput of <strong>989 TFLOP/s</strong> for dense BF16 Tensor Core operations.</p><p>But there’s a catch: having the ability to perform 989 trillion operations per second doesn’t mean every program will actually achieve that speed. If the GPU has to wait for data, its computing units cannot remain busy.</p><p>That’s where the second limit comes in.</p><h3>Limit 2: Memory bandwidth (how fast can the GPU get data?)</h3><p>Memory bandwidth is how much data can be transferred between the GPU’s memory (HBM) and the chip per second.</p><p>The H100 SXM has a memory bandwidth of <strong>3.35 TB/s</strong>, meaning it can transfer approximately 3.35 trillion bytes every second.</p><h3>Putting the two together</h3><p>Divide one limit by the other:</p><p><strong>989 trillion operations per second ÷ 3.35 trillion bytes per second ≈ 295 operations per byte</strong></p><p>This is called the <strong>ridge point</strong>. It says that for every byte memory delivers, the GPU can do about 295 operations. So to keep the math units fully busy, a program needs to do about 295 operations on every byte it moves.</p><p>If it does less, the math units finish early and sit idle, waiting for data. That is <strong>memory-bound</strong>. If it does more, data is no longer the problem and the math units are the limit. That is <strong>compute-bound</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-jQutc8i_6BQN7s8BuetA.png" /><figcaption>Whichever of the two takes longer sets the speed of the program. The other one spends part of its time idle.</figcaption></figure><h3>Part 5: Which limit will your program hit?</h3><p>The two limits belong to the GPU. Now let’s look at a program. Every program has two amounts: how many <strong>operations</strong> it needs, and how many <strong>bytes</strong> it moves. Dividing each by the matching speed gives two times:</p><ul><li><strong>Math time = operations ÷ peak speed</strong></li><li><strong>Data time = bytes ÷ bandwidth</strong></li></ul><p>Both happen at the same time, so the program takes as long as the <em>bigger</em> one. That one is the bottleneck.</p><p>Here is a made-up machine that does 100 operations per second and moves 10 bytes per second, running two programs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9wOOGpC2pWjBeu5xcE0JA.png" /><figcaption>Both programs need the same 1,000 operations, but Program B moves ten times more bytes, so it is stuck waiting on data.</figcaption></figure><h3>Arithmetic intensity</h3><p>Working out both times for every program gets tedious. Luckily, one number gives you the answer straight away: how much math the program does for each byte it moves. This is called <strong>arithmetic intensity</strong>, or <strong>AI</strong>.</p><p><strong>Arithmetic intensity (AI) = operations ÷ bytes moved to and from HBM</strong></p><p>A high AI means every byte is put to heavy use. A low AI means each byte is used once or twice and then thrown away. In our example, Program A does 1,000 operations on 50 bytes, so its AI is <strong>20</strong>. Program B does the same 1,000 operations on 500 bytes, so its AI is only <strong>2</strong>.</p><p>The machine has a matching number, its ridge: how many operations it can do for each byte it can fetch. For our made-up machine that is 100 ÷ 10 = <strong>10</strong> operations per byte. Now the rule is simple:</p><ul><li><strong>AI above the ridge → compute-bound.</strong> (Program A: 20 &gt; 10.)</li><li><strong>AI below the ridge → memory-bound.</strong> (Program B: 2 &lt; 10.)</li></ul><h3>Part 6: The roofline plot</h3><p>So far we asked “which side of the ridge are we on?”. The plot answers a bigger question: <strong>how fast can this GPU run this program, at best?</strong> We call that the <strong>attainable speed</strong>.</p><h3>Attainable speed</h3><p>Attainable speed is the maximum performance a program can reach, given the GPU’s compute capacity and memory bandwidth.</p><p>It is the smaller of the two limits:</p><p><strong>Attainable speed = min(Peak compute, Bandwidth × AI)</strong></p><p>Why these two?</p><ul><li><strong>Peak compute</strong> is the maximum amount of math the GPU can perform per second.</li><li><strong>Bandwidth × AI</strong> is the maximum amount of math the available data can support per second.</li></ul><p>A program cannot exceed either limit. Its attainable speed is therefore determined by whichever limit is lower. Here is the H100 at a few values of AI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Md2GVXs1hoLmnv__FdwSDg.png" /></figure><p>The attainable speed climbs with AI, then stops at the peak. The switch happens exactly at the ridge, where the two numbers are equal.</p><h3>Drawing it</h3><p>Put AI on the x-axis and attainable speed on the y-axis:</p><ol><li>Draw the points from the table. They form a rising line: the <em>data limit</em>, 3.35 × AI.</li><li>Draw a flat line at 989: the <em>math limit</em>.</li><li>They meet at AI ≈ 295, the ridge. Together they look like a roof, which is where the name comes from.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WyYokE_iOBcDl2ANAjYvlQ.png" /><figcaption>This roofline uses the H100’s dense BF16 Tensor Core peak. Other number formats and compute units have different compute ceilings.</figcaption></figure><h3>Reading the plot</h3><p>To place a program: work out its AI, find that number on the x-axis and go straight up until you hit the line. That height is its attainable speed.</p><ul><li><strong>Left of the ridge</strong> you land on the slope: <em>memory-bound</em>.</li><li><strong>Right of the ridge</strong> you land on the flat part: <em>compute-bound</em>.</li><li>The gap between a program’s measured performance and the roofline represents its potential performance headroom.</li></ul><h3>Why are the axes logarithmic?</h3><p>On a log axis, each step <em>multiplies</em> by 10 instead of adding: 0.1, 1, 10, 100, 1,000. We need that for two reasons:</p><ul><li><strong>The range is huge.</strong> AI runs from under 1 to over 1,000 and speed from about 0.5 to 989 TFLOP/s. On a normal axis, the small values would be squashed against the bottom and look like zero.</li><li><strong>Proportions become visible.</strong> Equal distances mean equal ratios and a proportional relationship (the data limit) becomes a straight line.</li></ul><h3>Part 7: So how do we get more out of our GPU?</h3><p>Once you know which limit you are hitting, you know what to fix. Most real programs are memory-bound and for those the goal is always the same: <strong>move right on the plot by raising the AI.</strong> There are only two ways to do that: move fewer bytes, or do more math with each byte you move.</p><h3>Fusion: move fewer bytes</h3><p>Say we compute relu(x × 2 + 1) on a large array of numbers. Normally that runs as three separate GPU programs and each one writes its result back to HBM just so the next one can read it again. Fused into one program, the in-between values stay in registers, so we read once and write once.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fCJDBtdQjUCjmIpbxRYg9Q.png" /><figcaption>Same math, but the fused version moves a third of the bytes, so the arithmetic intensity triples.</figcaption></figure><p>The bytes drop to a third, the AI triples and if the program is memory-bound it can run up to about <strong>3× faster</strong>. In PyTorch, a compiler (torch.compile) can fuse steps like this for you.</p><h3>Tiling: reuse data close to the math</h3><p>Instead of repeatedly fetching small pieces from HBM, load a block of data into fast on-chip memory, use it as much as possible and only then move on. <strong>FlashAttention</strong> does exactly this for the attention step in language models: same math, far fewer trips to HBM.</p><h3>Smaller numbers</h3><p>Storing a model’s weights in 8 or 4 bits instead of 16 means fewer bytes to move for every weight. The trade-off is a potential reduction in accuracy.</p><h3>Batching: more math per byte</h3><p>This one fixes the chatbot from the start. With a single user, every weight is read from HBM, used once and thrown away. But if we serve many users at the same time, we read the weights <strong>once</strong> and use them for everyone. With B users the math grows B times while the bytes barely change, so the AI is about B.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q28MZJo84eDPTTKzBBFpSg.png" /><figcaption>Idealized best case for a chatbot. The more users share one read of the weights, the closer the GPU gets to its peak.</figcaption></figure><p>That is why AI services batch requests. In this idealized example, a batch size of around 295 reaches the ridge and after that more users simply take more time. These numbers are idealized and real servers do somewhat worse, because attention reads each user’s own history and that can’t be shared.</p><h3>If you are compute-bound</h3><p>On the flat roof, the math units are already full. The only ways to go faster are to do less math (a smaller model or a better algorithm), use faster math (tensor cores, lower-precision numbers), or use more GPUs.</p><h3>The roof is a ceiling, not a promise</h3><p>The roofline shows the <em>best case</em>. Real programs land below it: tiny tasks finish before the GPU can be told what to do next, a small job may not keep all 132 SMs busy, real programs often move more bytes than the ideal count and clocks drop under heavy load. Even very well-tuned programs usually stay well short of peak.</p><p>Still, it gives you the one question worth asking whenever a program feels slow. Is the GPU waiting on data, or is it busy doing math? Once you know which, you know where to look.</p><h3>Mini glossary</h3><ul><li><strong>SM (streaming multiprocessor):</strong> one of the H100’s 132 identical blocks, where all the math happens.</li><li><strong>HBM:</strong> the 80 GB main memory beside the chip.</li><li><strong>L2 / L1 cache:</strong> smaller, faster memory between HBM and the math units.</li><li><strong>Register:</strong> the fastest storage, private to each thread.</li><li><strong>Tensor core:</strong> a circuit that multiplies small blocks of numbers in one step. Most of the chip’s speed comes from here.</li><li><strong>FLOP / TFLOP/s:</strong> one math operation and a trillion of them per second.</li><li><strong>Bandwidth:</strong> how many bytes per second memory can deliver.</li><li><strong>Arithmetic intensity (AI):</strong> operations done per byte moved to and from HBM.</li><li><strong>Ridge point:</strong> the AI where the roofline bends (about 295 on the H100).</li><li><strong>Compute-bound / memory-bound:</strong> limited by the math units, or by getting data to them.</li></ul><h3>Further reading</h3><ul><li>Williams, Waterman and Patterson, “Roofline: An Insightful Visual Performance Model for Multicore Architectures,” Communications of the ACM, 2009. The original roofline paper: <a href="https://dl.acm.org/doi/pdf/10.1145/1498765.1498785">https://dl.acm.org/doi/pdf/10.1145/1498765.1498785</a></li><li>Horace He, “Making Deep Learning Go Brrrr From First Principles.” A beginner-friendly take on compute-bound vs memory-bound in deep learning:<a href="https://horace.io/brrr_intro.html"> https://horace.io/brrr_intro.html</a></li><li>NVIDIA, “NVIDIA Hopper Architecture In-Depth.” Official deep dive into the H100’s SMs, tensor cores and memory: <a href="https://developer.nvidia.com/blog/nvidia-hopper-architecture-in-depth/">https://developer.nvidia.com/blog/nvidia-hopper-architecture-in-depth/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7973891b4913" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>