Computer Architecture • AI Systems Engineering • 4 min read

GPU Compute, Latency, and Throughput

Two AI services can run the same model on the same GPU yet give very different user experiences. One replies quickly to single requests; the other serves many requests per second but makes individuals wait longer. To design reliable AI services, distinguish compute capacity, memory capacity, latency, and throughput.

1. Why GPUs help AI workloads

Many neural-network operations involve large numbers of parallel multiply-and-accumulate operations. GPUs are built to execute many numerical operations concurrently, making them suitable for matrix multiplication and tensor operations.

A GPU is not automatically faster for every task. Small workloads, unsupported operations, memory copies, and scheduling overhead can outweigh parallel-compute benefits. CPUs remain important for preprocessing, orchestration, data transfer, and small models.

2. GPU memory is not the same as compute speed

Model weights occupy device memory, but inference also needs activations, temporary buffers, framework overhead, and sometimes a key-value (KV) cache for generated sequences.

As a first approximation, raw weight storage is:

Weight bytes≈parameter count×bytes per parameter\text{Weight bytes} \approx \text{parameter count} \times \text{bytes per parameter}

A 1-billion-parameter model using 2 bytes per parameter requires roughly 2 GB of raw weight storage (decimal units), before runtime buffers and caches. This approximation does not give the total memory needed to serve the model.

3. Latency and throughput are different

Latency is the time one request takes to complete, often measured in milliseconds or seconds. Throughput is the amount of completed work per unit time, such as requests per second or generated tokens per second.

A system can increase throughput by processing requests in batches, but users may wait for batching and queues. For interactive applications, track percentile latency, not only average latency.

Worked numerical example

If a service completes 240 requests over 60 seconds, its measured throughput is:

240 requests60 seconds=4 requests/second\frac{240\ \text{requests}}{60\ \text{seconds}} = 4\ \text{requests/second}

That alone does not reveal whether individual requests took 0.2 seconds or 8 seconds. Those latencies depend on concurrent requests, processing, and queueing.

4. Prompt processing versus token generation

Autoregressive language-model inference often has a prefill phase that processes the prompt and a decode phase that generates new tokens sequentially. Their compute and memory behavior differs. Systems may therefore track time to first token separately from time per output token.

Long contexts can increase KV-cache memory consumption. Running several users simultaneously introduces scheduling decisions: batching helps GPU utilization, while large batches or long sequences can raise memory demands.

5. Bottlenecks to recognize

BottleneckSymptomsPotential action
Compute-bound kernelsHigh arithmetic utilizationOptimize kernels or hardware choice
Memory bandwidthData transfer limits executionImprove access patterns or reduce precision
Device memoryOut-of-memory errorsReduce batch/context, quantize, shard where supported
CPU preprocessingGPU sits idle waitingProfile and parallelize preprocessing
Network or storageDelayed data/model loadingCache and improve transfer paths
Queueingp95 latency grows with trafficAdd capacity, enforce concurrency limits

Do not optimize based on intuition alone. Instrument each stage to identify where time and memory go.

6. A simple benchmark skeleton

from time import perf_counter

# Replace with a real model function and warm up first.
def model_call(x):
    return sum(v * v for v in x)

inputs = [list(range(1000)) for _ in range(100)]
start = perf_counter()
for sample in inputs:
    model_call(sample)
elapsed = perf_counter() - start
print('requests per second:', len(inputs) / elapsed)

This is a CPU timing demonstration, not a GPU benchmark. For GPU measurements, synchronize asynchronous device operations when appropriate and use framework-specific profilers.

7. Capacity planning and service quality

Choose expected input/output lengths, concurrent users, target p95 latency, and maximum cost. Run load tests with realistic traffic, then add safety margins for bursts and service failures. Recheck performance after model, runtime, and hardware changes.

References

Related articles in

Image preview

Fit