Horizontal fusion combines operators that execute in parallel within a computational graph, sharing a common input but producing separate outputs. Unlike vertical fusion, which chains sequential producer-consumer operations, horizontal fusion targets independent branches. The primary goal is to reduce kernel launch overhead and improve hardware utilization by executing multiple parallel operations in a single GPU kernel launch, thereby amortizing scheduling costs and enhancing data locality.
Glossary
Horizontal Fusion

What is Horizontal Fusion?
Horizontal fusion is a compiler-level optimization technique in deep learning that merges multiple independent, parallel operators that consume the same input tensor into a single, unified computational kernel.
This optimization is particularly effective for elementwise operations (e.g., multiple parallel activations or tensor manipulations) that are memory-bound. By fusing them, the compiler minimizes global memory accesses and better saturates memory bandwidth. Compilers like XLA, TVM, and MLIR use fusion heuristics and cost models to automatically identify profitable horizontal fusion opportunities, balancing reduced overhead against potential increases in register pressure or decreased parallelism.
Key Characteristics of Horizontal Fusion
Horizontal fusion merges independent, parallel operators that share an input or operate concurrently. Its primary goal is to amortize kernel launch overhead and improve hardware utilization by executing multiple operations in a single GPU kernel launch.
Parallel Operator Merging
Horizontal fusion combines independent operators that execute in parallel within the computational graph. Unlike vertical fusion, which chains dependent producer-consumer pairs, horizontal fusion targets operations that have no data dependencies on each other but can be executed simultaneously. For example, applying separate activation functions (e.g., Sigmoid and Tanh) to different channels of the same input tensor can be fused into a single kernel that processes all channels in one pass.
Shared Input Consumption
A core enabling condition for horizontal fusion is that the operators being fused consume the same input tensor or slices of the same tensor. This shared data access pattern allows a fused kernel to load the input data once from global GPU memory, perform all parallel computations in-register or in shared memory, and then write the results. This drastically reduces the memory bandwidth pressure that would occur if each operator launched separately and redundantly loaded the same input data.
Kernel Launch Overhead Amortization
The primary performance benefit is the amortization of kernel launch overhead. Each GPU kernel launch incurs fixed latency for scheduling, argument passing, and setup. By fusing N parallel operations:
- Launch overhead is reduced from N times to 1 time.
- This is particularly impactful for lightweight, elementwise operations (e.g., pointwise activations, scaling) where the launch overhead can be a significant fraction of the total execution time.
- The fused kernel presents a larger, more substantial workload to the GPU scheduler, improving hardware occupancy and utilization.
Improved Data Locality & Cache Utilization
Horizontal fusion enhances data locality by keeping intermediate results within the GPU's fast memory hierarchy. When operators are separate, the output of one must be written to global memory (DRAM) before the next can read it. A fused kernel can:
- Keep intermediate tensors in registers or shared memory.
- Promote cache reuse across the fused operations.
- This reduces the total volume of data transferred through the memory subsystem, which is often the bottleneck for performance.
Compiler-Driven Pattern Matching
Horizontal fusion is typically performed automatically by deep learning compilers like XLA, TVM, and PyTorch's Inductor (via torch.compile). These systems use pattern matching and cost models to identify profitable fusion opportunities. The compiler:
- Analyzes the computational graph for independent operators with shared inputs.
- Estimates the performance benefit using a fusion profitability heuristic.
- Generates a single, optimized fused kernel (e.g., via CUDA or ROCm) that implements the combined logic.
Trade-offs and Limitations
Fusion is not always profitable. Key trade-offs include:
- Register Pressure: A fused kernel may require more GPU registers to hold intermediate values, potentially reducing warp occupancy.
- Control Flow Divergence: Combining unrelated operations can lead to divergent execution paths within a warp, harming performance.
- Compiler Complexity: Identifying safe and profitable horizontal fusion groups is a complex optimization problem. Over-fusing can create monolithic kernels that are difficult to optimize and may exceed hardware resource limits (e.g., shared memory).
How Horizontal Fusion Works
Horizontal fusion is a compiler optimization that merges independent, parallel operators to enhance computational efficiency.
Horizontal fusion is a graph-level compiler optimization that merges multiple independent operators that consume the same input tensor or execute in parallel within a computational graph. Unlike vertical fusion, which chains dependent operations, horizontal fusion combines sibling nodes, enabling their execution by a single, unified fused kernel. This technique primarily reduces kernel launch overhead and can improve cache utilization by processing multiple data streams concurrently within the same loop structure.
The optimization is driven by a fusion planner using a cost model for fusion to assess fusion profitability. It is particularly effective for memory-bound operations, as it amortizes memory access costs. Common targets include parallel elementwise operations (e.g., multiple independent activations). Compilers like XLA, TVM, and MLIR implement this via pattern matching for fusion and fusion-aware scheduling to generate efficient code for accelerators.
Implementation Examples
Horizontal fusion merges independent, parallel operators that share an input or execute concurrently. These examples illustrate its application across compilers and neural network architectures.
Elementwise Operator Fusion
This is the most common form of horizontal fusion, where multiple pointwise operations applied to the same tensor are combined. For example, a sequence like y = relu(x) + sigmoid(x) * tanh(x) involves three independent reads of tensor x. A fused kernel performs all three computations in a single pass:
- Single memory load for the input tensor
x. - Parallel execution of ReLU, Sigmoid, and Tanh functions on each element.
- Single memory store for the final output
y. This eliminates redundant data movement and kernel launch overhead, turning a memory-bound workload into a more compute-efficient one.
Parallel Linear Layer Fusion
In transformer blocks, the feed-forward network (FFN) often consists of two parallel linear projections (often an up-projection and a gate projection) whose outputs are combined (e.g., via SiLU activation). Naively, these are two separate matrix multiplications (GEMMs). Horizontal fusion combines them:
- Single, batched GEMM kernel that computes
W_up * xandW_gate * xsimultaneously. - Shared input
xis read once for both operations. - Fused activation like SiLU is applied elementwise to the combined results. This pattern is critical in models like LLaMA's SwiGLU FFN, significantly reducing the memory bandwidth required for the input activations.
Limitations and Trade-offs
Horizontal fusion is not always profitable. Compilers use cost models to decide when to fuse. Key trade-offs include:
- Register Pressure: Fusing many operations can increase the number of live variables, exhausting GPU registers and causing spilling to slower memory.
- Reduced Parallelism: Extremely large fused kernels may leave GPU streaming multiprocessors underutilized if they cannot hide memory latency effectively.
- Kernel Complexity: Hand-tuning fused kernels (e.g., FlashAttention) is complex, requiring expert knowledge of hardware memory hierarchies.
- Dynamic Shapes: Fusion decisions made at compile-time (AOT) may be suboptimal for runtime-varying input shapes, favoring Just-In-Time (JIT) fusion approaches.
Horizontal Fusion vs. Vertical Fusion
A comparison of two primary graph-level optimization strategies for combining computational operators to reduce kernel launch overhead and improve memory locality.
| Optimization Characteristic | Horizontal Fusion | Vertical Fusion |
|---|---|---|
Primary Relationship | Parallel / Sibling Operators | Sequential / Producer-Consumer |
Data Dependency Pattern | Operators consume the same input tensor(s) | Output of one operator is the input to the next |
Primary Performance Goal | Reduce total kernel launches for parallel work | Reduce intermediate memory reads/writes |
Typical Fused Pattern | Multiple independent elementwise ops (e.g., Sigmoid, Tanh, ReLU) on the same tensor | Conv → BatchNorm → ReLU (a linear chain) |
Impact on Kernel Launch Overhead | High reduction (N parallel ops → 1 launch) | Moderate reduction (N sequential ops → 1 launch) |
Impact on Memory Bandwidth | Moderate (single read of shared input) | High (eliminates writes/reads of intermediate tensors) |
Compiler Complexity | Lower (independent ops are easier to combine) | Higher (must respect data dependencies and potential side effects) |
Potential for Increased Register Pressure | Low to Moderate | High (multiple sequential computations in one kernel) |
Example in Frameworks | XLA fusing multiple activations on the same tensor | PyTorch's |
Frequently Asked Questions
Horizontal fusion is a compiler optimization technique for merging independent, parallel computational operations. This glossary answers common technical questions about its mechanisms, benefits, and implementation.
Horizontal fusion is a compiler optimization that merges multiple independent operators that consume the same input tensor or execute in parallel within a computational graph into a single, unified kernel. Unlike vertical fusion, which chains sequentially dependent producer-consumer operations, horizontal fusion combines operations that are siblings in the dataflow graph, operating on the same or similarly shaped data. The primary goal is to amortize kernel launch overhead, improve data locality by keeping intermediate results in fast cache or registers, and increase arithmetic intensity for better hardware utilization. This technique is a core component of modern deep learning compilers like XLA, TVM, and MLIR.
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
Horizontal fusion is one of several compiler-driven techniques for optimizing neural network execution. These related concepts define the broader landscape of graph and kernel-level optimizations.
Vertical Fusion
Vertical fusion merges a producer operator with its immediate consumer operator in the computational graph. This chains sequentially dependent operations to minimize intermediate memory writes and reads.
- Key Mechanism: Fuses operations where the output of one is the direct input to the next (e.g., a matrix multiplication followed by a bias add).
- Contrast with Horizontal: While horizontal fusion combines parallel branches, vertical fusion compresses a linear sequence.
- Primary Benefit: Reduces memory bandwidth pressure by keeping intermediate results in fast registers or cache.
Operator Fusion
Operator fusion is the high-level, graph-level optimization that merges adjacent computational nodes in a neural network's dataflow graph. It is the overarching goal that horizontal and vertical fusion techniques achieve.
- Scope: Works on the abstract computational graph before low-level kernel code is generated.
- Objective: To create compound operations that replace multiple primitive ops, minimizing data movement between the GPU's global memory and its cores.
- Compiler Role: Frameworks like XLA, TVM, and PyTorch's torch.compile perform automatic operator fusion by pattern matching and cost-based analysis.
Kernel Fusion
Kernel fusion is the low-level implementation of operator fusion, where multiple GPU computational kernels are combined into a single, unified kernel. This is the concrete result of fusion optimizations.
- Implementation Level: Occurs at the level of CUDA, Metal, or Vulkan kernel code.
- Core Benefit: Dramatically reduces kernel launch overhead—the latency of scheduling work on the GPU—by issuing one launch instead of many.
- Example: A hand-written or compiler-generated fused kernel that performs elementwise addition, ReLU, and scaling in one pass over the data.
Graph Fusion
Graph fusion is the automated process of identifying and merging subgraphs within a full computational graph. It uses algorithms to find optimal fusion groups—sets of operators to combine.
- Process: Employs pattern matching and fusion heuristics to discover profitable fusion opportunities across the entire model graph.
- Planner Component: A fusion planner explores a search space of possible fusions, guided by a cost model for fusion that predicts performance impact.
- Outcome: Creates a new, optimized graph where entire subgraphs are replaced with single, efficient fused operators.
Elementwise Fusion
Elementwise fusion is a specific, common type of horizontal fusion where multiple pointwise operations are combined. These operations perform independent computations on each element of a tensor.
- Operations Included: Functions like
ReLU,Sigmoid,Add,Multiply, andScalethat apply uniformly across all tensor elements. - Fusion Simplicity: Highly profitable and straightforward to fuse because there are no complex data dependencies between the operations; they all read from and write to the same memory locations.
- Performance Gain: Elimates multiple passes over the same data, maximizing arithmetic intensity and cache locality.
Fusion Compiler (XLA/TVM/MLIR)
A fusion compiler is a specialized compiler backend responsible for performing fusion optimizations. Major examples include XLA, TVM, and MLIR.
- XLA (Accelerated Linear Algebra): Google's compiler for TensorFlow/JAX. Performs aggressive fusion using its own HLO IR, a key reason for its performance on TPUs and GPUs.
- Apache TVM: Uses its auto-scheduling and Ansor tuner to generate highly optimized, fused kernels for diverse hardware targets.
- MLIR (Multi-Level Intermediate Representation): Provides dialects like Linalg and transformation passes to represent and perform fusion in a hardware-agnostic way, enabling fusion-aware scheduling.
- Role: Transforms a high-level operator graph into a minimal set of high-performance, fused kernels for execution.

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