To decide whether a slow GPU-accelerated workload needs a different algorithm or better-written kernels, profile it and place its hot kernels on a roofline before changing any code. The authors of a roofline analysis of GPU nearest-neighbour search kernels already close to the bandwidth limit suggest that future gains will primarily come from moving less data. A kernel limited by latency or launch overhead calls for different fixes: more concurrency for latency, CUDA Graphs for launch overhead. The measured bottleneck should make the choice, not habit or a favourite technique.
The rest of this article works through how to read that bottleneck, one worked kernel where restructuring was the right move, and the cases where fusion and graphs are enough.
Three Ways a GPU-Accelerated Kernel Runs Out of Road
NVIDIA’s own CUDA optimisation guidance (Peng Wang, NVIDIA) sorts kernel limits into three types, each with its own remedy: memory bandwidth bound calls for memory optimisation, instruction throughput bound calls for instruction optimisation, and latency bound calls for configuration optimisation. Horace He’s framing from the deep learning side gives a parallel split into compute, memory and overhead, where overhead covers everything that is neither arithmetic nor moving tensors, such as Python interpreter time, framework dispatch and kernel launch cost. The practical point both make is the same: knowing the regime narrows down the optimisations that matter. Buying more FLOPS does nothing for a bandwidth-bound workload, and rewriting model logic in C++ does nothing for one dominated by large matmuls.
| Regime | How it shows in a profile | What tends to help | What will not help |
|---|---|---|---|
| Memory-bandwidth bound | Effective bandwidth near the device limit, compute well below peak | Fewer bytes moved: coalescing, shared-memory reuse, operator fusion | More compute |
| Compute (instruction) bound | Achieved FLOPS near peak, memory utilisation falling | Cheaper instructions, Tensor Cores, less divergence | Reducing launch overhead |
| Latency bound | Both memory and instruction throughput far from peak | More active warps, more instruction-level parallelism per thread | - |
| Overhead bound | GPU timeline gaps while the CPU dispatches; runtime barely grows with batch size | Tracing, operator fusion, CUDA Graphs | - |
Latency deserves its own word. Wang’s guidance defines a latency-bound kernel as one where neither memory nor instruction throughput is near peak, and the remedy is more concurrency, either by adjusting resource use to keep more warps active or by raising instruction-level parallelism in each thread.
How Do I Tell Whether My GPU Workload Is Limited by Its Algorithm or by Its Kernels?
Place each hot kernel on a roofline, then compare its arithmetic intensity with the machine’s ridge point. The Roofline model from Williams, Waterman and Patterson (Berkeley, 2008) bounds performance as attainable FLOP/s = min(peak compute, peak memory bandwidth × operational intensity), where operational intensity is operations per byte of DRAM traffic. The ridge point, where the sloped bandwidth roof meets the flat compute roof, is the minimum intensity a kernel needs to reach full compute performance.
In the original paper, operational intensity decides the optimisation region: a kernel in the low-intensity zone gets memory optimisations, one in the high-intensity zone gets computational ones, and a kernel in the overlap gets both. The same paper describes a practitioner using working-set size and intensity to decide whether an option-pricing solver needed algorithmic change at all: the implicit PDE formulation fitted in L1 and needed nothing, while the explicit formulation’s working set was too large and needed cache blocking to reach peak.
The read-out follows directly. If a kernel sits clearly on the sloped bandwidth roof, its memory access patterns are the most important thing to look at. If the kernel is far from both memory and instruction throughput peaks, it is latency bound, and the remedy is more concurrency. The CUDA C++ Best Practices Guide (NVIDIA, version 13.4) puts the test in bandwidth terms: when effective bandwidth is much lower than theoretical, design or implementation details are costing you, and raising it should be the next goal. Wang’s guidance treats 70-80% of theoretical bandwidth as very good.
The Berkeley authors also found how far real kernels sit from the ridge: on the two x86 machines they studied the ridge points were 4.4 and 6.7, while the 16 kernel-machine combinations ranged from 0.25 to 1.64 FLOP per byte, with a median of 0.60.
Worked Example: A V100 Kernel Just Under Machine Balance
The GPP kernel from a materials science code (studied by NERSC and NVIDIA on a V100) shows restructuring and tuning in sequence, analysed with the hierarchical roofline and Nsight Compute.
Starting point. Nsight Compute placed the kernel at 7.39 FLOP/byte against a double-precision machine balance of 7.5 FLOP/byte for the V100, just on the memory-bound side of the ridge. (The companion paper quotes the HBM-level balance as 7.4 FLOP/byte; the two sources round differently, and the kernel is below either figure.) That is about 98.5% of the balance point (7.39 ÷ 7.5).
Restructuring step. The loop nest exposed three parallel loops, and any two of them provided enough parallelism to fill the GPU, so the team collapsed only two and ran the third sequentially in each thread, increasing data reuse for some arrays. They chose which loop to serialise by looking at memory access strides, since coalesced access needs consecutive threads to touch consecutive addresses.
What the numbers did. Runtime got 10% worse, from 1.74 s to 1.92 s, but intensity rose to around 20 FLOP/byte and memory utilisation in the Speed of Light section fell from 34% to 11%. The kernel was now firmly compute-bound, which meant compute-side tuning finally had room to pay off.
Tuning step. Replacing high-latency complex divisions with reciprocals and swapping some absolute-value calculations raised throughput from 2.5 to 2.9 TFLOP/s and made the code run twice as fast overall; intensity dropped back to 6.3 FLOP/byte because faster compute pulls in more data. Later, at 184 registers per thread, occupancy was down to 8 active warps per SM, and capping registers doubled that to 16 warps despite causing register spills, a trade that paid off for this kernel.
End state. The companion eight-step paper reports that across eight steps the kernel went from 2.3 to 3.7 TFLOP/s, which is 55% of the theoretical 6.7 TFLOP/s peak and 70% of a customised 5.3 TFLOP/s ceiling based on its 58% FMA ratio.
Two lessons carry over. A restructuring step can look like a regression on the stopwatch and still be the right move, because its job was to change which roof applies. And once the kernel had crossed the ridge, the remaining work really was kernel tuning: instructions, registers, occupancy.
Near the Bandwidth Limit, Only Moving Less Data Helps
Roofline analysis in the Jasper paper, GPU-Accelerated ANNS: Quantized for Speed, Built for Change, found state-of-the-art approximate nearest-neighbour search (ANNS) kernels already memory-bound and running close to optimal throughput. Each vector dimension is read once, used in one multiply-add and discarded: a 128-dimensional float32 vector costs 256 floating-point operations for 512 bytes loaded, so there is no reuse to exploit. Jasper’s own kernels clustered at 0.7-0.95 FLOP/byte, tracking the sloped bandwidth roof.
The step that moved the kernel was quantisation, which reduced memory traffic. Switching to RaBitQ quantisation, which needs only sequential access, simple arithmetic and no lookup tables, raised operational intensity to 5.0-6.2 FLOP/byte and achieved performance to as much as 1.83 TFLOP/s, against roughly 0.89-1.14 TFLOP/s for the unquantised version on the DEEP dataset. The authors conclude that future gains for these kernels will mainly come from reducing data movement.
The same paper also contains the counter-case. For small beam widths, where search is limited by memory latency, a chunked loading scheme that spreads 16-byte loads across a warp’s threads gave up to a 14% speedup; at large beam widths it made no measurable difference. One workload, two regimes, two different right answers. Transformer training points the same way: Ivanov et al. (2020) found training memory-bound and reported a 1.30x gain on a BERT encoder layer from cutting data movement by up to 22.91%.
Is FlashAttention an Algorithmic Restructuring or a Kernel Optimisation?
FlashAttention is an algorithmic restructuring, and FlashAttention-2 builds on it with better work partitioning and fewer non-matmul FLOPs. Dao et al. (2022) describe FlashAttention as an IO-aware exact attention algorithm that uses tiling to reduce reads and writes between GPU HBM and on-chip SRAM, and they show it needs fewer HBM accesses than standard attention, optimal across a range of SRAM sizes. The result was a changed memory footprint, linear rather than quadratic in sequence length, with reported speedups including 3x on GPT-2 at sequence length 1K.
FlashAttention-2 (Dao, 2023) starts from the observation that the original reached only 25-40% of theoretical peak FLOP/s, and attributes this to poor work partitioning between thread blocks and warps, which caused low occupancy or unnecessary shared-memory traffic. Its fixes (fewer non-matmul FLOPs, parallelising a single head across thread blocks, better splitting of work between warps) gave around 2x over FlashAttention and 50-73% of peak on A100.
FlashAttention’s HBM savings came from tiling that changes how attention reads and writes memory, a change to the algorithm itself. FlashAttention-2 attributes the original’s remaining gap to work partitioning that caused low occupancy or unnecessary shared-memory traffic. The same order as the V100 example: restructure to change the roof, then tune to approach it.
When Is Kernel Fusion or CUDA Graphs Enough?
Fusion and CUDA Graphs are enough when the measured problem is launch overhead or intermediate round-trips through global memory.
CUDA Graphs address launch cost, not memory traffic. In NVIDIA’s V100 test, a 2.9 µs kernel cost 9.6 µs per launch with per-kernel synchronisation, 3.8 µs with overlapped launches and 3.4 µs as a captured graph. The PyTorch team recommends graphs when part of a network is graph-safe (usually static shapes and static control flow) and its runtime is at least partly CPU-limited, which is typical of small batches where fixed CPU dispatch cost exceeds GPU run time. A graph also has to be replayed often enough to recover its initialisation cost. The quick overhead test from Horace He: double the batch size, and if runtime rises by only about 10%, overhead is probably the limit.
Graphs do not reduce memory traffic. The Fused Kernel Library authors (2025) note that CUDA Graphs still launch the individual kernels one after another, producing the same DRAM reads and writes as before, and that graphs only help where there is room for horizontal fusion. Fusion goes further: it combines operations into one kernel so intermediates stay in registers rather than round-tripping through global memory. NVIDIA reports a 3x speedup on an RTX 4090 from manually fusing a two-kernel transform and reduction, cutting traffic from 3 GiB to 1 GiB. Compiler fusion through torch.compile reached the same traffic but with a strategy the authors would not have chosen, and they warn that a change of dtype or shape can silently change which kernels get fused.
Fusion has a limit of its own. In the UCNS3D CFD port, larger fused kernels cut launch overhead but raised register use, caused spills and reduced occupancy, so the team deliberately limited fusion where a kernel would carry too many local arrays. If you fuse, check registers and occupancy in Nsight Compute afterwards rather than assuming the merge was free. And once a fused kernel is already near the bandwidth roof on data it cannot avoid reading, as in the ANNS case, the next gain is expected to come mainly from moving less data, as quantisation did there. Our piece on performance tuning for AI inference goes into the deployment side.
Why Profile a GPU-Accelerated Workload Before Choosing a Fix?
Because the bottleneck, which only measurement reveals, determines the appropriate way of speeding up the workload. The CUDA Best Practices Guide makes profiling for hotspots a high-priority step and says the most important consideration is a realistic workload, so that decisions drawn from it apply to real data. At small batch sizes CPU overhead can exceed GPU run time, while at large batch sizes it is negligible.
The order of tools matters too. NVIDIA’s Nsight guidance is to use Nsight Systems first, fixing CPU-side gaps until the GPU is the bottleneck, and only then to use Nsight Compute to examine individual kernels. Nsight Compute isolates individual kernels for deep-dive analysis, including roofline placement and Speed of Light utilisation, but takes longer to run. The Best Practices Guide places instruction-level optimisation after all higher-level optimisations, which matches the restructure-then-tune order above.
For the mechanics of reading the profile, the guide to profiling GPU kernels to find the real bottleneck covers metrics and tool walkthroughs this article leaves out, and the broader profiling-first approach to improving GPU performance places this decision in an overall workflow.
Peak Ratios Mislead on Irregular Code
For irregular kernels like those in UCNS3D, comparing your speedup with the ratio of GPU to CPU peak specifications is the wrong yardstick. The UCNS3D authors (2026) report 2.71-4.05x node-level speedup and warn explicitly against comparing it with the roughly 60-70x ratio of theoretical hardware peaks, since peak FP64 assumes regular vector work and peak HBM assumes contiguous, coalesced streaming, and neither describes indirect stencil gathers with branch divergence and register pressure.
That project also shows why a collection of isolated directive-based GPU offloads was not enough. The decisive changes were keeping data resident on the device, replacing derived-type access with flat arrays, making temporary storage explicit at compile time and communicating halo data directly from device buffers. The authors describe the port as a full run-time transformation rather than a kernel-by-kernel annotation exercise, and the same restructuring sped up the CPU build as well (1.27-1.33x for one case).
An older example in a different field: a GPU voxel-reconstruction pipeline gained from merging two full traversals of an 8.6 MB array into one, because the extra global-memory pass cost far more on the GPU than on the CPU, and the final GPU version ran about 399x faster than the original single-threaded CPU code and 44x faster than a four-core TBB version. Those multiples compare against CPU baselines rather than against a tuned-only GPU variant, so they show that structure matters, not how much restructuring beat tuning.
Asking What Is Computed Before Asking How
TechnoLynx’s position is that calculating the same thing the same way is often too strong a constraint, and that the largest gains are frequently algorithmic: restructuring what is computed, not only how. That is why TechnoLynx asks a lot of questions about a workload before touching code, and weighs the effort of a restructuring against the outcome it can realistically deliver. A kernel’s operational intensity on the roofline tells you whether to try memory optimisations, computational ones or both.
The question that stays open for any given workload is how much freedom you have to change the computation itself: whether quantisation, a different tiling, a merged traversal or a reformulated solver is acceptable to the people who own correctness. That is a conversation about the problem, not the hardware, and it is where TechnoLynx’s GPU performance engineering work starts.