Exposing Hardware Building Blocks to Machine Learning Frameworks

Yash AkhauriarXiv 2020 · DOI

Abstract

There are a plethora of applications that demand high throughput and low latency algorithms leveraging machine learning methods. This need for real time processing can be seen in industries ranging from developing neural network based pre-distortors for enhanced mobile broadband to designing FPGA-based triggers in major scientific efforts by CERN for particle physics. In this thesis, we explore how niche domains can benefit vastly if we look at neurons as a unique boolean function of the form $f:B^{I} \rightarrow B^{O}$, where $B = \{0,1\}$. We focus on how to design topologies that complement such a view of neurons, how to automate such a strategy of neural network design, and inference of such networks on Xilinx FPGAs. Major hardware borne constraints arise when designing topologies that view neurons as unique boolean functions. Fundamentally, realizing such topologies on hardware asserts a strict limit on the 'fan-in' bits of a neuron due to the doubling of permutations possible with every increment in input bit-length. We address this limit by exploring different methods of implementing sparsity and explore activation quantization. Further, we develop a library that supports training a neural network with custom sparsity and quantization. This library also supports conversion of trained Sparse Quantized networks from PyTorch to VERILOG code which is then synthesized using Vivado, all of which is part of the LogicNet tool-flow. To aid faster prototyping, we also support calculation of the worst-case hardware cost of any given topology. We hope that our insights into the behavior of extremely sparse quantized neural networks are of use to the research community and by extension allow people to use the LogicNet design flow to deploy highly efficient neural networks.

Introduction

Modern real-time applications, such as particle physics triggers at the Large Hadron Collider (LHC), demand nanosecond-scale inference latencies that traditional CPU or GPU architectures struggle to provide. While Field Programmable Gate Arrays (FPGAs) are ideal for such tasks, standard hardware/software codesign workflows often rely on high-level abstractions that fail to exploit the underlying hardware's full potential.

This research introduces LogicNet, a framework that maps neural network neurons directly to FPGA Look-Up Tables (LUTs). By treating each neuron as a pure boolean function mapping $X$ input bits to $Y$ output bits, LogicNet bypasses traditional instruction-set architectures. The primary challenge in this approach is the exponential growth of the truth table size relative to the number of input bits (fan-in). To overcome this, LogicNet employs aggressive activation quantization and extreme sparsity to ensure that neural network topologies can be synthesized directly into efficient combinational logic.

The LogicNet Methodology

The LogicNet tool-flow bridges the gap between high-level PyTorch models and low-level Verilog RTL. The methodology centers on three core pillars:

1. Extreme Sparsification

To keep the per-neuron fan-in within hardware-feasible limits, the framework explores several pruning techniques. These include A-Priori Fixed Sparsity (using random fixed connections), Iterative Pruning (based on weight magnitude), and a modified Sparse Momentum algorithm. By strictly bounding the number of inputs to each neuron, the resulting truth tables remain manageable for synthesis.

2. Quantization-Aware Training

Using the Brevitas library, LogicNet implements heavy activation quantization, typically ranging from 1 to 3 bits. While weights remain at full precision during the training phase to facilitate gradient descent, they are eventually "baked" into the static truth tables of the neurons. This allows the final hardware implementation to be entirely weight-free, consisting only of logic gates.

3. Automated Synthesis and Cost Modeling

Once a model is trained, LogicNet generates a truth table for every neuron and automatically produces Verilog code. This direct mapping allows for massive parallelism and high throughput. Additionally, the framework provides an analytical cost model to estimate LUT usage during the design phase. Interestingly, empirical results show that Xilinx Vivado's logic minimization often reduces actual hardware costs by up to 9.5x compared to these analytical estimates.

Experimental Evaluation

The framework was evaluated on two distinct datasets representing different ends of the complexity spectrum.

High-Energy Physics: FPGA4HEP

The FPGA4HEP dataset involves jet substructure classification for the LHC. In this domain, LogicNet discovered topologies achieving an Average AUC-ROC of approximately 89.46% using roughly 10,461 LUTs. An even more lightweight model maintained 88.7% AUC-ROC using only 2,120 LUTs, demonstrating the framework's ability to scale down for extreme resource constraints.

Computer Vision: MNIST

On the MNIST handwritten digit dataset, LogicNet achieved over 97% accuracy using highly sparse Multi-Layer Perceptrons (MLPs) and over 98% accuracy using sparse depthwise separable convolutions. These results prove that the boolean-function approach is viable even for standard vision tasks, provided the architecture is sufficiently optimized.

Key Insights

  • The Power of Synthesis Tools: The significant gap between analytical cost models and actual synthesized results suggests that modern logic optimizers are highly effective at simplifying the boolean logic generated by sparse networks.
  • Precision Trade-offs: Moving from 1-bit to 2-bit activations provides a substantial accuracy boost. However, the jump to 3-bit activations offers diminishing returns while significantly increasing hardware complexity due to the exponential nature of truth tables.
  • Architectural Flexibility: Skip connections are effectively "free" in this paradigm. As long as the total fan-in per neuron is respected, adding skip connections improves accuracy without increasing the LUT count.

Conclusion and Future Work

LogicNet demonstrates a path toward ultra-low-latency machine learning by exposing the fundamental building blocks of FPGAs to deep learning frameworks. Future work will focus on parallelizing the truth table generation process to handle larger fan-ins and integrating Neural Architecture Search (NAS) to automatically discover optimal unstructured sparse topologies. Additionally, improving support for folded convolutional layers and incorporating routing congestion heuristics will further enhance the tool-flow's utility for complex edge-AI deployments.

Summary updated

BibTeX
@misc{akhauri2020exposing,
  author = {Yash Akhauri},
  title = {{Exposing Hardware Building Blocks to Machine Learning Frameworks}},
  year = {2020},
  eprint = {2004.05898},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2004.05898},
}
Figure