A cost model for fusion is a predictive, often analytical, model used by a compiler to estimate the performance benefit or penalty of fusing a specific group of operators, guiding automated fusion profitability decisions. It quantifies trade-offs between reduced kernel launch overhead, improved data locality, and potential downsides like increased register pressure or decreased parallelism to determine an optimal fusion plan.
Glossary
Cost Model for Fusion

What is Cost Model for Fusion?
A predictive model used by compilers to evaluate the performance impact of merging computational operators.
The model typically analyzes the computational graph, estimating metrics like memory bandwidth consumption, arithmetic intensity, and data reuse patterns for both fused and unfused execution paths. By simulating these costs, the compiler can make data-driven choices, avoiding memory-bound fusions that offer no gain or compute-bound fusions that could hinder parallelism, ultimately generating efficient fused kernels for targets like GPUs or NPUs.
Key Factors in a Fusion Cost Model
A cost model for fusion is a predictive model used by a compiler to estimate the performance benefit or penalty of fusing a particular group of operators, guiding fusion profitability decisions. It quantifies trade-offs between reduced overhead and increased kernel complexity.
Kernel Launch Overhead
This is the fixed latency and resource cost of submitting a kernel for execution on a GPU or accelerator. A primary goal of fusion is to amortize this overhead by reducing the total number of kernel launches. The cost model must estimate the saved overhead against the increased execution time of a larger, fused kernel.
- Quantifiable Latency: Includes driver API calls, argument marshaling, and scheduler queueing.
- Amortization Benefit: Most significant when fusing many small, rapid-fire operations.
Memory Access Patterns & Data Locality
Fusion can dramatically reduce the volume of data movement between slow global memory and fast on-chip caches (L1, L2, shared memory). The cost model analyzes the dataflow graph to estimate savings from keeping intermediate tensors resident in registers or cache.
- Intermediate Tensor Elimination: Fusing a producer and consumer operator avoids writing a full tensor to global memory and immediately reading it back.
- Cache Reuse Potential: Evaluates if fused operations can reuse data across multiple computational steps within the same kernel.
Arithmetic Intensity & Compute Bound vs. Memory Bound
This factor assesses whether the fused kernel's performance will be limited by memory bandwidth or computational throughput. Arithmetic Intensity (FLOPs per byte of DRAM access) is a key metric.
-
Memory-Bound Fusion: Profitable when fusing light, elementwise ops (e.g., ReLU, Add) with a heavy operation (e.g., Conv). The light ops become 'free' as they hide behind memory latency.
-
Compute-Bound Fusion: May be unprofitable if fusing already compute-saturated operations leads to register spilling or underutilized parallelism.
Hardware Resource Constraints
A larger, fused kernel competes for finite hardware resources. The cost model must predict constraints to avoid performance degradation.
- Register Pressure: Combining operations increases register usage per thread, which can limit active thread occupancy.
- Shared Memory Usage: Fused kernels may require more shared memory for communication between warps, reducing the number of concurrent thread blocks.
- Instruction Cache Pressure: Very large kernels may exceed the capacity of the instruction cache, causing thrashing.
Parallelism & Scheduling Flexibility
Fusion can reduce opportunities for parallel execution. The cost model evaluates the parallelizability of the fused operation group.
- Horizontal Fusion: Merging independent operators that could run in parallel may reduce overall throughput.
- Vertical Fusion: Chaining dependent operators is typically safe and beneficial.
- Loop Fusion Implications: Merging loops affects tiling, vectorization, and parallel loop scheduling strategies.
Pattern-Specific Optimizations
Certain operator sequences have known, hand-tuned fused implementations. The cost model assigns high profitability to these canonical patterns.
- Fused Conv-BN-ReLU: The standard pattern in CNNs; fusion provides massive speedup by folding batch norm parameters into the convolution weights.
- Fused Multi-Head Attention (e.g., FlashAttention): A single kernel for the entire attention mechanism, optimizing IO to achieve near-theoretical minimum memory movement.
- Elementwise Op Chains: Sequences like
Sigmoid → Log → Multiplyare ideal for fusion into a single pass.
How a Fusion Cost Model Works
A cost model for fusion is a predictive, mathematical framework used by a compiler to estimate the performance impact of merging multiple computational operators into a single, fused kernel.
The model operates by analyzing the computational graph and estimating the execution cost of both the original, separate operators and the proposed fused kernel. It quantifies key factors like kernel launch overhead, memory bandwidth consumption for intermediate tensors, arithmetic intensity, and hardware-specific constraints such as register pressure and shared memory usage. This quantitative analysis allows the compiler's fusion planner to make data-driven decisions.
The goal is to predict fusion profitability—whether the reduction in launch latency and improved data locality outweigh potential downsides like increased register spilling or reduced parallelism. Advanced models may use machine learning or profile-guided data to refine their predictions. This enables automatic, optimal fusion in compilers like XLA, TVM, and MLIR, directly reducing inference latency and GPU memory traffic.
Cost Models in Major Compilers & Frameworks
A cost model for fusion is a predictive model used by a compiler to estimate the performance benefit or penalty of fusing a particular group of operators, guiding fusion profitability decisions. Major compilers implement distinct cost models tailored to their intermediate representations and target hardware.
Common Cost Model Factors
Across all compilers, fusion cost models evaluate a core set of hardware-aware factors to determine profitability:
- Kernel Launch Overhead: Amortizing fixed per-launch latency (synchronization, driver calls).
- Memory Traffic: Reduction in reads/writes of intermediate tensors to DRAM.
- Cache Locality: Improved data reuse in L1/L2 cache or GPU shared memory.
- Register Pressure: Negative cost from increased live variables in a fused kernel, potentially reducing occupancy.
- Parallelism: Potential loss of independent parallelism from fusing independent (horizontal) ops.
- Arithmetic Intensity: Fusing a memory-bound op with a compute-bound op can better saturate compute units. The optimal balance of these factors varies by hardware architecture (CPU, GPU, TPU).
Fusion Types and Their Cost Model Considerations
A comparison of common fusion strategies, detailing their primary optimization target, key cost model inputs, typical profitability criteria, and common compiler implementations.
| Fusion Type | Primary Optimization Target | Key Cost Model Inputs | Typical Profitability Criteria | Compiler Examples |
|---|---|---|---|---|
Elementwise Fusion | Kernel launch overhead & instruction throughput | Number of operations, tensor element count, operation latency | Almost always profitable for sequential pointwise ops | XLA, Torch Inductor, TVM |
Vertical Fusion (Producer-Consumer) | Intermediate memory bandwidth | Size of intermediate tensor, memory bandwidth, compute intensity of fused block | Intermediate size > L1 cache; consumer op is memory-bound | XLA, MLIR (Linalg), TVM |
Horizontal Fusion (Parallel Ops) | Kernel launch overhead & GPU utilization | Launch latency, identical iteration space, independent operation costs | Operations have identical loop structure; combined kernel saturates GPU | XLA, specialized TVM schedulers |
Memory-Bound Fusion | DRAM bandwidth & cache locality | Memory access volume, cache hierarchy sizes, data reuse distance | Fusion reduces total DRAM traffic by >~10% | MLIR affine fusion, polyhedral compilers |
Compute-Bound Fusion | ALU utilization & arithmetic intensity | Theoretical FLOPs, operational intensity (FLOPs/byte), hardware peak FLOPs | Increases arithmetic intensity to approach hardware peak | Hand-tuned libraries (cuDNN, oneDNN) |
Pattern-Based Fusion (e.g., Conv-BN-ReLU) | Fixed-sequence overhead & latency | Known pattern latency, fixed memory access pattern, kernel launch cost | Pre-fused kernel latency < sum of individual kernel latencies | cuDNN, oneDNN, XLA pattern matcher |
Just-In-Time (JIT) Fusion | Runtime adaptability for dynamic shapes | Concrete input tensor shapes, runtime profiling data, available device memory | Profiling shows fusion gain; static fusion was not possible | PyTorch's |
Ahead-of-Time (AOT) Fusion | Predictable, minimal runtime overhead | Static graph, fixed tensor shapes (or upper bounds), target hardware specs | Fusion plan is optimal for all expected static shapes | TVM (AOT compilation), XLA (for TPU) |
Frequently Asked Questions
A cost model for fusion is a predictive model used by a compiler to estimate the performance benefit or penalty of fusing a particular group of operators, guiding fusion profitability decisions. These FAQs address how it works, its key components, and its role in modern AI compilers.
A cost model for fusion is a predictive, mathematical model used by a deep learning compiler to estimate the execution time, memory usage, or hardware utilization of a potential fused kernel before it is generated. Its primary function is to answer the fusion profitability question: will combining a specific set of operators into a single kernel yield a net performance gain compared to executing them separately? The model acts as the decision engine for a fusion planner, allowing the compiler to explore a vast search space of possible fusion groups and select an optimal or near-optimal fusion strategy. It is a core component of modern compilation stacks like XLA, TVM, and MLIR, enabling automated, hardware-aware optimization.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
A cost model for fusion operates within a broader compiler ecosystem. These related terms define the mechanisms, strategies, and tools that interact with or are guided by the cost model's predictions.
Fusion Planner
The compiler component that uses the cost model to construct an execution plan. It explores the search space of possible operator groupings, queries the cost model for estimated performance, and selects the set of fusion groups that yield the optimal or near-optimal schedule. Its effectiveness is directly dependent on the accuracy of the underlying cost model.
Fusion Profitability
The binary outcome determined by the cost model. It answers whether fusing a specific group of operators will result in a net performance gain. The analysis weighs:
- Benefits: Reduced kernel launch overhead, improved data locality, fewer global memory accesses.
- Costs: Increased register pressure, decreased parallelism, potential for resource contention. A cost model's primary job is to predict this profitability accurately.
Graph Fusion
The overall process that a cost model guides. It involves automatically identifying and merging subgraphs (fusion groups) within a computational graph. The cost model provides the quantitative rationale for which subgraphs to fuse, moving the optimization from simple pattern matching to a performance-driven search. This is a core pass in compilers like XLA, TVM, and MLIR.
Fusion Heuristics
Rule-based algorithms that often serve as a simpler alternative or a fallback to a full cost model. These are hand-crafted rules (e.g., "always fuse elementwise ops with their producer") that make fast, deterministic fusion decisions. A sophisticated system may use heuristics for common patterns and a cost model for complex, ambiguous cases where performance trade-offs are less obvious.
Kernel Launch Overhead
A primary performance metric that fusion aims to amortize. This is the latency and resource cost of submitting a single GPU kernel for execution, involving driver calls and scheduling. A key prediction of a cost model is how much this overhead can be reduced by merging N kernels into 1. For very small, memory-bound operations, launch overhead can be the dominant cost, making fusion highly profitable.
Memory-Bound vs. Compute-Bound Fusion
The two fundamental optimization targets a cost model must distinguish.
- Memory-Bound Fusion: Focuses on fusing ops to reduce data movement between slow global memory and fast caches. The cost model estimates reduced DRAM bandwidth.
- Compute-Bound Fusion: Aims to increase arithmetic intensity by combining light ops (e.g., ReLU) with heavy ones (e.g., MatMul). The cost model estimates improved FLOP utilization. The optimal strategy depends on the hardware's balance of compute and memory bandwidth.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us