Abstract
In recent years, there is a surge on machine learning applications in industry. Many of them are based on popular AI frameworks like TensorFlow, Torch, Caffe, or MxNet, etc, and are empowered by accelerator platforms such as GPUs. One important challenge of running TensorFlow computations on GPUs is the fine granularity problem, namely, FLOPS of individual ops are far from enough to fully exploit the computing power of underlying accelerators. The XLA framework provides a solid foundation to explore this problem further. In this paper, we propose FusionStitching, a novel, comprehensive Op fusion and code generation system to stitch computations into large GPU kernels. Experimental results on four public models and two of our large in-house applications show another 55% (geometric mean) reduction of GPU kernel launches, compared to the XLA fusion baseline. This increases the E2E performance of both of our latency critical in-house applications up to 20%.
Introduction
Modern deep learning models are composed of thousands of individual operations (ops). While heavy hitters like Matrix Multiplications (MatMuls) and Convolutions are well-optimized by vendor libraries, a massive portion of a model's execution time is often spent on "fine-grained" ops—elementwise additions, small reductions, and shape transformations. On a GPU, these tiny ops create a "granularity problem" where the overhead of launching a kernel can exceed the time it takes to perform the computation.
FusionStitching is a novel optimization system that aggressively fuses these fine-grained TensorFlow operations into large, efficient GPU kernels. By moving beyond simple loop-nesting to a "block composition" approach—using on-chip shared memory to "stitch" operations together—it achieves a 55% reduction in kernel launches and up to a 20% end-to-end performance boost over standard XLA.
System Architecture and Methods
The FusionStitching pipeline enhances the standard XLA framework with several specialized stages for deep fusion and schedule planning.
The system begins with Work/Span Analysis, identifying the critical path of the computation graph and organizing ops into layers based on their depth. The Deep Fusion module then groups ops together. Unlike traditional compilers that focus solely on producer-consumer fusion, FusionStitching also performs "intra-layer" fusion, grouping independent ops at the same depth to further minimize launch overhead.
Core Innovation: Block Composition
The central innovation of FusionStitching is the shift from "thread composition" to Block Composition.
In traditional thread composition (used by XLA), all fused ops must share the same parallel loop structure. This constraint prevents the fusion of complex patterns, such as a reduction followed by a transpose. FusionStitching overcomes this by allowing different ops within a single kernel to have independent loop structures. These ops are "stitched" together using the GPU's fast on-chip shared memory as a scratchpad for intermediate results.
To optimize these kernels, the system includes Schedule Planning & Tuning, which searches a space of parameters like splitDim and sword (partition size). A Performance Library—a key-value store of actual execution times—is used to select the most efficient implementation. Because shared memory is scarce, a "size shrinking" algorithm intelligently trades memory for recomputation if hardware limits are exceeded.
Evaluation and Results
The authors validated FusionStitching using a mix of standard benchmarks (LR, W2V, RNN, BiRNN) and large-scale industrial applications from Alibaba, including Speech Recognition and Neural Machine Translation (NMT). Analysis of over 50,000 models on Alibaba’s PAI platform highlighted the prevalence of the granularity problem.
Key results include:
- Kernel Launch Reduction: A 55% geometric mean reduction in GPU kernel launches compared to the XLA baseline.
- End-to-End Speedup: Latency-critical applications saw performance improvements of up to 20%.
- Fusion Efficiency: On the specific parts of the graph targeted for fusion, the average speedup was 1.74x. The system proved particularly effective for workloads with complex interaction patterns between reductions and transposes.
Conclusion and Future Work
FusionStitching demonstrates that treating shared memory as a managed bridge between fused ops allows for much more aggressive optimization than standard loop-fusion techniques. While highly effective for fine-grained ops, future work aims to extend this fusion to "heavy" library ops like large MatMuls and Convolutions. Additionally, the authors plan to replace the current lookup-table-based tuning with machine learning models to predict kernel performance, eliminating the need for a JIT warmup phase.
Summary updated