What an Inference Engine Is, and How It Shapes the Port Decision

An inference engine is model compute, runtime and host glue. Learn how to attribute latency to one layer before choosing C++, CUDA or WASM as a port…

What an Inference Engine Is, and How It Shapes the Port Decision
Written by TechnoLynx Published on 12 Jun 2026

In machine learning, an inference engine is the software that takes a trained model and its inputs and produces predictions. We treat it as three layers: the model’s compute kernels, the runtime that schedules those kernels on hardware, and the host glue that brings requests in and sends results out. Some production engines separate the runtime from the serving layer. Modular’s MAX, for example, pairs an engine (an inference library and runtime) with a separate serving layer that exposes REST endpoints. Before you port, you need to know which of the three layers owns your latency. Rewriting the Python around an engine only helps if the time is actually spent in that Python.

How Does an Inference Engine Work, and What Does That Mean in Practice?

Host code handles the request, tokenises the input and prepares the arguments for the kernels. The runtime decides which nodes run on which device and launches the kernels. The kernels do the arithmetic, and the host formats the output and returns it. Deep learning frameworks dispatch work asynchronously to the accelerator, but CPU operations such as kernel launch, graph construction, control flow and device synchronisation add a fixed cost.

So “the inference engine is slow” is not yet a diagnosis.

The term also has an older meaning, from expert systems. In classical AI, an inference engine is the component of an expert system that applies logical rules to a knowledge base to deduce new facts, working by forward or backward chaining. This article uses the machine-learning meaning throughout.

What Are the Layers of an Inference Engine, and What Does Each One Own?

Model compute is the kernels themselves: matrix multiplications, attention and elementwise operations. When latency depends on how these kernels execute and how data moves, the workload is compute-bound. Its speed then comes down to operation type, kernel size and the device’s throughput.

The runtime turns a graph into launched work. It partitions the graph, selects and fuses kernels, and caches compiled engines. ONNX Runtime’s execution providers are a clear example: through a GetCapability() interface, nodes or subgraphs go to providers such as CUDA or the CPU, in priority order with fallback. Deferred and static frameworks compile the graph to fuse operations, which cuts kernel launches. When CPU work such as kernel dispatch holds up GPU execution, the model is framework-bound. In that regime, latency stays constant whatever the batch size or the number of MACs.

Host glue is everything on the CPU that is not the model: HTTP handling, request validation, tokenisation, scheduling, input preparation, detokenisation and response streaming.

Layer What it owns Signature when it is the bottleneck Fixes that reach it
Model compute Kernel arithmetic and data movement on the device Latency grows with batch size or FLOPs Better kernels, lower precision, faster GPUs
Runtime Graph partitioning, kernel selection, launch, fusion, compiled-engine caching Latency flat across batch sizes, many small kernels, GPU idle between launches, slow first run for a new shape Graph compilation, CUDA Graphs, operator fusion, a different execution provider
Host glue Request handling, tokenisation, scheduling, I/O, output formatting CPU saturated while the GPU waits Process separation, more CPU cores, moving glue out of the interpreter, a host-language port

The flat-latency signature in the runtime row is the framework-tax finding; the CPU-saturation pattern comes from a 2026 characterisation of multi-GPU serving.

A Black-Box Engine Hides Where a Port Would Land

Treated as one opaque box, the engine is assumed compute-bound, as NLP inference long was. Measurements show otherwise. One study named this the “framework tax”: at small batch sizes and sequence lengths, fixed framework overhead dominates inference time. In that regime, MACs and parameter counts are poor predictors of latency.

PyTorch with CUDA Graphs took 2.82 ms, ONNX Runtime with ahead-of-time compilation 2.56 ms, and ONNX Runtime with CUDA Graphs 2.11 ms. Those runs differ in framework, graph compilation and kernel serialisation. At batch size 1, TorchScript and ONNX Runtime gave average FP16 speedups of 34.16% and 71.38% over PyTorch.

For GPU performance engineering, faster hardware makes the problem worse, not better. Kernels finish sooner while the CPU dispatch overhead stays the same, so in the study the RTX 3090 and A100 stayed framework-bound at larger batch sizes. The authors found single-example BERT inference slower on an A100 than on a V100, even though the A100 has 2.75 times the peak computational throughput. Peak throughput does not predict latency in that regime, and the page on what CPU GFLOPS means and why it never decides hardware explains why.

