Inferensys

Glossary

Cost Model for Fusion

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.
ML engineer running AI model benchmarks, performance charts on multiple screens, late night home office setup.
COMPILER OPTIMIZATION

What is Cost Model for Fusion?

A predictive model used by compilers to evaluate the performance impact of merging computational operators.

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.

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.

COST MODEL FOR FUSION

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.

01

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.
02

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.
03

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.

04

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.
05

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.
06

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 → Multiply are ideal for fusion into a single pass.
GLOSSARY

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.

IMPLEMENTATION LANDSCAPE

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.

06

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 STRATEGY ANALYSIS

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 TypePrimary Optimization TargetKey Cost Model InputsTypical Profitability CriteriaCompiler 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 torch.compile, JAX's JIT

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)

COST MODEL FOR FUSION

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.

Prasad Kumkar

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.