To improve GPU performance in a compute or AI workload (training, inference, CUDA or ROCm code, not game frame rates), first find out what the bottleneck is. A GPU workload is limited by memory bandwidth, math throughput or latency. More GPU FLOPS will not help a memory-bound workload, and cutting framework overhead will not help a compute-bound one. So the method is: profile with Nsight Systems, torch.profiler or the ROCm tools, name the limit, change one thing, then profile again. Applying best-practice tips comes after that diagnosis, not before it.
The same order runs through NVIDIA’s own CUDA guidance. Its Best Practices Guide treats optimisation as a loop: find an opportunity, apply it, check the speedup, repeat. It describes the profiling tools as “invaluable for guiding this process”. AMD’s ROCm team says it more bluntly: it is always best not to assume you know where the bottlenecks are or why they happen.
Improving GPU Performance Starts with Which Resource Runs Out First
Horace He splits deep-learning runtime into three parts: compute (time spent on floating-point work), memory (time spent moving tensors within the GPU) and overhead (everything else). Overhead includes time in the Python interpreter, time in the framework and time spent launching CUDA kernels rather than running them. On top of these sits a fourth limit outside the GPU: the data pipeline that feeds the device.
Whether a kernel is compute-bound or memory-bound depends on its arithmetic intensity, meaning operations per byte accessed. NVIDIA compares that figure with the processor’s ops:byte ratio (math bandwidth divided by memory bandwidth). If the intensity is higher, the kernel is math-limited. If it is lower, the kernel is memory-limited. That comparison only works when the workload is big enough to saturate the hardware. With too little parallelism, latency sets the speed, and NVIDIA itself calls the calculation a first-order approximation that profiler data should replace when accuracy matters.
Telling the Four Regimes Apart
| Regime | What the profile shows | What helps | What will not help |
|---|---|---|---|
| Compute-bound | Achieved FLOPS close to peak; kernel sits in the compute region of a roofline chart | Fewer low-throughput instructions, Tensor Cores, lower precision where accuracy allows | Cutting Python or framework overhead |
| Memory-bandwidth-bound | Kernel sits under the memory-bandwidth slope of the roofline; effective bandwidth well below theoretical | Coalesced access, shared-memory reuse, fewer redundant global loads | A GPU with more FLOPS but the same bandwidth |
| Overhead-bound (launch or CPU) | Self CPU time far above self CUDA time; gaps between kernels on the GPU timeline | Bigger batches, operator fusion, CUDA graphs | Faster kernels, since the GPU is already waiting |
| Data-feed or transfer-bound | GPU idle while fetch, pre-processing or host-to-device copies run | More CPU cores for pre-processing, more DRAM cache, pinned and batched transfers | A faster GPU |
How Do I Find Out What Is Actually Limiting My GPU Workload Before I Start Optimising?
Start with a system-wide timeline before a kernel profiler. A view that correlates CPU and GPU activity shows when the GPU is idle. Nsight Systems is NVIDIA’s system-wide analysis tool for that view. Its GPU Metrics feature is built to answer questions like “Is my GPU idle? Is my GPU full? Am I using TensorCores?”. In PyTorch, the torch.profiler trace does the same job by showing CPU and GPU lanes side by side, with idle gaps visible as empty space.
- Profile a realistic workload. NVIDIA calls this the most important consideration in any profiling activity, because unrealistic problem sizes send developers to the wrong functions.
- Limit collection to the critical region. Use NVTX ranges or
cudaProfilerStart()/cudaProfilerStop(), which cut data volume and keep attention on code where optimisation pays off. - Run the scaling test. Overhead generally does not grow with problem size, so if doubling the batch raises runtime by only about 10%, the workload is probably overhead-bound.
- Check the input pipeline before the kernels. The TensorFlow Profiler guide makes “is the program input-bound?” the first step of GPU performance debugging.
- Go to the kernel level only once the GPU is busy. TensorFlow’s guide works on kernel efficiency only after utilisation is acceptable.
Classifying individual kernels as compute-limited or memory-limited is a deeper step, using Speed of Light, roofline and stall-reason data. Our guide to kernel profiling with Nsight to find the real bottleneck covers that step. The exact commands and the order to run the tools in are laid out in our GPU profiler workflow for Nsight Systems and Nsight Compute.
Why Is My GPU Utilisation Low, and Is It the CPU, Data Loading or Transfers?
Low utilisation means the GPU sits idle for part of the run. PyTorch’s Holistic Trace Analysis splits GPU idle time into host wait and kernel wait. Host wait means the CPU is not enqueuing kernels fast enough, and it is addressed by examining the slow CPU operators, increasing the batch size or fusing operators. Kernel wait means the small gaps between back-to-back launches, which CUDA graphs reduce.
A torch.profiler walkthrough shows a 1.78 ms cudaDeviceSynchronize covering 26 µs of real GPU work, meaning the run was 98% idle. The guide calls this “the textbook overhead-bound symptom”. TensorFlow puts host-side launch latency at around 20 to 40 µs before a kernel runs, so a stream of tiny kernels leaves the device waiting on the host.
Data loading is another cause in training. Mohan et al. studied nine models in a Microsoft production cluster. They found that training is often I/O-bound on fetching data or CPU-bound on pre-processing, and that either way the GPU sits idle. Their rule is simple: stalls appear whenever the GPU processes data faster than the pipeline can fetch or pre-process it. Lighter models needed as many as 12 to 24 CPU cores per GPU to mask pre-processing stalls.
Host-to-device copies are a third suspect. NVIDIA’s data-transfer guidance calls PCIe “the slowest link in GPU computing”. Its example, on older hardware (a Tesla C2050 on PCIe x16 Gen2), compares 144 GB/s device-memory bandwidth with 8 GB/s host-to-device bandwidth, a gap of about eighteen times (144 / 8). The same guidance reports that pinned host memory more than doubles transfer rates, and that batching small transfers removes per-transfer overhead. Nsight Systems GPU Metrics track PCIe throughput alongside SM activity, so heavy transfers next to an idle GPU are visible.
The opposite case also occurs: the GPU looks fully busy and is still slow. The nvidia-smi utilisation figure only records whether some kernel is running. Why that misleads, and which metrics to trust instead, is covered in our piece on misleading GPU metrics versus the ones that explain bottlenecks.
Is a Faster GPU the Answer, or Should the Workload Be Profiled First?
Profile the kernels first, not vendor specs, because the regime decides whether new hardware helps at all. Horace He puts it plainly: if a workload spends its time on memory transfers, more GPU FLOPS will not help. Mohan et al. found that as compute gets faster, data stalls “squander the benefits due to fast compute”. They concluded it may be cheaper to train some models on slower, less expensive GPUs without stalls than on faster ones left underused.
Launch overhead matters more as hardware gets faster. The PyTorch team notes that as GPUs get faster and workloads spread across more devices, launch-induced stalls become more likely. A faster card shortens each kernel, while the CPU’s per-launch cost is fixed.
A hardware upgrade is the right call when the profile shows a saturated resource that the new device actually has more of. Even then, NVIDIA warns that cache sizes, SM counts, memory bandwidth and peak FLOP rates can all change which part of a workload is the limit on a new architecture. A workload that was compute-bound before an upgrade may be bandwidth-bound after it. We make the same argument for inference in machine learning on GPU: a faster future. Faster inference comes from latency diagnosis, batching, quantisation and cost-per-inference accounting, not from the size of the GPU. For the same reason, any cost saving from a hardware or software change can only be estimated after the workload has been measured.
Which Profiling Tools Show Where Time Goes in a CUDA or ML Workload?
| Question | NVIDIA / CUDA | PyTorch | TensorFlow | AMD / ROCm |
|---|---|---|---|---|
| Is the GPU idle, and why? (timeline) | Nsight Systems | torch.profiler trace; Holistic Trace Analysis | TensorFlow Profiler trace viewer, input-pipeline analyser | rocprof-sys |
| What limits this kernel? | Nsight Compute | torch.profiler table for hotspots, then Nsight Compute | Profiler kernel stats, then Nsight Compute | rocprof-compute (Speed of Light, roofline) |
The older Visual Profiler and nvprof are deprecated and do not support devices of compute capability 8.0 and higher. NVIDIA directs users to Nsight Systems and Nsight Compute instead.
Profilers Change the Thing They Measure
Profiling adds overhead, and collecting more metrics adds more. NVIDIA’s profiler guide warns that collecting events or metrics for all kernels serialises every kernel on the GPU and so changes overall performance. The per-kernel values stay correct, so they can be merged onto a separately captured timeline. Nsight Compute may replay a kernel several times because hardware counters cannot all be read in one pass, and more metrics mean more passes.
Two Nsight Compute defaults affect comparisons. Nsight Compute locks SM clocks while Nsight Systems does not, so NVIDIA recommends locking clocks externally with nvidia-smi and running ncu with --clock-control none when comparing results. Nsight Compute also flushes GPU caches between replay passes, which can mislead for cache-sensitive workloads. The same kernel can also time differently from step to step because of clocks, thermals and power management. Read the trace, not just the mean. When comparing before and after a change, keep capture settings identical, compare the same workload scope, and use an optimised build configuration rather than a debug build.
Worked Example: CUDA Graphs on a Launch-Bound Mask R-CNN Backbone
The PyTorch team’s write-up on CUDA graphs shows a limit being fixed after it was diagnosed on a timeline. An Nsight timeline of the Mask R-CNN backbone at a per-GPU batch size of 1 showed the CPU maxed out at 100% load. The GPU was idle most of the time, with large gaps between kernels. That is the overhead-bound pattern in the table above. Faster kernels would only have widened the gaps.
CUDA graphs package a series of kernels into one unit launched by a single CPU call. Replaying the graph skips argument setup and kernel dispatch in Python, C++ and the CUDA driver. With the graph in place, the backbone ran in 6 ms instead of 31 ms, about a fivefold speedup. Mostly just the backbone was graphed, and the whole model sped up by about 1.7 times.
PyTorch’s own guidance sets the condition: try CUDA graphs when the network, or part of it, is graph-safe (usually static shapes and static control flow) and you suspect the runtime is at least somewhat CPU-limited. On a training job stalled on data loading, the same change would show little benefit, because the idle time comes from somewhere the graph never touches.
“Avoid branches” and Other Rules Only Mean Something in Context
Advice such as “avoid branches” only makes sense in context, and that context comes from profiling, not from reading blog posts. CUDA’s guidance does warn that divergent control flow within a warp serialises execution paths. But if the profile shows a kernel waiting on DRAM, rewriting its branches will not move runtime much. Nsight Compute’s own interpretation notes say the target is higher issue-slot utilisation, not driving every stall counter to zero. Cutting stalls usually speeds things up only when low issue activity makes the kernel latency-limited. The same notes point out that a memory-latency-bound kernel is not necessarily memory-bandwidth-bound, and the two call for different changes.
Occupancy shows the same problem. “Raise occupancy” is a common rule, yet NVIDIA states that higher occupancy does not always mean higher performance, even though low occupancy always weakens latency hiding. Earlier GPU performance models mispredicted observed throughput by factors of up to 1.7. Their most common limitation was underestimating the occupancy needed for maximum throughput, by a factor of up to about two. If careful analytical models miss by that much, a rule of thumb applied without measurement deserves less trust still.
The choice of vendor API follows the same logic. Vendor-specific APIs are not magically faster than standard ones: the same code performs essentially the same. Their value is access to lower-level features, and using that access takes real commitment that is not always worth it. CUDA gives the deepest optimisation path but runs only on NVIDIA GPUs, so the useful question is whether a standard API exposes enough of the hardware for the performance target. Only a profile showing that you have hit what the portable path can reach makes the case for that commitment.
After the First Fix, the Bottleneck Moves
Profiling is a loop that ends when the remaining limit is one you accept, not a single step before the real work. Mohan et al. show a bottleneck shifting directly: as the number of GPUs falls, the storage fetch rate catches up with GPU ingestion and the bottleneck moves to pre-processing. A team that profiles once, fixes the top item and stops has not checked what limits the workload next.
When the profile points at kernel design, restructuring the algorithm or writing a custom kernel can be the right next step. Our explainer on when to write your own CUDA kernel covers that decision. When it points at the pipeline, the host or the transfers, the work lies outside the kernels altogether.