Launch cost has a concrete size. NVIDIA’s TensorRT-RTX documentation says most CUDA kernels take the CPU and driver around 5 to 15 microseconds to launch. When kernels run for only a few microseconds each, the workload becomes enqueue-bound. A write-up on CUDA Graphs shows the effect on a model with a ResNet backbone. Only the backbone was graphed, and the overall speedup was about 1.7x.

For the port decision, host-code rewrites miss compute-bound models, whose latency is set by the kernels. If the model is enqueue-bound, a runtime change such as CUDA Graphs or a static runtime may get you further than a language change, and you would not have to rewrite anything. Engine-level evidence in the other direction exists too. The vLLM team reports that its V1 engine reached up to 1.7x the throughput of V0 with nearly identical kernels, and puts the difference down to lower CPU overhead.

How Do You Tell Which Layer Owns the Latency in Your Inference Path?

Profile the host and the device separately, then split server-side latency into its parts before you change any code. A full walkthrough is in how to profile a Python inference path before committing to a port. We would run this sequence:

  1. Separate CPU time from kernel time. The PyTorch profiler records ProfilerActivity.CPU (operators, TorchScript functions, user-labelled code) and ProfilerActivity.CUDA (on-device kernels) as separate activities. Read self CPU time as well as total CPU time, because self time leaves out child operator calls.
  2. Split server latency into queue, compute and overhead. NVIDIA’s Triton perf_analyzer breaks server latency into queue time (waiting for a model instance), compute time (inference, including copies to and from the GPU) and overhead (endpoint time the send and receive timing cannot capture).
  3. Sweep the batch size. If latency stays flat as the batch grows, the model is framework-bound. If latency grows with the batch, it is compute-bound.
  4. Look for GPU idle gaps between kernels. At small batch sizes, CPU metadata processing can take longer than the GPU run time, and the GPU sits idle between kernel calls.
  5. Keep one-time costs out of steady-state numbers. In one 2021 compiler study, building a TensorRT engine per subgraph took 8 to 62 seconds per kernel on a Jetson Xavier. Once cached, it did not affect inference latency.
  6. For LLMs, measure TTFT and time between tokens as well as end-to-end latency. The reason is in the next section.

At the end of this, you should know what share of your latency the engine’s compute owns and what share the glue owns. You should also know whether steady-state behaviour differs from first-run behaviour. That share is what a port could save at most. Without it, a port estimate is a guess about a layer nobody measured.

What Is the Difference Between an Inference Engine and an LLM, and Does It Change Where the Bottleneck Lives?

An LLM is the model: weights plus an architecture. An LLM inference engine is the software that runs it, such as vLLM, TensorRT-LLM, llama.cpp or SGLang. A survey of these engines notes that general-purpose frameworks like PyTorch and TensorFlow are built for broad compatibility and lack optimisations specific to LLMs and sequential decoding. Dedicated engines add batching, streaming and attention optimisations. The vLLM V1 release shows the split clearly: it re-architected the scheduler, KV cache manager, worker, sampler and API server, but kept the V0 model implementations and GPU kernels.

The distinction does change where the bottleneck sits, because LLM inference runs in two phases with different costs. Prefill processes the prompt and produces the first token. Decode then generates the remaining tokens one at a time. Prefill is compute-bound and decode is memory-bandwidth-bound, because decode keeps reading the KV cache. One characterisation on vLLM v0.9.2 measured this. Prefill showed higher SM utilisation, while decode showed higher memory bandwidth utilisation.

Which phase dominates depends on input token count. For Qwen2.5-7B with 128 output tokens, decode accounted for most of the latency on short inputs, and prefill took over at around 2k input tokens. The two phases also map onto different user-facing metrics: prefill sets time to first token (TTFT) and decode sets time between tokens (TBT). When long prompts repeat a shared prefix, a radix cache that reuses prefix computation attacks prefill directly.

Within compute, then, the phase tells you whether you face a compute-throughput or a memory-bandwidth bottleneck. Neither one is a host-language problem.

How Do LLM Inference Engines Differ from Classic Model-Serving Runtimes When You Attribute Latency to Compute Versus Host Glue?

The engine survey contrasts LLM inference with CNNs on high-performance kernels and large batch sizes. The same survey argues that LLM inference, unlike CNN inference, cannot rely on those alone. It needs engine-level methods such as phase-separated batching and scheduling. Under continuous batching, the host makes a new scheduling decision at every decode step.

