Serving Recurrent Neural Networks Efficiently with a Spatial Accelerator

Tian Zhao, Yaqi Zhang, Kunle Olukotun

Abstract

Recurrent Neural Networks (RNNs), such as LSTMs and GRUs, are critical for real-time AI services like live translation and voice assistants. However, traditional software frameworks relying on Basic Linear Algebra Subprograms (BLAS) suffer from significant data movement bottlenecks and resource underutilization during single-batch inference. This paper introduces a novel approach that replaces kernel-stitching with loop-based abstractions mapped directly to spatial accelerators. By leveraging cross-kernel fusion and fine-grained parallelism on the Plasticine Coarse-Grained Reconfigurable Architecture (CGRA), this method achieves a 30x performance improvement over high-end GPUs and doubles the efficiency of state-of-the-art FPGA implementations.

Introduction

Modern real-time AI applications demand "single-batch" inference to ensure ultra-low latency. Standard deep learning frameworks typically implement RNNs by stitching together optimized BLAS kernels (e.g., matrix-vector multiplications). While these kernels are individually efficient, the overall approach creates two primary bottlenecks: massive intermediate data movement between processor and memory, and hardware underutilization when processing small hidden states. To address these issues, we propose a shift toward loop-based abstractions that exploit the physical arrangement of compute units in spatial hardware.

Methodology: From Kernels to Loops

The core innovation involves moving away from the "kernel-stitching" model. Instead of treating gate functions (input, forget, output gates) as discrete steps, the entire computation of a single hidden state element is fused into a single pipeline.

Comparison of (a) traditional kernel-based implementation vs (b) the proposed loop-based implementation for an LSTM cell.

As shown in Figure 2, the loop-based approach (b) allows intermediate results to remain in registers rather than being written back to slower on-chip scratchpad memory. This "register-level locality" significantly reduces energy consumption and latency. We define the "LSTM-1" operation, which allows every element in the hidden state to be computed independently, exposing massive fine-grained parallelism.

Spatial Mapping and Hardware Co-design

To implement these abstractions, we utilize the Spatial hardware description language to automatically schedule and parallelize complex nested loops onto the Plasticine CGRA.

Spatial mapping of the loop-based RNN computation, illustrating nested "Foreach" loops and vectorization parameters.

Figure 5 illustrates how the computation is mapped spatially. Key micro-architectural enhancements include:

  • Mixed-Precision Support: Optimized handling of 8-bit and 16-bit operations.
  • Folded Reduction Trees: Ensuring high hardware utilization even for small mathematical operations.
  • Consistent Scaling: Unlike GPUs, which experience performance degradation on small models, this spatial approach maintains high utilization across various problem sizes.

Evaluation and Results

The system was evaluated using the Baidu DeepBench suite against an Intel Xeon CPU, an NVIDIA Tesla V100 GPU, and Microsoft’s Brainwave (Stratix 10 FPGA).

  • Performance: The Plasticine implementation achieved a geometric speedup of 30x over the V100 GPU for small RNN tasks.
  • Efficiency: It demonstrated 1.6x better area efficiency and 2x better power efficiency than the V100.
  • FPGA Comparison: It delivered 2x the performance of Microsoft Brainwave by avoiding the fragmentation issues inherent in matrix-based designs.
  • Latency: All configurations met the critical 5ms latency threshold required for real-time human-computer interaction.

Conclusion

This research demonstrates that BLAS is a "leaky abstraction" for spatial accelerators. By redesigning RNN computation around fused loops and register-level locality, we can unlock significant performance and efficiency gains. Future work will explore extending these loop-based optimizations to extra-large models that exceed on-chip memory capacity and investigating support for sparse neural networks.

Summary updated

BibTeX
@inproceedings{zhao2019serving,
  author = {Tian Zhao and Yaqi Zhang and Kunle Olukotun},
  title = {{Serving Recurrent Neural Networks Efficiently with a Spatial Accelerator}},
  booktitle = {SysML},
  year = {2019},
}
Figure