<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Gpu Kernel Optimization on RockB</title><link>https://baeseokjae.github.io/tags/gpu-kernel-optimization/</link><description>Recent content in Gpu Kernel Optimization on RockB</description><image><title>RockB</title><url>https://baeseokjae.github.io/images/og-default.png</url><link>https://baeseokjae.github.io/images/og-default.png</link></image><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 26 Aug 2026 22:01:44 +0000</lastBuildDate><atom:link href="https://baeseokjae.github.io/tags/gpu-kernel-optimization/index.xml" rel="self" type="application/rss+xml"/><item><title>GPU Performance &amp; AI Infrastructure: A Hands-On Playground Guide</title><link>https://baeseokjae.github.io/posts/gpu-perf-playground-ai-infra-2026/</link><pubDate>Wed, 26 Aug 2026 22:01:44 +0000</pubDate><guid>https://baeseokjae.github.io/posts/gpu-perf-playground-ai-infra-2026/</guid><description>Learn GPU performance and AI infrastructure by building and profiling kernels. A hands-on playground path from profiling-first mindset to real cost savings.</description><content:encoded><![CDATA[<p>GPU performance is the single biggest lever in modern AI infrastructure, and the fastest way to master it is to stop reading theory and start building. This guide gives you a hands-on playground path: set up profiling tooling, measure before you optimize, build the canonical matrix multiplication kernel, and learn how micro-optimizations compound into real training and inference cost savings. By the end, you will know exactly how to profile a GPU, where your time actually goes, and when to hand-write a kernel versus trust a vendor library.</p>
<h2 id="why-gpu-performance-is-the-new-bottleneck-in-ai-infrastructure">Why GPU Performance Is the New Bottleneck in AI Infrastructure</h2>
<p>For years, the bottleneck in AI infrastructure was model quality. Today, the bottleneck is GPU efficiency. As models grow and training runs scale to thousands of accelerators, the cost of idle GPU time has become the dominant line item in an AI budget. Industry-wide GPU utilization in AI data centers is often far below peak, and storage and data-loading bottlenecks are a primary cause of idle GPU time, according to engineering analysis from JuiceFS. When a 1,000-GPU training cluster sits at 50% utilization, you are effectively paying for 500 GPUs that do nothing.</p>
<p>The economics are stark. A single high-end accelerator can cost tens of thousands of dollars, and a training run that takes weeks multiplies that cost across every hour of underutilization. This is why GPU performance is no longer a niche concern for kernel developers — it is a core skill for anyone who owns AI infrastructure. The teams that win on cost and time-to-train are the teams that treat GPU efficiency as a first-class engineering discipline, not an afterthought.</p>
<p>The good news is that the skills are learnable and transferable. You do not need to be a hardware engineer to profile a kernel, read a utilization report, or fix a data pipeline that is starving your GPUs. You need a playground, a profiling-first mindset, and a systematic approach. That is exactly what this guide builds.</p>
<h2 id="setting-up-your-gpu-performance-playground-tooling--environment">Setting Up Your GPU Performance Playground (Tooling &amp; Environment)</h2>
<p>A GPU performance playground is a controlled environment where you can write kernels, profile them, and iterate without breaking production. The goal is to make experimentation cheap and measurement automatic. You want three things: a GPU you can access, a profiler you trust, and a set of benchmark kernels you understand deeply.</p>
<p>Start with the tooling. On NVIDIA hardware, the standard stack is <code>ncu</code> (NVIDIA Nsight Compute) for kernel-level profiling and <code>nsys</code> (Nsight Systems) for application-level tracing. On AMD hardware, the equivalent is ROCm&rsquo;s profiling tooling, which covers profiler tooling, kernel-level metrics, and an optimization workflow. The AMD ROCm profiling guide positions profiling as the first step before any optimization — a principle that applies regardless of vendor.</p>
<p>Your environment should be reproducible. Use a container image with the CUDA or ROCm toolkit pinned to a specific version, and keep your benchmark kernels in a version-controlled repository. A simple structure looks like this:</p>
<ul>
<li><code>kernels/</code> — your hand-written kernels (matmul, copy, reduction)</li>
<li><code>benchmarks/</code> — scripts that run each kernel and record metrics</li>
<li><code>profiles/</code> — saved profiler output for comparison across iterations</li>
<li><code>results/</code> — a log of what changed and what the numbers said</li>
</ul>
<p>The playground philosophy matters more than the specific tools. The GPU systems playground approach used in CUDA kernel experiments and performance profiling emphasizes an experiment-driven path to learning GPU internals. You learn by changing one variable, measuring the effect, and recording the result. Every optimization you make in the playground becomes a skill you can apply to real AI infrastructure.</p>
<h2 id="profiling-first-measure-your-gpu-before-you-optimize">Profiling First: Measure Your GPU Before You Optimize</h2>
<p>The single biggest mistake in GPU performance work is optimizing before measuring. You cannot know whether a change helps unless you have a baseline, and you cannot find the real bottleneck by guessing. Profiling is the standard first step in any GPU performance optimization workflow, and it should be the first thing you do in your playground.</p>
<p>Profiling answers three questions: Is the GPU busy? Is the GPU doing useful work? And where is the time going? A profiler like <code>ncu</code> gives you kernel-level metrics: occupancy, memory throughput, compute throughput, and stall reasons. These tell you whether a kernel is memory-bound, compute-bound, or latency-bound — and that diagnosis determines which optimization strategy will actually work.</p>
<p>The profiling-first mindset is the biggest lever for AI infra teams. When you profile before you optimize, you avoid the classic failure mode of spending a week optimizing a kernel that was never the bottleneck. You also build a baseline culture: every change is measured, every claim is backed by a number, and every optimization is verified against the previous state.</p>
<p>A practical workflow looks like this:</p>
<ol>
<li>Profile the current kernel and record the key metrics.</li>
<li>Identify the bottleneck: memory, compute, or latency.</li>
<li>Make one change targeting that bottleneck.</li>
<li>Re-profile and compare against the baseline.</li>
<li>Keep the change only if it improves the metric you targeted.</li>
</ol>
<p>This loop is the heart of the playground. It is fast, it is measurable, and it builds the intuition that separates people who guess at GPU performance from people who understand it.</p>
<h2 id="the-canonical-kernel-building-and-optimizing-matrix-multiplication">The Canonical Kernel: Building and Optimizing Matrix Multiplication</h2>
<p>Matrix multiplication (matmul) is the canonical kernel for teaching GPU performance because it exercises memory bandwidth, compute, and kernel design all at once. It is also the operation at the heart of nearly every deep learning workload — fully connected layers, attention, and convolutions all reduce to matmul. If you can optimize matmul, you can optimize a large fraction of real AI compute.</p>
<p>The mini-GPU-runtime-playground approach builds understanding from first principles by treating matmul as the canonical kernel and progressing from CPU optimization to CUDA. You start with a naive implementation, profile it, and then apply a series of well-understood optimizations: tiling to improve data reuse, shared memory to reduce global memory traffic, and vectorized loads to increase memory throughput.</p>
<p>Each optimization teaches a distinct lesson:</p>
<ul>
<li><strong>Naive matmul</strong> teaches you the baseline and shows you how badly a naive kernel performs.</li>
<li><strong>Tiling</strong> teaches you data reuse and how to keep data in fast memory.</li>
<li><strong>Shared memory</strong> teaches you how to explicitly manage the memory hierarchy.</li>
<li><strong>Vectorization</strong> teaches you how to maximize memory bandwidth utilization.</li>
</ul>
<p>The key insight is that matmul is a memory-bound problem at small sizes and a compute-bound problem at large sizes, and the crossover point depends on your hardware. Profiling tells you which regime you are in, and that determines which optimization matters. This is why the playground approach works: you build the kernel, profile it, and see the tradeoffs with your own eyes instead of memorizing them from a textbook.</p>
<h2 id="memory-bandwidth-vs-compute-where-your-gpu-time-actually-goes">Memory Bandwidth vs Compute: Where Your GPU Time Actually Goes</h2>
<p>Every GPU kernel is limited by one of two resources: memory bandwidth or compute throughput. Understanding which one limits your kernel is the difference between effective optimization and wasted effort. A memory-bound kernel is waiting on data movement; a compute-bound kernel is waiting on arithmetic. The two require completely different optimization strategies.</p>
<p>Memory bandwidth is the amount of data a GPU can move per second, and it is often the real constraint in AI workloads. Many kernels are memory-bound because they read and write far more data than they compute on. The fix for a memory-bound kernel is to reduce memory traffic: use shared memory, increase data reuse, and avoid redundant global memory accesses. The JuiceFS analysis shows that data movement is so important that a distributed cache layer can push GPU utilization from roughly 50% to 98% in 1k GPU-scale AI training — the storage and data pipeline, not the compute, was the bottleneck.</p>
<p>Compute throughput is the number of arithmetic operations a GPU can perform per second. A compute-bound kernel is limited by FLOPs, and the fix is to improve arithmetic efficiency: use faster math, reduce redundant computation, and ensure the compute units stay busy. Profiling tells you which resource is the constraint by showing you the memory throughput and compute throughput percentages. If memory throughput is near 100% and compute is low, you are memory-bound. If the reverse, you are compute-bound.</p>
<p>The practical lesson is that most AI kernels are memory-bound, and most optimization wins come from reducing data movement rather than speeding up arithmetic. This is why the data pipeline matters so much: if your GPUs are idle waiting for data, no amount of kernel optimization will help. You have to fix the pipeline first.</p>
<h2 id="when-to-hand-write-kernels-vs-trust-vendor-libraries">When to Hand-Write Kernels vs Trust Vendor Libraries</h2>
<p>One of the most important decisions in GPU performance work is whether to hand-write a kernel or use a vendor library like cuBLAS or cuDNN. The answer is rarely &ldquo;always&rdquo; or &ldquo;never&rdquo; — it depends on the shape of your problem and the maturity of the library. A nuanced view on when a hand-written GPU kernel beats the library, and where it cannot, is essential for making this call.</p>
<p>Vendor libraries are the default choice for standard operations. cuBLAS and cuDNN are heavily optimized by the vendor, tuned for specific hardware, and battle-tested across thousands of workloads. For standard matmul shapes and common layer types, the library is almost always faster than anything you can write in a reasonable time. The library also gets free performance improvements every time the vendor releases a new version.</p>
<p>Hand-written kernels win in three situations. First, when your operation is not a standard library call — a custom fusion, a specialized attention variant, or a domain-specific kernel. Second, when you need to fuse multiple operations to reduce memory traffic, and the library cannot express the fusion. Third, when you are on hardware or a shape that the library does not optimize well, and a targeted kernel closes the gap.</p>
<p>The decision framework is simple: start with the library, profile it, and only hand-write a kernel when profiling shows a real gap that you can close. Never hand-write a kernel to match a library you have not profiled. The playground is the perfect place to test this: write a naive kernel, compare it against cuBLAS, and see the gap for yourself. That gap is the motivation for optimization, and it is also the reality check that keeps you honest about when hand-writing is worth it.</p>
<h2 id="the-hidden-bottleneck-data-pipelines-and-gpu-utilization">The Hidden Bottleneck: Data Pipelines and GPU Utilization</h2>
<p>The most underappreciated bottleneck in AI infrastructure is not the GPU at all — it is the data pipeline. GPUs are fast, but they are only useful when they have data to process. If the storage layer, the network, or the data-loading code cannot feed the GPUs fast enough, the accelerators sit idle and your utilization collapses.</p>
<p>The JuiceFS/MLPerf benchmark is the clearest demonstration of this. By using a distributed cache layer, the team achieved 98% GPU utilization in 1k GPU-scale AI training. The implication is direct: the data pipeline was the bottleneck, and fixing it unlocked near-peak utilization. This is a massive win because it requires no kernel optimization at all — it is pure infrastructure work.</p>
<p>The mechanics are straightforward. During training, every batch of data must be read from storage, preprocessed, and moved to the GPU. If any step in that chain is slow, the GPU waits. Common culprits include cold storage reads, network latency to remote data, CPU-bound preprocessing, and insufficient caching. Each of these creates idle GPU time that shows up as low utilization in your profiler.</p>
<p>The fix is a layered approach: cache hot data close to the GPUs, prefetch the next batch while the current one trains, and parallelize preprocessing across CPU cores. The MLPerf benchmark context matters here because it is the de-facto industry standard for measuring real AI training and inference performance across GPU platforms. If you can measure your utilization against a known baseline, you can quantify exactly how much the data pipeline is costing you — and how much fixing it is worth.</p>
<h2 id="from-micro-optimizations-to-ai-infra-cost-savings">From Micro-Optimizations to AI Infra Cost Savings</h2>
<p>Individual kernel optimizations might seem small, but they compound into enormous cost savings at scale. A 10% improvement in a kernel that runs millions of times across a training run is not a 10% improvement in one operation — it is a 10% reduction in the time and cost of the entire run. This is how micro-optimizations become macro savings.</p>
<p>The compounding works across three levels. At the kernel level, a faster matmul or a fused operation reduces the time per step. At the pipeline level, a better data path keeps GPUs busier and raises utilization. At the infrastructure level, higher utilization means you need fewer GPUs to do the same work, which means lower capital and operating costs. The JuiceFS result — pushing utilization from roughly 50% to 98% — is the extreme case: it effectively doubles the throughput of the same hardware.</p>
<p>The cost math is compelling. If a training run costs $100,000 and you improve GPU utilization by 20%, you save $20,000 on that run. Across a fleet of GPUs running continuously, the savings are recurring and substantial. This is why GPU performance is a strategic investment, not a technical nicety. Every hour of idle GPU time is money you are paying for and not using.</p>
<p>The playground teaches you the micro-skills, but the value is in applying them to the macro problem. Once you can profile a kernel, fix a data pipeline, and measure the result, you can quantify the cost impact of every optimization. That is the skill that makes you valuable to an AI infrastructure team.</p>
<h2 id="cross-vendor-skills-cuda-and-rocm-profiling-that-transfers">Cross-Vendor Skills: CUDA and ROCm Profiling That Transfers</h2>
<p>GPU performance skills are not locked to a single vendor. The profiling-first mindset, the memory-versus-compute diagnosis, and the optimization workflow transfer directly between NVIDIA CUDA and AMD ROCm. If you learn to profile on one platform, you can apply the same approach on the other with minimal relearning.</p>
<p>The concepts are identical: occupancy, memory throughput, compute throughput, and stall reasons mean the same thing on both platforms. The tools differ — NVIDIA uses Nsight Compute and Systems, while AMD uses ROCm profiling tooling — but the questions you ask are the same. The AMD ROCm profiling guide covers the same foundations as the CUDA guides: profiler tooling, kernel-level metrics, and an optimization workflow.</p>
<p>This transferability is increasingly valuable as the AI hardware landscape diversifies. Teams are no longer locked into a single vendor, and the ability to profile and optimize across platforms is a real competitive advantage. The playground approach makes this easy: build the same benchmark kernels on both platforms, profile them, and compare. You will find that the optimization lessons — reduce memory traffic, improve data reuse, keep compute units busy — apply everywhere.</p>
<p>The practical takeaway is to invest in the transferable skills, not the vendor-specific syntax. Learn the profiling workflow once, and you can apply it to any GPU platform. That is the difference between being a CUDA developer and being a GPU performance engineer.</p>
<h2 id="your-30-day-hands-on-gpu-performance-roadmap">Your 30-Day Hands-On GPU Performance Roadmap</h2>
<p>The fastest way to build GPU performance skills is a structured, hands-on roadmap. Here is a 30-day plan that takes you from zero to a working playground with real optimization wins.</p>
<p><strong>Week 1: Set up the playground.</strong> Get access to a GPU, install the profiling tooling for your platform (Nsight for CUDA, ROCm tools for AMD), and build a container with a pinned toolkit. Write a naive matmul kernel and profile it. Record the baseline metrics. This week is about environment and measurement, not optimization.</p>
<p><strong>Week 2: Optimize the canonical kernel.</strong> Apply tiling, shared memory, and vectorization to your matmul. Profile after every change and compare against the baseline. Learn to read the profiler output and identify whether you are memory-bound or compute-bound. By the end of the week, you should have a kernel that is measurably faster and a clear understanding of why.</p>
<p><strong>Week 3: Attack the data pipeline.</strong> Measure your GPU utilization during a realistic workload. Identify where the GPUs are idle and trace the cause back to the data path. Add caching, prefetching, or parallel preprocessing, and measure the utilization improvement. This is where you learn the hidden bottleneck that most teams miss.</p>
<p><strong>Week 4: Apply it to real infrastructure.</strong> Take your profiling and optimization skills to a real training or inference workload. Profile the actual kernels, find the real bottlenecks, and make targeted improvements. Quantify the cost impact of each change. This is where the playground skills become production value.</p>
<p>By the end of 30 days, you will have a working playground, a profiling-first mindset, and a set of verified optimization skills. More importantly, you will understand GPU performance the way it is actually learned — by building, measuring, and iterating. That is the hands-on path to GPU performance and AI infrastructure mastery.</p>
<h2 id="faq">FAQ</h2>
<p><strong>What is the first step in GPU performance optimization?</strong>
The first step is always profiling. Measure your GPU before you optimize anything. Profiling tells you whether a kernel is memory-bound or compute-bound, which determines the optimization strategy that will actually work. Guessing without a baseline is the most common and most expensive mistake in GPU performance work.</p>
<p><strong>Why is matrix multiplication the canonical kernel for learning GPU performance?</strong>
Matrix multiplication exercises memory bandwidth, compute, and kernel design all at once, and it is the operation at the heart of nearly every deep learning workload. Optimizing matmul teaches you tiling, shared memory, vectorization, and the memory-versus-compute tradeoff — skills that transfer directly to real AI kernels.</p>
<p><strong>How much can fixing the data pipeline improve GPU utilization?</strong>
Dramatically. In a 1k GPU-scale AI training benchmark, a distributed cache layer pushed GPU utilization to 98%, up from the far lower utilization caused by storage and data-loading bottlenecks. The data pipeline is often the real constraint, and fixing it requires no kernel optimization at all.</p>
<p><strong>When should I hand-write a GPU kernel instead of using a vendor library?</strong>
Start with the vendor library (cuBLAS, cuDNN) and profile it. Hand-write a kernel only when profiling shows a real gap you can close — typically for custom operations, fused kernels, or shapes the library does not optimize well. Never hand-write a kernel to match a library you have not profiled.</p>
<p><strong>Do GPU performance skills transfer between NVIDIA and AMD?</strong>
Yes. The profiling-first mindset, the memory-versus-compute diagnosis, and the optimization workflow are identical across CUDA and ROCm. Only the tools differ. Learning to profile on one platform transfers directly to the other, which is increasingly valuable as AI hardware diversifies.</p>
]]></content:encoded></item></channel></rss>