A 2025 review of LLM serving evaluation cites work showing that CPU overheads can account for more than 50% of latency. The vLLM team wrote that the engine’s CPU components “take a surprisingly long time”, because most of vLLM is Python built on native lists and dicts. The team also found that when the API server and the engine ran in one process, they competed for the Python GIL. Its fixes targeted CPU overhead. Multi-step scheduling raised Llama 70B throughput on 4xH100 by 28%, and an object cache for Python allocations raised end-to-end throughput by 24%. With GPU execution for Llama-8B on an H100 as low as about 5 ms, these CPU tasks become a large share of each step.

Tokenisation is one of these host tasks. A 2026 study on vLLM V1 found tokenisation took up to 50% of total latency in long-sequence configurations, even with CUDA Graphs, chunked prefill and torch.compile enabled. Removing CPU scarcity improved long-sequence TTFT by 1.36 to 5.40 times on 4 to 8 GPUs.

Two attribution rules follow for LLM engines. First, measure TTFT and TBT separately, because host delays raise TTFT and scheduling repeats at every decode step. Second, check CPU provisioning before blaming the kernels or the language. NVIDIA’s guide to LLM benchmarking notes that TTFT includes request queueing and network latency as well as prefill. For agents that call tools between model turns, the page on agentic AI benchmarks and where latency lives breaks down where latency sits. Classic engines have their own distribution of latency too, and DLRM inference latency is a non-LLM case worth comparing.

How Does the Inference Engine Relate to the Runtime Targets a Port Would Aim At?

We read each port target, whether C++, CUDA or WebAssembly, as replacing one or more of the engine’s layers. What it gains depends on which layer it replaces and whether that layer was the bottleneck.

C++ for the host. The PyText paper compared Python and C++ models on an intent-slot detection task. JointBLSTM’s P50 latency dropped from 34.08 ms in PyTorch to 19.65 ms when exported to Caffe2. RNNG moved only from 19.74 ms to 18.73 ms with the PyTorch C++ API. The authors called the first a significant boost and the second a slight one. The same team’s C++ moves gave very different gains on the two models. When porting Python inference to C++ or WASM earns its engineering cost turns that variance into a decision.

CUDA and compiled runtimes for the runtime layer. CUDA Graphs or an ahead-of-time runtime cut launch overhead without changing the host language. The framework-tax authors recommend static or ahead-of-time runtimes at small batch sizes. Partitioning still applies: offloading a region to an accelerator adds data transfer and kernel invocation overhead, so regions without heavy computation should stay on the host. For compiler-driven accelerator targets, MLIR-AIE for AMD AI Engines is one example.

WebAssembly and WebGPU for the browser. Here the port starts with a measured slowdown. Jangda and colleagues (USENIX ATC 2019) found that SPEC CPU applications compiled to WebAssembly ran on average 45% (Firefox) to 55% (Chrome) slower than native. On the GPU side, a cross-vendor study measured WebGPU’s per-dispatch cost at 24 to 36 microseconds on Vulkan, against about 7.4 microseconds for CUDA launch. Including Python and framework code, the total per-operation overhead was about 95 microseconds. Kernel fusion cut Vulkan dispatches from 876 to 564 and raised throughput by 53%, while fusion brought no benefit on CUDA. WebLLM, which pairs WASM-compiled C++ subsystems with compiled WebGPU kernels, kept up to about 80% of native MLC-LLM decoding throughput on an M3 Max. The same WebGPU study concludes that WebGPU inference suits latency-tolerant, portability-critical or privacy-sensitive workloads, not latency-critical serving where CUDA is available.

A host-language port pays off only when host glue owns the time. A runtime-level change, the subject of porting AI inference at the runtime and hardware level, pays off when launch and dispatch own the time. A browser target trades speed for reach. The page on when a port moves cost without moving the bottleneck covers that failure mode. Measure the layer split before the first line of C++ is written.

FAQ

Is Ollama an Inference Engine?

Yes. Ollama is a Go-based engine for running LLMs locally. It is built as a client and a server: the server contains an HTTP layer and a llama.cpp backend that loads the model and handles requests. To measure one locally, see the guide to running an Ollama benchmark.

What Are the Two Main Types of Inference Engines?

In the classical rule-based sense, inference engines work by forward chaining (from known facts to new ones) or backward chaining. In machine learning, the 2025 engine survey separates serving-oriented engines such as vLLM and TensorRT-LLM from lightweight engines for personal devices such as llama.cpp and Ollama.

What Does KV Cache Help Optimise During LLM Inference?

The KV cache stores the context computed during prefill so that each decode step only computes the newest token instead of repeating work. Decode is memory-bound because of the memory access its KV cache requires.