How to Profile a GPU: From System Timeline to Kernel Analysis
GPU profiling observes a representative workload to find which stage limits total execution time and then narrow down why. First measure the application as a whole, inspect the relationship among CPU preparation, transfers, waits, and GPU kernels on a system timeline, and then collect detailed metrics only for kernels that matter. This guide uses NVIDIA CUDA tools; other GPU vendors use different tools and metrics. Do not treat one profiler time or utilization value as user-visible performance: after a change, verify end-to-end latency or throughput with the profiler turned off.
How to Profile a GPU: From System Timeline to Kernel Analysis
GPU profiling observes a representative workload to find which stage limits total execution time and then narrow down why. First measure the application as a whole, inspect the relationship among CPU preparation, transfers, waits, and GPU kernels on a system timeline, and then collect detailed metrics only for kernels that matter. This guide uses NVIDIA CUDA tools; other GPU vendors use different tools and metrics. Do not treat one profiler time or utilization value as user-visible performance: after a change, verify end-to-end latency or throughput with the profiler turned off.
Find the long stage in the whole run first
A program that uses a GPU can feel slow for several reasons besides the kernel itself. CPU code may take too long to read or preprocess inputs; the CPU may submit work too slowly; transfers or synchronization may fail to overlap with computation; or a particular kernel’s compute or memory path may be limiting progress. The first profiling question is not “How do I keep the GPU busier?” It is “Where does a realistic user workload spend its time?”
NVIDIA’s CUDA Best Practices Guide recommends using a realistic workload to find the functions that consume most of an application’s time and choose optimization candidates. A small synthetic input or one kernel duration may suggest a different bottleneck from the one in deployment. A profiler provides evidence for a hypothesis; one metric does not automatically prove a cause. NVIDIA CUDA C++ Best Practices Guide: Application Profiling
A system timeline and kernel analysis answer different questions
Nsight Systems, a system-level profiler, places CPU-thread CUDA API calls, copies, synchronization, GPU kernels, and execution streams on a timeline. It helps answer questions such as: “What is the CPU doing while the GPU is idle?”, “Do transfers overlap with computation?”, and “In which application phase do long kernels occur?” Nsight Compute, a kernel-level profiler, collects more detailed metrics for a selected CUDA kernel, including memory activity, compute pipelines, scheduling, and resources. A practical sequence is to find an important phase on the timeline, then select the kernel whose behavior needs closer explanation. NVIDIA Nsight Systems User Guide NVIDIA Nsight Compute User Guide
| Signal in a timeline or report | First question to ask | What to inspect next |
|---|---|---|
| Repeated gaps appear on the GPU timeline after CPU work. | Is input preparation, thread scheduling, synchronization, or submission delaying GPU work? | Inspect the relevant CPU thread and CUDA API around the gap, along with application-phase timings. |
| Copies and kernels run back to back without overlapping. | Is a required synchronization blocking overlap, or do stream and buffer choices prevent it? | Check copy start/completion, synchronization calls, and stream dependencies. |
| One or two kernels occupy much of the device execution interval. | Which path inside those kernels limits progress? | Use Nsight Compute on the selected kernel and representative execution. |
| GPU utilization looks high but the application remains slow. | Is the right work being measured, and is a resource busy doing useful work? | Consider end-to-end latency, useful throughput, transferred bytes, and selected-kernel pipeline metrics together. |
Check the denominator before interpreting report percentages. For example, a Nsight Systems summary of API calls, kernels, and memory operations may calculate shares from the listed entries, not from application wall time. API time, GPU queue waiting, and kernel execution are also different intervals and may overlap. A visible wait interval is not automatically wasted time. NVIDIA Nsight Systems Post-Collection Analysis Guide
Fix the workload and measurement conditions first
You need a runnable application, reproducible inputs and a way to validate outputs, plus Nsight Systems and Nsight Compute installations that support the target GPU. The steps and command below target NVIDIA CUDA applications. CLI options, operating-system support, and hardware counters vary by release, so check the installed nsys and ncu versions and the support documentation for the target GPU. NVIDIA’s documentation was checked on 2026-11-23.
Keep input size, data type, application phase, warm-up count, and repetition count consistent between the baseline and profiled runs. Record the driver, CUDA and framework versions, GPU model, power and temperature conditions, and other GPU processes. Changing the final synchronization point changes which asynchronous work is included, so measure whole-application time between the start and completion boundaries that matter to users. If you cannot reproduce representative inputs, document that limitation and do not present the result as deployment performance.
Start with a short, representative capture
On a Linux shell, this basic example captures the CUDA timeline of an application. Replace ./app and its arguments with the executable and options you actually use.
nsys profile --trace=cuda,nvtx --sample=none --cpuctxsw=none -o gpu-profile ./appThis collects CUDA and NVTX traces while disabling CPU sampling and thread-scheduling collection. Available trace types and options vary by operating system and release; check nsys profile --help and the documentation for the installed version. If the full run is long or initialization obscures the result, mark the phase of interest with an NVTX range or the CUDA profiler API and collect only that region. The Nsight Systems guide explains that focusing collection on performance-critical regions reduces data volume and analysis effort. Nsight Systems User Guide: Focused Profiling
**Measure an unprofiled baseline first.** Warm up the representative input, run it several times, and record end-to-end application latency or throughput and output correctness. This is the comparison baseline.
**Find an important phase on the system timeline.** Inspect the order and overlap of CPU preparation and CUDA APIs, transfers, synchronization, and GPU kernels. When a GPU gap appears, determine whether a CPU thread, queue, or synchronization event explains it.
**Select one significant interval or kernel.** Narrow the investigation to a phase or kernel that matters to the whole run. Collecting detailed data for every kernel at once creates more data and can add overhead.
**Add only metrics relevant to that kernel.** Start with Nsight Compute’s basic report, then select sections such as memory, compute pipelines, or scheduling according to the hypothesis. Metric names and availability vary across GPU generations. Check the target-device documentation; do not substitute an unsupported metric as if it meant the same thing.
**Apply one change and measure a normal run again.** With the same inputs and start/completion boundaries, recheck correctness, whole-application time, and throughput. If repeated results vary, inspect environmental conditions and the distribution before declaring improvement from counter changes alone.
Read detailed kernel metrics with measurement overhead in mind
Nsight Compute may replay a kernel several times to collect a large set of performance metrics. Depending on the replay mode, it may save and restore memory accessed by the kernel or run the application more than once. More metrics can mean more replay passes and longer collection. For kernels with write side effects, dependencies on external state, or nondeterministic activity order, check whether replay matches normal execution. If you cannot reproduce the behavior safely, stop detailed collection and return to a smaller metric set, a system timeline, or a separate unprofiled measurement. NVIDIA Nsight Compute Profiling Guide: Replay and Overhead
The two tools’ reported kernel durations do not always share the same measurement conditions. Nsight Compute can serialize launches outside dedicated replay modes, whereas Nsight Systems observes concurrency on the system timeline. If several kernels overlap on the same GPU, the tools can report different durations. That does not by itself mean a measurement is wrong; the observation method and execution conditions differ. Do not rank raw durations across tools. Interpret each in the context of its question and use unprofiled application runs for the final performance decision. Nsight Compute Profiling Guide: Serialization and Tool Overhead
Narrow the hypothesis with an example and verify the whole result
Hypothetical image-processing example: Suppose a program reads frames, transforms them on the GPU, and saves the results, but feels slow. If the first timeline shows repeated GPU gaps between kernels while CPU preprocessing continues, raising the occupancy of a long kernel is not the first step. Investigate input preparation or submission delay. If a particular transform kernel occupies most of the GPU interval instead, inspect that kernel with Nsight Compute and compare hypotheses about memory throughput, instruction pipelines, waits, and resource use. This scenario illustrates a method; it is not a result from a particular product or experiment.
If the report is too large to find the important work, narrow the capture first. If you enabled many detailed counters at once, keep only the sections needed to test the hypothesis. When a metric is unsupported or the result is nondeterministic, choose a question the target GPU and tool version can answer. If a detailed replay run fails or changes behavior, turn off replay-heavy collection and start with a system trace and ordinary application run. Even if a report metric improves, an optimization has not met its goal unless representative unprofiled runs improve latency or throughput at the user-visible boundary.
Sources
[NVIDIA CUDA C++ Best Practices Guide: Application Profiling](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html)
[NVIDIA Nsight Systems User Guide](https://docs.nvidia.com/nsight-systems/UserGuide/index.html)
[NVIDIA Nsight Systems Post-Collection Analysis Guide](https://docs.nvidia.com/nsight-systems/AnalysisGuide/)
[NVIDIA Nsight Compute User Guide](https://docs.nvidia.com/nsight-compute/NsightCompute/)
[NVIDIA Nsight Compute Profiling Guide](https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html)