YFlows: Systematic Dataflow Exploration and Code Generation for Efficient Neural Network Inference using SIMD Architectures on CPUs

Cyrus Zhou, Zack Hassman, Dhirpal Shah, Vaughn Richard, Yanjing Li

TL;DR

This paper introduces YFlows, a novel framework that systematically explores dataflow execution orders to optimize neural network inference on CPUs using SIMD instructions. By analyzing data reuse opportunities and employing a code generation approach, YFlows achieves significant speedups (up to 3x for 8-bit and 4.8x for binary networks) over existing optimized implementations.

What Problem Does This Paper Address?

Deploying neural networks (NNs) on resource-constrained devices like CPUs presents a significant challenge, primarily due to the need for fast inference times without sacrificing accuracy. While Single Instruction, Multiple Data (SIMD) capabilities on modern CPUs offer a promising avenue for acceleration, effectively leveraging them for NNs is complex. Existing compiler optimizations often fall short, failing to fully exploit SIMD registers and complex data dependencies inherent in NN computations. Furthermore, the order in which computations are performed (dataflow) significantly impacts data reuse and, consequently, SIMD efficiency, but this aspect has been largely overlooked in prior CPU-focused NN optimization efforts.

Methods

The core of YFlows lies in its systematic exploration of dataflows. The authors extend the concept of "stationarity" (keeping data in registers) to include input, weight, and output data. They propose a methodology that:

  1. Extends Basic Dataflows: Introduces "anchoring stationarities" (defining execution order) and "auxiliary stationarities" (stashing additional data for reuse).
  2. Heuristic-Guided Optimization: Develops heuristics based on memory movement costs to guide the optimization of three basic dataflows (Input Stationary, Weight Stationary, Output Stationary) by maximizing reuse opportunities.
  3. Code Generation Framework: Implements a code generator that automatically produces SIMD-optimized code for various extended dataflows, allowing for empirical comparison.
  4. Memory Layout Optimization: Utilizes an NCHW[xc] memory layout for input/output tensors and a CKRS[xc] layout for weights to streamline vectorization and enable data reuse.
  5. End-to-End Optimization: Integrates memory layout optimization and blocking/operator fusion techniques for holistic performance gains.

Datasets

The paper does not explicitly mention training datasets. For evaluation, they use convolution layers from various neural network architectures, including ResNet (18 and 34), VGG (11, 13, and 16), and DenseNet-121. The experiments are conducted on physical ARM machines.

Key Insights and Ideas

  • Dataflow is Crucial for SIMD Efficiency: The order of operations (dataflow) is not just a minor detail but a critical factor in maximizing SIMD register utilization and data reuse on CPUs.
  • Output Stationary (OS) Dominates: Among the basic dataflows, Output Stationary consistently outperforms Input Stationary (IS) and Weight Stationary (WS), achieving significant speedups due to reduced reduction operations and better memory access patterns.
  • Auxiliary Stationarities Unlock Further Gains: Extending basic dataflows with auxiliary stationarities (stashing inputs, weights, or outputs) is essential to fully utilize SIMD registers and achieve substantial performance improvements.
  • Weight Stationary (WS) is Less Promising: WS dataflows, even when optimized with auxiliary stationarities, yield the least performance improvement and remain the slowest, suggesting their inherent limitations for SIMD optimization.
  • OS with Weight Auxiliary Stationarity is Optimal: The most effective extended dataflow identified is OS-anchored with auxiliary weight stationarity, offering a good balance of performance and code readability.

Key Results

  • Significant Speedups: YFlows achieves up to 3x speedup for 8-bit neural networks and up to 4.8x speedup for binary neural networks compared to state-of-the-art optimized implementations.
  • Outperforming Baselines: Compared to TVM's autotuned implementations, YFlows shows a ~3x speedup for 8-bit NNs and up to ~14x speedup over TVM's untuned implementation.
  • Binary NN Performance: For binary NNs, YFlows is over 12x faster than TVM-based bitserial implementations and achieves up to 4.8x speedup over other prior works.
  • Auxiliary Stationarity Impact: Prioritizing output auxiliary stationarity under input-anchored dataflows yields an 8% performance gain. For OS-anchored dataflows, the impact of prioritizing input vs. weight auxiliary stationarity is minimal.

Limitations and Future Work

  • Focus on Convolution Layers: The current work primarily focuses on optimizing convolution layers, which are common but not the only type of layer in NNs.
  • Heuristic Limitations: While heuristics are effective, they might not cover all edge cases or complex scenarios.
  • Future Work: The authors suggest extending their framework to other layer types, exploring more advanced SIMD optimization techniques, and investigating its applicability to other architectures like Intel's AMX extension. They also propose combining their dataflow approach with existing techniques like daBNN for binary NNs to achieve further improvements.

Summary updated

BibTeX
@inproceedings{zhou2024yflows,
  author = {Cyrus Zhou and Zack Hassman and Dhirpal Shah and Vaughn Richard and Yanjing Li},
  title = {{YFlows: Systematic Dataflow Exploration and Code Generation for Efficient Neural Network Inference using SIMD Architectures on CPUs}},
  booktitle = {CC},
  year = {2024},
  doi = {10.1145/3640537.3641566},
}
Figure