Fast convolutional neural networks on FPGAs with hls4ml

Thea Aarrestad, Vladimir Loncar, Maurizio Pierini, Sioni Summers, Jennifer Ngadiuba, Christoffer Petersson, Hampus Linander, Yutaro Iiyama, Giuseppe Di Guglielmo, Javier M. Duarte, Philip C. Harris, Dylan S. Rankin, Sergo Jindariani, Kevin Pedro, Nhan Tran, Mia Liu, Edward Kreinar, Zhenbin Wu, Duc Hoang · DOI

Abstract: We introduce an automated tool for deploying ultra low-latency, low-power deep neural networks with convolutional layers on FPGAs. By extending the hls4ml library, we demonstrate an inference latency of $5\,\mu$s using convolutional architectures, targeting microsecond latency applications like those at the CERN Large Hadron Collider. Considering benchmark models trained on the Street View House Numbers Dataset, we demonstrate various methods for model compression in order to fit the computational constraints of a typical FPGA device used in trigger and data acquisition systems of particle detectors. In particular, we discuss pruning and quantization-aware training, and demonstrate how resource utilization can be significantly reduced with little to no loss in model accuracy. We show that the FPGA critical resource consumption can be reduced by 97% with zero loss in model accuracy, and by 99% when tolerating a 6% accuracy degradation.

Introduction

At the CERN Large Hadron Collider (LHC), proton collisions occur every 25 nanoseconds, generating a tidal wave of data. To handle this, "Level-1" trigger systems must decide which data to keep and which to discard in less than a microsecond.

While Deep Learning is highly effective for identifying patterns in this data, deploying these models on FPGAs (the hardware used in triggers) is notoriously difficult. Standard Convolutional Neural Network (CNN) implementations are often too slow or too resource-intensive for the limited memory and logic cells available on a chip. The hls4ml tool was developed to bridge this gap, and this work extends its capabilities to support spatially-aware CNNs for real-time hardware triggers.

Hardware Implementation Methods

The authors introduce several engineering innovations to bridge the gap between high-level Python models and low-level hardware:

Streaming Implementation

Instead of storing entire images in memory (which would quickly exhaust FPGA resources), the tool uses a "streaming" approach. Data flows through the chip via FIFOs (First-In, First-Out buffers), processing one pixel or column at a time. This avoids the "partitioning limit" of standard High-Level Synthesis (HLS) tools, allowing the handling of much larger input images than previously possible.

Binary Mask Instructions

To manage the "sliding window" of a convolution without complex, slow branching logic, the researchers pre-compute a binary mask. This mask acts as a set of hardware instructions telling the buffer exactly which elements to use for the next calculation.

Figure 3: Illustration of the sliding window mechanism and the corresponding binary mask used for hardware instructions.

Model Compression Pipeline

Fitting a CNN into an FPGA requires aggressive compression. The pipeline employs two primary techniques:

  1. Pruning: Using the TensorFlow Pruning API, 50% of the weights are removed (set to zero). The hls4ml compiler then skips these multiplications in hardware, saving significant resources.
  2. Quantization-Aware Training (QAT): Using the QKeras library, models are trained to use extremely low-precision numbers (e.g., 3-bit or 7-bit integers) instead of standard 32-bit floats. Because the model "learns" to be accurate despite the low precision during training, it performs much better than post-training quantization.

Datasets

The researchers used the Street View House Numbers (SVHN) dataset for benchmarking. It consists of $32 \times 32$ RGB images of digits. SVHN is significantly more challenging than MNIST due to varying colors, backgrounds, and orientations, but it has a similar input size to the data shapes found in particle detector systems.

Figure 5: Sample images from the Street View House Numbers (SVHN) dataset used for benchmarking.

Key Results and Insights

The success of the project relies on hardware-software co-design, specifically the tight integration between QKeras (software training) and hls4ml (hardware synthesis).

  • Ultra-Low Latency: On a high-end Xilinx Virtex UltraScale+ FPGA, the benchmark CNN achieved an inference latency of 5.2 $\mu$s.
  • Extreme Compression: A model quantized to 7 bits and pruned to 50% sparsity maintained 94% accuracy while reducing critical resource consumption by 97%.
  • Versatility: To prove the tool's efficiency, a 7-bit model was deployed on a PYNQ-Z2 (a low-cost hobbyist SoC), achieving 171 $\mu$s latency and processing over 2,800 images per second.

Conclusion and Future Work

The expansion of hls4ml to support CNNs enables ultra-low-latency deep learning in extreme environments. While current results are promising, future work will address the quantization of Batch Normalization layers and explore higher clock frequencies to further reduce latency. Additionally, the team plans to extend these streaming optimizations to more exotic architectures like dilated or separable convolutions.

Summary updated

BibTeX
@inproceedings{aarrestad2021fast,
  author = {Thea Aarrestad and Vladimir Loncar and Maurizio Pierini and Sioni Summers and Jennifer Ngadiuba and Christoffer Petersson and Hampus Linander and Yutaro Iiyama and Giuseppe Di Guglielmo and Javier M. Duarte and Philip C. Harris and Dylan S. Rankin and Sergo Jindariani and Kevin Pedro and Nhan Tran and Mia Liu and Edward Kreinar and Zhenbin Wu and Duc Hoang},
  title = {{Fast convolutional neural networks on FPGAs with hls4ml}},
  booktitle = {Mach. Learn. Sci. Technol},
  year = {2021},
  url = {https://openreview.net/forum?id=PmjZy0Upj2C},
}
Figure