NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Automatic Horizontal Fusion for GPU Kernels

Ao Li, Bojian Zheng, Gennady Pekhimenko, Fan Long

TL;DR

This paper introduces horizontal kernel fusion, a novel GPU optimization technique that executes independent kernels concurrently within the same thread blocks to maximize thread-level parallelism and hide instruction latencies. To automate this, the authors developed HFUSE, a source-to-source CUDA compiler that intelligently partitions thread spaces and handles synchronization barriers, delivering speedups of up to 60.8%.

What Problem Does This Paper Address?

Modern GPU optimization relies heavily on kernel fusion. Traditionally, this is done vertically: combining sequential, dependent kernels (where the output of Kernel A is the input to Kernel B) into a single kernel to eliminate expensive round-trips to global memory.

However, vertical fusion has a major blind spot. It cannot optimize independent kernels or exploit situations where different kernels bottleneck on different hardware resources (e.g., one is compute-heavy while the other is memory-heavy). When a memory-intensive kernel stalls waiting for data, valuable compute cores sit idle.

The authors address this gap by proposing horizontal kernel fusion. Instead of running kernels back-to-back, horizontal fusion co-schedules independent kernels to run simultaneously on the same Stream Multiprocessor (SM). This allows the GPU's hardware warp scheduler to interleave instructions from both kernels, effectively hiding memory latencies using the compute instructions of the other.

Fig. 1: Vertical and horizontal kernel fusion.

Methods

The authors designed and implemented HFUSE, a source-to-source CUDA compiler that automates horizontal fusion through three main mechanisms:

  1. Thread Space Partitioning: HFUSE groups threads within a block and assigns different intervals of thread IDs to different original kernels using conditional branching statements.
  2. Partial Synchronization Barriers: Standard CUDA block barriers (__syncthreads()) stall all threads in a block. If Kernel A hits a barrier, it would inadvertently freeze the concurrent threads of Kernel B. HFUSE solves this by replacing standard barriers with inline PTX assembly (bar.sync), creating localized, partial barriers that only synchronize the threads belonging to that specific kernel.
  3. Automated Profiling & Configuration Search: Fusing kernels increases register pressure, which can lower a GPU's occupancy (the number of active warps per SM). HFUSE automatically profiles the fused kernel under various thread-partitioning ratios and register bounds to find the sweet spot between thread-level parallelism and occupancy.

Datasets

The approach was evaluated using 16 pairs of kernels across two distinct domains:

  • Deep Learning: 5 kernels extracted from PyTorch (Maxpool, Batchnorm, Upsample, Im2Col, and Hist), which are widely used in models like ResNet and BigGAN.
  • Cryptocurrency Mining: 4 cryptography kernels (Ethash, SHA256, Blake256, and Blake2B) from open-source miners.

Evaluations were performed across two generations of NVIDIA GPUs: the GeForce GTX 1080Ti (Pascal architecture) and the Tesla V100 (Volta architecture).

Key Insights and Ideas

  • Opposites Attract: Horizontal fusion is highly effective when pairing a memory-intensive kernel (like Ethash or Batchnorm) with a compute-intensive kernel (like Blake256 or Hist). The compute instructions fill the execution gaps caused by long-latency memory stalls.
  • Fusing Similars Fails: Fusing two compute-intensive kernels together actually hurts performance. Because they compete for the exact same execution units, the fusion adds register pressure and lowers occupancy without providing any latency-hiding benefits.
  • The Parallelism Trade-off: The paper highlights a fundamental tension between thread-level parallelism (interleaving instructions from more threads) and block-level parallelism (running more blocks concurrently). Horizontal fusion proves that sacrificing block occupancy is often worth it if the remaining threads can be scheduled more efficiently.

Key Results

Horizontal fusion achieved overall execution time speedups ranging from 2.5% to 60.8% compared to native, non-fused parallel stream execution.

Out of the 16 evaluated pairs, HFUSE outperformed both native execution and standard vertical fusion in 7 pairs on the 1080Ti and 6 pairs on the V100. For instance, pairing Batchnorm and Hist yielded massive performance gains because their complementary resource needs allowed the warp scheduler to maximize slot utilization.

Fig. 7: Kernel execution time speedup.

Limitations and Future Work

  • Dimension Simplification: For simplicity in the compiler design section, the authors assume kernels operate on a single block sub-dimension ($blockDim.y$ and $blockDim.z$ are 1), though they note it can be extended to multi-dimensional blocks.
  • Pairwise Limitation: The current HFUSE framework focuses on fusing exactly two kernels at a time; scaling this to horizontally fuse three or more kernels simultaneously remains an open engineering challenge.
  • No Recursion: HFUSE does not support recursive function calls, though the authors note this is rarely an issue since recursion is highly inefficient and seldom used in GPU kernels.

Summary updated

BibTeX
@misc{li2020automatic,
  author = {Ao Li and Bojian Zheng and Gennady Pekhimenko and Fan Long},
  title = {{Automatic Horizontal Fusion for GPU Kernels}},
  year = {2020},
  eprint = {2007.01277},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2007.01277},
}
Figure