Jack Carrick's Blog


How to predict the future

Estimating execution time of CUDA kernels

November 30, 2026

Turns out predicting the future is pretty difficult… it’s what I attempted to do in the first release of GASP (GPU Analytical Speedup Predictor). GASP takes two or more CUDA “kernels”, which are basically just programs built to run on NVIDIA GPUs, and tries to predict how long each will take to run. GASP outputs the speedup ratio, or, how much faster one kernel is over another. Seems simple enough, but there’s a catch: GASP doesn’t execute the kernels at all. It guesses the total execution time in cycles statically, specifically by looking at the machine code (called SASS) from the compiled programs. But why do this at all? Well, anyone who’s worked with GPUs, especially in HPC (high performance computing) environments knows that it can take a lot of effort just to get your code scheduled. In short, a developer may wish to test code optimizations without having to wait for a program to execute or be scheduled and, in some cases, may not even have access to a given GPU during development.

So, how does GASP give an estimate? The answer is not too straightforward and requires an understanding of how GPUs work.

Background: more chefs in the kitchen

GPUs (or Graphical Processing Units) extend SIMD/SIMT (Same instruction multiple data/thread) architecture. This means they have thousands of cores that execute the same instruction on different inputs. This means they are optimized for high throughput tasks. GPUs were designed first for graphics rendering. For example, to render a video, thousands of threads (i.e. streams of instructions), are each responsible to compute the RGB value for a single pixel. This task is what GPU programmers call embarrassingly parallel, meaning that the job of one thread can execute entirely on its own. CPUs aren’t optimized for this kind of work. They have far fewer cores, but each core has far more capabilities. The kitchen / chef analogy is a common one for this comparison. Let’s say a restaurant is famous for one dish - mashed potatoes (sorry, thanksgiving was last week). The demand for the dish is enormous and they output billions of pounds a week and use many different types of potatoes. The kitchen includes thousands of chefs who do a limited number of tasks (mash, slice, boil, peel, etc.). The ingredients may change, but each chef’s task is identical. This is a GPU. The chefs are the cores and tasks are the threads. A CPU kitchen has far fewer chefs, who are more capable, but can make much more than mashed potatoes, but far slower.

Sticking to the analogy, how would you estimate how long the GPU kitchen will take to output its daily task? Well, you can’t simply just look how long they took yesterday. That would move away from pure static analysis. Rather, you can infer the total time from discrete properties of the kitchen. For example, how large are the potato staging areas between preparation areas? How long does a chef typically take to peel a single potato? What is the capacity of the total kitchen or a single counter? How many potatoes does a kitchen receive a day? etc, etc..

All of these factors come together for a prediction in total time. But this is just the beginning. Instead of just one kitchen, we must generalize to all kitchens of this type. Each GPU has different hardware characteristics and architecture, so the prediction model must be portable. Okay, enough of potatoes, let’s get back to GPUs…

GASP Prediction Pipeline

This post will provide the high-level overview of GASP and how it predicts a speedup ratio and total execution time of a kernel. You can read the full research paper I wrote here, or wait for future posts that will go into further detail.

GASP’s first version extends an analytical model of GPU execution time from Sim et al.1

\[T_{exec} = T_{memory} + T_{compute} - T_{overlap}\]

Simply put, there are two types of operations GPUs perform: computation and memory requests. The time waiting for memory loads and stores can often be hidden by computation and vice-versa. GPUs provide something called zero overhead context switching. Unlike CPUs, whose cores operate on single tasks / threads, GPUs schedule 32 threads at the same time in warps. NVIDIA GPUs have dozens of symmetric multiprocessors (SMs). Each SM has a warp scheduler (though newer GPUs have at least 4). Warps can be scheduled and descheduled within only 1 clock cycle. This is due to how each warp’s resources are managed. Briefly, each thread in a warp has its own register file that lives in one location on an SM. Instead of having to save register state, switch in new registers like in CPUs, the warp scheduler can instantly change the execution context. So, this means as soon as a warp makes a memory request, another ready warp can be run instantly. This is what we are talking about when we say latency hiding.

So, to determine if a kernel is memory-bound or compute-bound, GASP analyzes the machine-code and classifies the instruction types, and also determines how many instructions are dependent on each other. For example, two subsequent memory or compute instructions can be made concurrently if one does not depend on the other. Occupancy (i.e. how many active warps will be launched) needs to be considered, as well as caching. Modern GPUs have two cache levels (L1 and L2). L1 is local to an SM, where L2 is for all SMs on the GPU. The broad pipeline is as follows (see figure 1)

GASP Prediction Pipeline

1. Receive and consolidate user input

GASP accepts the kernel source code (valid .cu files), as well as user-supplied values for problem size and parameters. The source code is compiled and disassembled into SASS machine code. We also supply a hardware profile, which contains specifications about the target GPU from official NVIDIA spec and from microbenchmark results.

2. Parse machine code

The machine code (SASS) is parsed. Opcodes are categorized and operands are tracked. We also pull out the destination and source registers for each instruction as well as the predicates.

3. Occupancy

GASP estimates how many resident warps will be on the GPU based on the memory requirements of the kernel, as well as the number of threads within a block and number of blocks (i.e. grid size), which is indicated as a user input.

4. Memory Coalescing and Bank Conflicts

We use an external tool called Pico, which is used to estimate the degree of memory coalescing and bank conflicts. We won’t get into this too much in this post, but memory coalescing describes how contiguous parallel memory requests are across threads within a warp. The SM memory unit can coalesce multiple requests into one, given the addresses are close by. Bank conflicts describe multiple accesses to shared memory banks. Shared memory is an optimization technique for kernels to avoid long trips to GPU-wide global memory. Bank conflicts occur when multiple threads try to read/write to the same location at a given time.

5. Divergence analysis

Warps can have divergent instructions (think if...else). If threads within a warp have divergent instructions it incurs a performance penalty. GASP analyzes the degree of divergent instructions within a kernel.

6. Dependency

GASP determines the longest string of dependent instructions within a thread through a control flow graph (CFG) by looking at the source and destination registers of each instruction.

7. The analytical model

GASP extends Sim et al.’s analytical model, introducing terms for L1/L2 cache throughput limits and more specific instruction pipeline terms.

8. Caching

Estimating caching behavior is very difficult, since it is very hard to tell what data will be at a given cache layer at a given time. GASP uses a working set approach (i.e. analyses a cache hit ratio from how large the total problem size is relative to the cache sizes), but also accepts user-supplied estimates for L1 hit rate.

Putting it all together

Each kernel gets an estimated execution time in cycles. Then the speedup ratio is given as

\[S_k = \frac{T_r}{T_k}\]

GASP has been tested on 140 kernels with a median absolute speedup error of 13.2 - 17.4 percent. For comparison, Alavani et al.2 reported a mean absolute error of 26.86% across 45 benchmarks using PTX-based analysis. For simple kernels, the static analysis (i.e. dependency / instruction count) is very accurate. The analytical model that GASP adapted was targeted for older GPUs. Future versions of GASP may use newer models for execution time.

I hope to talk about each module in GASP in much more detail in future posts.


  1. J. Sim, A. Dasgupta, H. Kim, and R. Vuduc, “A performance analysis framework for identifying potential benefits in GPGPU applications,” in PPoPP’12, 2012.↩︎

  2. G. Alavani, K. Varma, and S. Sarkar, “Predicting execution time of CUDA kernel using static analysis,” in Proc. IEEE Intl. Conf. on Parallel & Distributed Processing with Applications, 2018, pp. 948–955.↩︎