Next Article in Journal
Red Fluorescent Genetically Encoded Voltage Indicators with Millisecond Responsiveness
Next Article in Special Issue
Location Privacy Protection in Distributed IoT Environments Based on Dynamic Sensor Node Clustering
Previous Article in Journal
Enabling the Orchestration of IoT Slices through Edge and Cloud Microservice Platforms
Previous Article in Special Issue
DNN-MVL: DNN-Multi-View-Learning-Based Recover Block Missing Data in a Dam Safety Monitoring System
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Mapping Neural Networks to FPGA-Based IoT Devices for Ultra-Low Latency Processing

by
Maciej Wielgosz
1,2,* and
Michał Karwatowski
1,2
1
Faculty of Computer Science, Electronics and Telecommunications, AGH University of Science and Technology, al. Adama Mickiewicza 30, 30-059 Cracow, Poland
2
Academic Computer Centre CYFRONET AGH, ul. Nawojki 11, 30-072 Cracow, Poland
*
Author to whom correspondence should be addressed.
Sensors 2019, 19(13), 2981; https://doi.org/10.3390/s19132981
Submission received: 28 April 2019 / Revised: 29 June 2019 / Accepted: 1 July 2019 / Published: 5 July 2019
(This article belongs to the Special Issue Algorithm and Distributed Computing for the Internet of Things)

Abstract

:
Internet of things (IoT) infrastructure, fast access to knowledge becomes critical. In some application domains, such as robotics, autonomous driving, predictive maintenance, and anomaly detection, the response time of the system is more critical to ensure Quality of Service than the quality of the answer. In this paper, we propose a methodology, a set of predefined steps to be taken in order to map the models to hardware, especially field programmable gate arrays (FPGAs), with the main focus on latency reduction. Multi-objective covariance matrix adaptation evolution strategy (MO-CMA-ES) was employed along with custom scores for sparsity, bit-width of the representation and quality of the model. Furthermore, we created a framework which enables mapping of neural models to FPGAs. The proposed solution is validated using three case studies and Xilinx Zynq UltraScale+ MPSoC 285 XCZU15EG as a platform. The results show a compression ratio for quantization and pruning in different scenarios with and without retraining procedures. Using our publicly available framework, we achieved 210 ns of latency for a single processing step for a model composed of two long short-term memory (LSTM) and a single dense layer.

1. Introduction

Artificial Intelligence algorithms are developing rapidly and in multiple areas. One of the crucial factors causing this significant leap is the exponential increase of the available data, mainly due to the adoption of the IoTinternet of things (IoT). To be able to make correct decisions, from those vast amounts of data, the knowledge needs to be extracted. This task is usually done using machine learning algorithms, nowadays very often implemented as neural networks. Fast and well-defined system response time increasingly becomes a more decisive factor in the Quality of Service.
The structure of a conventional data processing and knowledge extraction system is presented in Figure 1, with most of the data processing done in the computing cloud. As a result, the latency of the system response depends on both computing and data-transfer time between edge devices, over the network, and to the data centers. The computing acceleration is possible at every step of the path. The most notable latency decrease can, however, be achieved by relocating as much of the computations into the edge (IoT) devices as possible. Consequently, the amount of data transferred and processed in the upper levels of hierarchy can be significantly reduced.
The maintenance or improvement of the system working parameters, simultaneous with the growing amount of data, and increased expectations regarding the system response time is a complex problem. It was conceptually presented in Figure 2. There are three main dimensions of the compression operation, namely the model size, the latency of the model response, and quality of the processing results delivered by the compressed model. Aggressive compression usually leads to a reduction of model size and processing latency at the expense of the quality of the model performance (e.g., an accuracy drop in the classification set-up) which is undesirable and even not acceptable in many applications. Consequently, the most desirable but unreachable result of the compression operation may be visualized as the coordinate system origin, as presented in Figure 2. Moving towards this location requires deep learning (DL) models to be compressed in a way that does little or no harm to their performance. Furthermore, the compressed modules implemented in the IoT platforms need to be scalable and portable across different devices within the sensor network. This requirement imposes additional conditions on the compression process and makes it even more challenging.
It is worth noting that for over 30 years, Moore’s law determined the progress in computing devices. Thus, the preferred strategy was to wait for a new generation of devices to show up rather than optimizing existing software and platforms. Nowadays, in an era of IoT, multi-core processors, deep learning, and 5G networks, it is better to develop custom solutions which can be employed across various embedded platforms.
Unfortunately, designing, training and modifying DL architectures, created with currently widely available frameworks offering a lot of flexibility and extensive features range, remain in contrast to rigid and well-grounded hardware digital systems design methodology [1,2,3,4]. Bringing those two different worlds together is a challenging endeavor, especially when it comes to creating a methodology and a framework which preserve all the desirable traits of machine learning software.
Popular frameworks provide extensions designed for mobile applications [5,6,7]. However, as they target mobile devices such as smartphones, latency requirements are not very strict. For example, TensorFlow Lite [5] provides performance benchmarks for popular architectures, and the lowest mean inference time is reported for quantized Mobilenet_1.0_224 on iPhone 8 which is 24.4 ms, for other models or on other devices latency is higher.
To accelerate neural models inference many researchers turned to field-programmable gate arrays (FPGAs) [8,9,10]. However, they usually target larger networks, often with image processing in mind. Such architectures are too sizable to be fully unrolled in hardware; therefore, their implementations are based on various types of processing elements with loadable parameters.
Authors of survey [9] put together several neural networks implementations in FPGAs and compared their performance and resource requirements. Usually, the factor that implementations are optimized against is the number of operations per second. Performance is often achieved by processing many samples in a single batch; however, they also report latency for batch size equal to 1, which is desirable for IoT devices working in the real-time regime. Depending on the network model and the device it was run on, the latency varies from a few milliseconds to a couple of hundreds of milliseconds.
LeFlow [8] presents a very interesting usage of Google’s XLA compiler. Authors provide latency results for single layers, and they were able to infer through a small fully connected layer in 380 clock cycles at 267.45 MHz resulting in 1420 ns latency, fully unrolled element-by-element multiplication of two arrays of size 64 took 428 ns.
The most similar work to ours is presented in [10]. The authors use Xilinx Vivado HLS for mapping to FPGA along with their custom supporting code. The tool was benchmarked with a simple four-layer fully-connected model. More details about this experiment can be found in Section 3.4.
The primary pitfall of the commercially available frameworks is the restricted choice of models and the limited ability to modify and extend both the flow and architectures. On the other hand, mapping applications developed by more research-oriented teams suffer from several deficiencies which make them hard for practical application both in terms of the design time and the flow complexity. They usually lack a clear and convenient path of migration between high-level tools used for model development and simulation and low-level software used directly for FPGA mapping. Consequently, all the issues which occur on a platform level which involve model modification, such as running out of available resources and necessity to redesign the model, are very time-consuming and error-prone. Usually, the low-level software was not created with DL models mapping in mind, so there are no routines and mechanisms which facilitate the process.
The main techniques for neural network compression include weights pruning, weights quantization [4,11]. The pruning is done with the aim of the elimination of selected weights by zeroing them, or, in a more sophisticated version, forcing them to acquire specific values so that their histogram is narrow [4]. Employment of pruning before weights quantization allows to significantly improve both the quality of results generated by the compressed model and the efficiency of weights quantization itself. Several pruning methods are described in Appendix A.
The purpose of weight quantization is the conversion from float to fixed-point representation, as required by efficient hardware implementation. Change of the representation from floating-point to fixed-point representation affects the dynamic range of possible representation. However, when the distribution of the weights is unimodal and narrow, it can be adequately represented as fixed-point. It is worth noting that modern FPGAs can handle floating-point operations, but they are very resource-consuming and sub-optimal [12]. Common quantization approaches are described in Appendix B.
Several works [4,13,14] showed that pruning, quantization, and retraining results in much better results in terms of the weights sparsity than just using static operations. The retraining operation allows to shape histogram of weights and dynamically modify them. There is a range of methods which address this task, and it is still a field of intense exploration [15].
The mapping process should account for each of model, data, and the platform profile, and this is a primary goal of the compression procedure. The compression may be done through the reduction of the weights’ bit-width to its limit, while simultaneously retaining the high quality of results produced by the model.
This paper aims to introduce a methodology for mapping neural models to hardware FPGA platforms with a particular focus on IoT devices. The proposed approach may also be used to assess the feasibility of distributed sensors systems concerning resources consumption of individual nodes as well as the latency budget.
We also conducted the experiments with data bucketization (as introduced in [16,17]) which can enable data stream down-scaling between nodes within the system. This down-scaling is done with little or none performance degradation of the model of several modes distributed across devices within the network.
For mapping the model which specified compression parameters to FPGA, we have developed a tool, called DL2HDL (see Supplementary Materials). The tool encapsulates a series of hardware-oriented conversion procedures which enable efficient implementation of neural architecture components (e.g., layers and activation functions).
This paper’s main contributions are as follows:
  • A methodology for mapping recurrent neural network-based models to hardware,
  • A case studies of the proposed methodology, done in the area of time series analysis (TSA),
  • Custom set of scoring metrics, along with multi-objective covariance matrix adaptation evolution strategy (MO-CMA-ES) applying scheme,
  • DL2HDL, a publicly available framework to map models written in Python to FPGAs.
The rest of the paper is organized as follows. The Section 2 explains the proposed methodology and describes the mapping tool and FPGA implementation details. In the Section 3 the case study setup and experimental results are described. Finally, the Section 4 contains the discussion and future work directions, while conclusions are presented in the Section 5.

2. Materials and Methods

The ultimate goal of the mapping procedure is to stay within the latency budget, even if it incurs some acceptable performance loss. The critical aspect of the process is to mitigate the design timing requirements and resources consumption. Consequently, dedicated strategies and methods are essential.

2.1. Architecture of Tensors Processing

There is a set of processing stages in the proposed flow which shape tensors propagated throughout the neural module. In each stage, a different operations’ precision and operands of various bit-width can be used.
An overview of the proposed processing flow is presented in Figure 3. The high-level sequence of operations is very similar whether the flow in FPGAs after the module was mapped to hardware, or the one performed as an emulation before mapping, done on central processing unit (CPU), is considered.
When entering the module, the original (input) data was subject to optional bucketization and quantized. The bucketization operation has a beneficial impact on the utilization of the available dynamic range of the input data, which was discussed in [16,17]. Then, the data was quantized through mapping to the fixed-point notation. The data quantization mapping schemes were the same as weights quantization ones, presented in Appendix B.
Figure 3 also presents weights pruning and quantization flow. These operations were done in the same way regardless of the platform (CPU or FPGA). In the first step, weights are pruned, and then the quantization operation is performed. If the processing was done on CPU, the quantized weights were stored in the floating-point container. Alternatively, for hardware operations, the quantized weights were directly mapped to FPGA, and the computations were conducted using fixed-point representation.
The core operation in the neural models’ computations was matrix multiplication. When the model compression was emulated on the CPU, the multiplication was done in floating-point precision. On the other hand, in the FPGA flow, the matrix multiplication was done with the precision that prevents overflow, e.g., for two 8 bit arguments fed to single atom multiplication the result occupies 16 bits and was truncated to eight bits (upper eight bits were taken). Consequently, to precisely emulate the hardware flow on CPU, after each matrix multiplication operation, the result should be quantized. This operation is called the activations quantization. It is worth emphasizing that all operations within the hardware platform (FPGA) were done using fixed-point, and the activations quantization can be perceived as being done automatically.
During the emulation, the activations quantization effect can be observed through the performance degradation (e.g., accuracy drop in the classification task). When the performance degradation is too severe, it means that the activations quantization was too aggressive, i.e., too few bits were allocated for the propagation of the activation between the processing stages of the module. If activations quantization was applied during emulation, the module’s output can be extracted from FPGA and mapped back to the floating-point, and then directly compared with the CPU results.
In the proposed mapping scheme, we did not incorporate activation quantization in the flow but used functional simulation of the hardware description language (HDL) code. This omission is possible since our flow is equipped with the simulation step. By examination of the simulation results, we can determine if the overflow occurs. When it happens, the bit-width allocated for the activations should be increased.

2.2. Mapping Strategies

Different paths may be taken to map a deep learning model to platforms with limited resources. The process is complicated and depends on preliminary constraints of a particular design. Two different strategies may be adopted when it comes to the starting point of the mapping flow, the choice of which depends whether we start from scratch or with a pre-trained model. The first strategy leaves much more freedom for the mapping procedures to be applied since the architecture of the model is not fixed at this point and can be modified. On the other hand, when it comes to a mapping of a pre-trained model, we are much more limited concerning the number of available tools that can be used in the process, since the architecture and the internal structure should remain as intact as possible. In practice, it is hardly ever achievable, and modifications such as quantization, pruning, or compression are essential to reduce response latency and memory footprint of the model.
We propose a series of strategies based on our experience in hardware design, deep learning architectures, and FPGA optimization. Since FPGAs may be considered as highly flexible among application-specific integrated circuits (ASICs), general-purpose graphics processing units (GPGPUs), CPUs, and other dedicated platforms [18,19], the presented strategies may be tailored for other hardware as well.
The strategies are split into two main paths. The first one is addressing the flow of a pre-trained model (Figure 4). The second one covers a scenario where a designer starts from the beginning with all the freedom to create a model, which however has to be optimized with hardware constraints in mind (Figure 5).
Before any strategies are attempted, the pre-trained model should be examined concerning incurred latency and resources consumption. The initial calculations should address the border scenario, i.e., the least amount of memory the L-layered model may occupy, assuming the weights are compressed to one bit and 95% of coefficients are removed (Equation (1)).
memory = i = 0 L 1 size ( layer i ) 1 0.05 .
Such quantization and pruning settings are, of course, very optimistic and hardly ever achievable. Consequently, if border conditions analysis shows that the model still exceeds available resources, its architecture should be changed or a bigger FPGA chip should be used.
In the next step, the baseline results should be obtained. It can be done by a simple mapping operation performed after changing the data format to fixed-point. The format change was needed since even though the float-point representation absorbs the same amount of memory (e.g., 32 bit), it leads to much more expensive arithmetic operations. Usually, it turns out after the synthesis and implementation for FPGAs that the model exceeds available resources of the chip. After the compression potential of the model was analyzed, a suitable set of strategies and parameters for the next stages can be chosen.
Ehile two basic proposed flows, A and B, are very similar, the second one is, however, more computationally demanding, therefore it is advisable to start with scenario A if possible. When applying both pruning and quantization, which was the most common case, the pruning should be applied first. It is because quantization granulates the weights search space of the optimal point, making the pruning process harder to converge. The pruning and quantization operations are usually applied on the per-tensor level. However, for some models, especially the ones equipped with depth-wise/point-wise layers (e.g., Mobilenet, Resnext, Xception) performing pruning and quantization operations on per-tensor level can lead to significant degradation of performance [20]. Therefore, the higher granularity of the operations (channel or gate level) is essential for better convergence of pruning and quantization operations.
As incurred latency is affected both by the number of required operations and their precision, the first stage of model mapping procedure should allow to quickly obtain a set of pruning and quantization parameters’ combinations for further (and more time-consuming) tests. To this effect, we propose to apply a software pruning/quantization simulation and some form of multi-objective optimization. For large datasets, the optimization can be performed using a small, but representative test dataset (e.g., 5% to 10% of original), and final results should be validated on the full test dataset. The optimization objectives should include keeping the model quality as close to original as possible, ensuring the biggest overall model weights’ sparsity, and bringing the precision down as much as possible. The analysis of the original model resources consumption can help to define the range of the optimization parameters, e.g., it may turn out that to fit the model into the required hardware reaching a specific sparsity or quantization level is required.
The generated parameters’ combinations suitability for further tests may need to be further examined, e.g., to remove all combinations that yield the model with quality drop above the acceptance threshold, usually ≈1 percentage point (p.p.). It may also be beneficial to run the inference with the full testing dataset and verify the model quality. Once the candidates were selected, the pruned and quantized models were once again mapped to FPGA for the examination of incurred latency. If the latency is satisfactory, the procedure is over; else flow B can be used. It may also turn out that the flow B better addresses the distribution of the compressed model across the IoT platforms comprised of multiple nodes with limited and different resources.
In the flow A, the pruning and quantization parameters were chosen for the whole model (e.g., the precision of N bits) and then applied per-tensor (e.g., prune X% of each tensor, find the number of integral/fractional bits that will best represent this tensor). In scenario B, the pruning and quantization parameters are chosen and applied on the per-tensor basis, i.e., each tensor can have different precision and pruning conditions than the other. This individualization can potentially yield even better results, but is much more computationally intensive, since the number of optimized parameters grows with the number of layers.
The next two mapping methods cover scenarios when the model is created from scratch or can be retrained, and the flexibility of modification is left to the designer. In scenario C, the model is interchangeably quantized (using flows A or B) and retrained to regain performance lost in the process and shape the coefficients. Especially trained quantization [21,22] allows shaping coefficients in a way which make a whole model more pruning-prone. If the expected latency is not satisfied, procedure D can be tried.
Procedure D differs from the previously presented scenarios since it incorporates input data bucketization. As such, it is suitable mostly for classification tasks. In the first step, the data should be bucketized, and the model trained. We recommend the adaptive bucketization procedure, which takes the best advantage of the dynamic range of data representation (please See Section 2.1 and Appendix A of [17] and Section 4.2 of [16] for details). This process is arbitrary and should be monitored concerning the performance of the model.
It is worth mentioning that using data bucketization makes the data more susceptible to compression, which in turn may result in the data throughput increase within the system. Furthermore, during experiments, we have noticed that data bucketization may also positively impact model compression (see Section 3.3.5). This effect is caused by the distribution of the input data being affected by a profile of the model weights.
As a second stage of the procedure D, scenario A or B was followed. It those steps fail to meet the latency budget again, scenario C was applied. As the final step, when all those procedures failed to satisfy latency constraints, model modification was recommended. This case was typical when it comes to DL models binarization [11,23] because the network structure was deprived of most information carriers. In such a scenario, after all the operations were applied, the model was extended with few more layers and retrained. The procedure was applied until the performance close the original was reached.

2.3. Analyzed Model—LSTM

The proposed methodology can be applied to various models; however, in our work, we focused on models that can be used for predictive maintenance or anomaly detection, in particular, the long short-term memory (LSTM) networks.
All the tested models utilized LSTM cells and dense units. Each of the LSTM layers comprised of three tensors (W—input connections weights, U—recurrent connections weights and b—bias). Each of the LSTM layer tensors can be further deconstructed into four tensors: i (input), f (forget), c (cell state) and o (output) ones. For input tensor x at time t the LSTM layer output h t can be calculated as in Equations (2)–(6), with c 0 = 0 , h 0 = 0 , σ being the hard sigmoid activation function and the ∘ operator denoting the element-wise product.
i t = σ W i x t + U i h t 1 + b i
f t = σ W f x t + U f h t 1 + b f
c t = f t c t 1 + i t tanh W c x t + U c h t 1 + b c
o t = σ W o x t + U o h t 1 + b o
h t = o t tanh ( c t )
A dense layer can be described by two tensors; W—input connections weights and b—bias. The parameter ϕ  denotes the activation function—we have used softmax for classification tasks and linear activation for regression. A dense layer output can be calculated as follows:
o t = ϕ W x t + b .
For calculation of the total number of model parameters, the size of each tensor needs to be found. If k is the number of input features, m—output features, and n—LSTM cells, the tensor sizes can be calculated as in Equation (8):
size ( W L S T M ) = size ( W i ) + size ( W f ) + size ( W c ) + size ( W o ) = k · n + k · n + k · n + k · n = 4 · k · n , size ( U L S T M ) = size ( U i ) + size ( U f ) + size ( U c ) + size ( U o ) = n · n + n · n + n · n + n · n = 4 · n 2 , size ( b L S T M ) = size ( b i ) + size ( b f ) + size ( b c ) + size ( b o ) = n + n + n + n = 4 · n , size ( W D e n s e ) = n · m , size ( b D e n s e ) = m .
It is worth noting that in the case of multi-layer networks, the number of previous layer’s LSTM cells becomes the number of input features for the next layer. For example, a two-layer LSTM network, with n = [ 8 , 4 ] with k = 3 input features (data channels) and m = 2 output features (classes; e.g., anomaly/non-anomaly) would yield following values:
size ( W L S T M 1 ) = 4 · k · n 1 = 96 , size ( U L S T M 1 ) = 4 · n 1 2 = 256 , size ( b L S T M 1 ) = 4 · n 1 = 32 , size ( W L S T M 2 ) = 4 · n 1 · n 2 = 128 , size ( U L S T M 2 ) = 4 · n 2 2 = 64 , size ( b L S T M 2 ) = 4 · n 2 = 16 , size ( W D e n s e ) = n 2 · m = 8 , size ( b D e n s e ) = m = 2 ,
summing up to 384 parameters in first LSTM layer, 208 in the second and 10 in the dense layer, with the total number of model parameters equal to 602.
Applying the flow A of the presented methodology to the LSTM network means that the pruning and quantization parameters are selected globally for the model, and then applied for each of the W, U, and b tensors. For example, when ‘hist_amount’ pruning method was used and pruning fraction = 0.1 , it is 10 % of each tensor that was pruned, and not some small fraction in one layer and much higher in another.
Flow B, on the other hand, was designed to realize something akin to that second scenario. Its objective was, in our case, finding the best pruning and quantization parameters for each of the W, U, and b tensors individually, potentially resulting in lower resources consumption (e.g., when some of the tensors can be more aggressively compressed than in flow A) or better quality (e.g., retaining the high precision representation where it is needed and dropping it elsewhere). For the two-layer network mentioned above, this means that instead of finding the single pruning fraction value, it needs to optimize eight of them; similarly for the quantization bits.

2.4. Optimization Strategy—MO-CMA-ES

In this work, we deal with a range of relatively small number of parameters, but quite diverse. There were also several criteria (e.g., the sparsity of the model, model performance) which were simultaneously taken into account during the optimization process. This multiplicity makes it very challenging to define a single descriptive objective function. Lack of a well defined objective function or an inability to provide such may be prohibitive for using simple optimization methods or heuristics. Furthermore, the parameter space is non-convex and not differentiable; thus, the gradient-based optimization methods may not be employed. Utilization of naive grid or random search approaches does no lead to satisfactory results because those procedures do not account for a complex nature of the parameters space and do not improve in the process. Consequently, a very long examination time or a very dense grid of a parameters space would be required, which is prohibitive, especially for large models where the computing time of each instance is long.
This leaves us with black-box optimization techniques. In this work, we have decided to utilize evolutionary approach. There are many of such techniques [24], but all of them may be formulated as an algorithm that delivers a set of candidate solutions to evaluate the optimization task (see Algorithm 1).
Algorithm 1 Basic evolutionary strategy.
while true do
   token, solutionsampler.ask()▹ ask for candidate solution
   loss ← evaluate(solution)▹ evaluate the given solution
   sampler.update(token, loss)▹ give fitness result back to ES
   sampler.update(token, loss)
   if loss < REQUIRED_LOSS then
     break
   end if
end while
The straightforward approach of evolution strategy (ES) is based on using a standard distribution with initially defined mean and variance. In each step, the very best value from the previous step of the procedure and use it as a new mean. This approach has severe limitations and is prone to get stuck in a local minimum. There is also a whole range of genetic algorithms (GAs) which introduce mechanisms such as crossover recombination and mutations. GAs help to maintain a diversity of a set of candidate solutions and perform better than the simpler algorithms. A whole range of improved GAs was also developed, such as Enforced SubPopulations (ESP) [25], and NeuroEvolution of Augmenting Topologies (NEAT) [26], which use clustering of similar solutions to maintain better diversity of the population.
A limitation of simple ESs and GAs is taking a fixed value of standard deviation noise parameter. This premise affects the efficiency of the explore-and-exploit mechanism operating in the solution space. When an algorithm is close to the desired solution with high confidence, it should exploit it; on the other hand, in the exploration phase, the algorithm should penetrate as ample candidate solution space as possible.
The covariance matrix adaptation evolution strategy (CMA-ES) is a modern single objective ES, introduced for the first time in [27], and later improved in [28,29]. It turned out that it works very well in a wide range of problems in a continuous domain.
The CMA-ES uses a number of best solutions from the current generation to calculate both mean and standard deviation of the parameters being optimized. The change of the standard deviation value allows to adjust the size of the search space, i.e., whether algorithm focuses on exploitation or exploration, as can be seen in Figure 6. Those re-calculated values are then used to generate the candidate solutions for the next generation, with parameters sampled from a multivariate normal distribution.
One of the beneficial properties of CMA-ES is the rate at which good approximations of the global minimum can be found. It is also resistant to using the incorrect initial set of parameters due to its self-adaptive nature.
There is an extension of CMA-ES for multi-objective optimization denoted as MO-CMA-ES [30]. Since MO-CMA-ES operates on multiple objectives, it yields Pareto fronts as a result (Algorithm 2). The Pareto front is a set of results which cannot be improved any further i.e., improvement of any of the objectives can be made only at the expense of the others. The Pareto fronts are also used in the process of the next candidate solution selection.
A detailed description of CMA-ES and MO-CMA-ES is beyond the scope of this paper, however we encourage the reader to look into [24,27,28,29,30] for more information.
Algorithm 2 Multi-objective evolutionary strategy.
for step ← to max_steps do
   token, solutionsampler.ask()▹ ask for candidate solution
   loss ← evaluate(solution)▹ evaluate the given solution
   sampler.update(token, loss)▹ give fitness result back to ES
end for
resultssampler.results()
first_front ← get_first_pareto_front(results)
To optimize pruning and weights quantization parameters we used MO-CMA-ES provided by the chocolate package [31]. We optimized four basic parameters: pruning method, pruning fraction, quantization method, and quantization bit-width. The number of parameters increased to 2 + 2 L with the number of layers L when the individualized approach was used. Evaluated pruning methods are described in Appendix A, and quantization methods are explained in Appendix B.
We used three optimization criteria (designed for minimalization):
  • Quality score, where qual orig is the original model’s quality measure, preferably in [ 0 , 1 ] range, qual pq is the quality after weights pruning and quantization, and allowed _ drop = 0.01 is the allowed quality drop. If quality score < 1 , the pruned and quantized model’s quality is considered to be satisfactory.
    quality score = qual orig qual pq allowed drop .
    When using a quality measure that is designed to be minimized (such as root-mean-square error (RMSE)), the quality score is additionally negated.
  • Sparsity score, where N is the number of model weights, and w i is the i-th weight value.
    sparsity score = 1 1 N i = 0 N 1 ( w i = = 0 )
  • Used bits score, where N is the number of model weights, and bit-width ( w i ) is the i-th weight bit-width after quantization. Used bits score is adjusted to fall into [ 0 , 1 ) range, assuming the maximum allowed bit-width after quantization is 31 bit.
    used bits score = 1 N · 32 bit i = 0 N 1 bit-width ( w i ) .
As presented in Algorithm 2, the optimization was run for a fixed number of max steps, calculated according to the Equation (13). The number of parents used to generate the candidates was mu = 30 .
max steps = number of parameters number of optimization criterions mu 10 .

2.5. Mapping Tool

As mentioned in Introduction, there are many challenges associated with hybrid model mapping, such as inter-tool format translation, arbitrary precision emulation, and incorporation of pruning and quantization on all the processing levels. Rather than enumerating and presenting all of them, it is better to provide a set of requirements which a decent and useful framework should meet. They are based on our experience of many years of using high-level languages (HLLs) for hardware design such as OpenCL, MitrionC, ImpulseC, CataputC as well as DL models training. Primarily educative in terms of experience was our work [32], which led us to an idea and an architecture presented in this paper.
A high-level tool for mapping Machine Learning models to hardware, especially FPGAs should:
  • provide the ability to migrate, map and test using a single set of tests at all levels of the project description abstraction (from the meta description on the top layer, through the intermediate format up to HDL). This ability is especially important if there are changes in the notation of the data structure at particular levels of the description,
  • allow parametrizing modules on a high level of description,
  • provide a mechanism for arbitrary data representation and modification along with all the associated arithmetic operations,
  • enable of simulation at all the development levels, preferably using the same tests, or provide mechanisms which generate test-benches for hardware simulations,
  • come with a library of predefined DL modules comprising a set of basic application programming interfaces (APIs) for developing new custom elements,
  • include HDL generation back-end which preserves the original architecture of the model, so the debugging and analysis on the hardware level is facilitated.
We treated the directions presented above as guidelines in the process of designing our DL2HDL (see Supplementary Materials). The block diagram of the tool flow is presented in Figure 7.
In the first step of the process, a deep learning model was trained in Keras or PyTorch. Since the main flow is in PyTorch, a model trained or provided in Keras is converted to PyTorch. The conversion tool was embedded within the flow. The PyTorch was chosen because it is a dynamic-graph-based framework, which made it much easier for debugging and instrumenting the code. It was especially vital during the initial stages of development of the flow.
Once the DL model was trained, quantized and pruned, the three actions were taken:
  • appropriate components from the custom DL library are picked and embedded in the model,
  • MyHDL wrapper around the DL learning components was generated,
  • MyHDL test files were generated to be used for verification of the code this stage.
The custom library of the DL components was created along with a tool which populates a DL model with the elements from the library. Currently, the library contains the following components:
  • a set of activation functions: relu, sigmoid, tanh and softmax
  • a set of layers: linear, conv1D, conv2D,
  • LSTM,
  • maxpool.
All the layers were parameterizable, which enabled smooth integration to form a complete model. In addition to the layers, sample complete models based on recurrent neural network (RNN) and convolutional neural network (CNN) were available.
Next, once the model was compiled HDL was generated using the to_HDL conversion tool based on MyHDL package [33]. From this point in the flow, a standard FPGA flow was followed, which is composed of functional simulation, synthesis, and implementation. As the final step, a bitstream was generated and uploaded to FPGA.
It is worth noting that at any stage of this flow, it was possible to revert and redo the step before. This option was per the principles of proposed methodology because it allows for redoing the operations many times before the satisfactory latency is met.

2.6. FPGA System Architecture

Figure 8 presents the schematic of the network implemented using DL2HDL tool. All component are connected using AMBA AXI4-Stream interface [34], which facilitates easy modifications. Data transfer to and from the network is managed by receiver, and transmitter blocks. In our implementation, a receiver collected serial data using 32-bit wide interface and when full feature map is received, transmits it as one data word. For example, if input data for the LSTM is a set of values from four analog-to-digital converters (ADCs) then the output word width was 4 × ADC data width.
This approach allows for full unroll of operations in subsequent blocks. The transmitter works similarly but in the opposite direction. However, thanks to the modular approach and standard interface, receiver and transmitter blocks can be easily replaced to match the desired interface. LSTM layers work on a series of data, but the linear layer needs a single sample, and for that purpose, the flow control block was introduced. It counted the sequence samples and passed only the last one to linear layer; other connection schemes can also be implemented. Inside the LSTM, apart from an LSTM cell, additional registers were placed to ensure synchronization of passing data in temporal dimension, additional sequence counter control clearing and setting these registers to zero input at the beginning of each new sequence.
The LSTM cell was built according to the Equations (2)–(6). First, the linear operations were performed, and gates were concatenated for input and hidden state so that only two linear modules were required. Then the data was split for separate activations, and all element-wise operations were performed. Single data word contains a complete feature map; therefore, element-wise operations can be fully unrolled. As they execute relatively simple operations, additional registers were not necessary; as a result, element-wise operations do not introduce latency in terms of clock cycles, only indirectly in logic complexity between modules. However, during development, the tests showed that the linear modules have a large impact on final latency. Hyperbolic tangent was implemented as a linear approximation, which is further discussed in Appendix D, and hard sigmoid was implemented similarly.
In linear module operations are split for each output unit, then multiplication is fully unrolled. The results are accumulated using tree addition presented in Figure 9. Summation operation proved to be time-consuming in terms of logic complexity, and it is necessary to insert registers between summation levels for bigger layers. For modern Xilinx devices, it is enough to insert registers every two to three levels to bring logic complexity close to the rest of the design; this parameter can be easily changed. Multiplication results were in fixed point format; summation result was also a fixed point, which introduces the risk of overflow for narrow representations. This effect was mitigated by the distribution of results concentrated on both the positive and negative side of zero; however, to ensure proper operation data width need to be verified during a simulation on training data set. Components inside the LSTM cell were also using AXI4-Stream interfaces to communicate.
Summation in softmax function was implemented similarly as in the linear layer. Additionally, there is a choice between two exponent implementations: calculated approximation, and a look-up table. Look-up table implementation was significantly faster, but its size grows with data width, therefore for wider data approximation scheme should be selected. In most of our experiments, the look-up table proved to give better results.
We have noticed that using the same bit-width for data, weights, and activations representation is, in most cases, wholly sufficient and optimal. Using smaller bit-with may lead to overflow. On the other hand, using a larger bus size is sub-optimal in terms of resources consumption of an FPGA.

3. Results

To present and validate the methodology, we have examined three datasets using ’analysta’, our time series analysis framework (see Supplementary Materials). The first one is the International Airline Passengers data from the Time Series Data Library (TSDL) [35]. It was used in a toy example, depicting selected aspects of the methodology. The [IAP] tag was used in figures’ and tables’ captions for easier identification of the related results.
The second dataset contains PM2.5 pollution data of the US Embassy in Beijing in conjunction with meteorological data from Beijing Capital International Airport [36]. The model objective in this example was to predict the pollution value. The related results are marked with the [PM2.5] tag.
The third, most extensive use case was based on the experiments conducted in [17], which was focused on exploring the influence of history length and various data quantization schemes on the models’ performance. The data we used came from the post mortem (PM) database of European Organization for Nuclear Research (CERN) Large Hadron Collider (LHC), representing the state of the superconducting magnets. The figures and tables containing related results are marked with the [LHC] tag.
It may be beneficial to estimate and compare the resulting model size with original, uncompressed one to interpret the compression results. For model with N weights w i W , its approximate size after pruning and linear quantization can be calculated as follows:
compressed model size = i = 0 N 1 bit-width ( w i ) if w i < > 0 .
This value can then be compared with original size, calculated as N · 32 bit:
percentage of original model size = 100 % compressed model size N · 32 bit .

3.1. International Airline Passengers

To illustrate the selected aspects of the methodology, we used the International Airline Passengers dataset [35]. It contains the number of international airline passengers in thousands per month, collected between January 1949 and December 1960, and has 144 data points in total, first 92 of which we used for training, 23 for validation and the remaining 29 for testing. The history window length was set to 5, and batch size was = 1 .

3.1.1. Initial Conditions Analysis

The network we used contained n = 4 LSTM cells and a single dense unit, with a single input ( k = 1 ) and a single output feature ( m = 1 ). Total number of parameters, with tensor sizes calculated according to Equation (8), was 101. The uncompressed model memory usage, assuming 32 bit representation, was therefore 404 B. The hypothetical memory usage after extreme compression can be calculated according to Equation (1):
memory = 101 1 bit 0.05 5 bit 1 B .

3.1.2. Pruning/Quantization Optimization

The optimization was done according to flow A—finding per-model weights pruning and quantization parameters. Due to the small size of the original dataset, the optimization process could use it as a whole. The RMSE (see Equation (A14) in Appendix C) was used as a quality measure, resulting in a following quality score:
quality score = RMSE pq RMSE orig 0.01 .
Optimization was run for 3600 steps and resulted in 49 unique Pareto optimal solutions, four of which retained the required quality score < 1 . The results are shown in Table 1 and Figure 10a. Figure 10a shows that the best result results range 12.22% to 12.50% with size of 4 to 5 bits. It is worth noting that the biggest contribution came from quantization, and the sparsity level due to pruning was relatively low. This sparsity level resulted from a small size of the model, which cannot be pruned as effectively as large models.

3.1.3. Individualized Pruning and Quantization

The individualized weights pruning and quantization optimization (flow B) was run for 10,800 steps. Its aim was to find optimal pruning fraction and quantization bits for each of the W, U and b tensors. It resulted in 192 unique Pareto solutions, 52 of which retained the required quality. While the pruning fraction in each of those solutions was different, only 37 different values of quality score and sparsity score were yielded, with small values differences having no impact on the final result. Those 37 representative results are shown in the Table A2 (Appendix E) and Figure 10b.
It is worth noting that in this case, the individualized pruning and quantization led to much better results than the per model approach (flow A). This is reflected in Table A2, where the lowest compressed model size is 0.68% of the original. It is worth noting that for the best case in Table A2 sparsity is 78.85% and 1 to 3 bits are used for most of weights representation.

3.1.4. Pruning and Quantization with Retraining

For optimization with retraining, we have limited the range of the optimized parameters to the number of bits [ 4 , 31 ] and pruning fraction [ 0 , 0.5 ) . We have applied the retraining procedure using keras.optimizers.SGD (lr = 0.0001, momentum = 0.0, decay = 0.0, nesterov = False) and weights masking. The masking means that the model weights that were pruned were discarded from the training process in the next iteration. Optimization was run for 3600 steps and resulted in 44 unique Pareto optimal solutions, 30 of which retained the required quality score < 1 . In all of those 30 solutions, the ‘thq’ was selected as the quantization method, with the number of bits = 4 , and ‘simple’ pruning method was chosen. Similarly to the individualized optimization, the pruning fraction in each of those solutions was different, however only seven different values of quality score and sparsity score were yielded. Those seven representative results are shown in Table A3 (Appendix E) and Figure 10c. It can be seen that for this example, the retraining positively impacts the model compression limits.

3.2. Beijing PM2.5 Pollution

This dataset contains hourly readings of the PM2.5 concentration from the US Embassy in Beijing, combined with the meteorological data from Beijing Capital International Airport [36], and includes missing data. Each sample contains 13 attributes, including date of the reading, hour, PM2.5 concentration ( μ g / m 3 ), dew point ( ° C ), temperature ( ° C ), pressure ( h Pa ), combined wind direction, cumulated wind speed ( m s 1 ), cumulated hours of snow and cumulated hours of rain.
The combined wind direction is expressed as one of five broad categories:
  • northwest (NW), which includes W, WNW, NW, NNW, and N;
  • northeast (NE), which includes NNE, NE, and ENE;
  • southeast (SE), which includes E, ESE, SE, SSE, and S;
  • southwest (SW), which includes SSW, SW, and WSW;
  • calm and variable (CV).
The gaps in the data shorter than 12 h were interpolated. Longer gaps split the data into 37 variable-length series, containing 42,168 samples in total. Series were then assigned to training, validation and testing sets, maintaining roughly a 64-16-20 split. The model task was to predict the value of the PM2.5 concentration. For experiments, the history window length was set to 72, with batch size = 1024 .

3.2.1. Initial Conditions Analysis

The network we used contained 16 LSTM cells and a single dense unit, for a total of 1873 parameters. The hypothetical memory usage after extreme compression is:
memory = 1873 1 bit 0.05 94 bit 12 B .

3.2.2. Pruning/Quantization Optimization

Optimization was run for 3600 steps. Since the dataset is quite small, it was used whole during the optimization process. Similarly to the International Airline Passengers example, the RMSE was used in a quality score.
Optimization resulted in 165 unique Pareto optimal solutions, 39 of which retained the required quality score < 1 . For selected of those solutions, the hardware resources consumption and latency were simulated and presented in Table 2. The full results are shown in Table A4 (Appendix E) and Figure 11a. In terms of percentage of original model size, the best result for this dataset is comparable to the one achieved for International Airline Passengers (Section 3.1.2), but the Pareto front is much larger.

3.2.3. Individualized Pruning and Quantization

The individualized pruning and quantization optimization (flow B) was run for 10,800 steps. It resulted in 332 unique Pareto solutions, 11 of which retained the required quality. The results are presented in Table A5 (Appendix E) and Figure 11b.
In case of this dataset, the individualized pruning and quantization did not lead to as good results as applying the flow A. This inability to at least match the best per-model outcomes may indicate that the selected number of optimization steps was too low for the number of optimized parameters.

3.2.4. Pruning and Quantization with Retraining

For optimization with retraining, we have limited the range of the optimized parameters to the number of bits [ 4 , 31 ] and pruning fraction [ 0 , 0.5 ) . Optimization was run for 3600 steps and resulted in 111 unique Pareto optimal solutions, 40 of which retained the required quality score (<1). The results are presented in Table A6 (Appendix E) and Figure 11c. Adding the retraining operation yielded solutions with the slightly improved quality score; however, contrary to the example presented in Section 3.1.4, it does not seem to affect the model compression limits.

3.3. Superconducting Magnets

This case study was based on the experiments conducted in [17], which was focused on exploring the influence of history length and various data quantization schemes on the models’ performance. The data we used came from the PM database of CERN LHC, representing the state of the superconducting magnets. Four data channels were used: UDIFF (total voltage), URES (resistive voltage), IDCCT (current measured using Hall sensor), and IDIDT (time derivative of the electric current). Anomalies were marked using QUENCHTIME field as a start and until the end of series. Overall, 26 % of used samples were marked as anomalous, which allowed using the accuracy (see Equation (A15) in Appendix C) as one of the quality measures.
The currently used system can detect an anomaly (a quench) with a latency of 10 m s . Such a low latency is needed to start the shutdown procedure and safely discharge the magnet, without it being damaged. This system, however, requires manual adjustments for each magnet type and needs to be reworked for new devices that will be introduced in high-luminosity (HL) LHC phase. Our recent work concentrates on proposing an alternative solution, based on RNNs, that could become a part of the new protection device [16,17]. In order to meet the hard real-time requirements, the RNN-based model needs to be mapped to hardware, more specifically the FPGA. Also, the FPGA reconfigurability is a vital trait due to the necessary modifications caused by the change of the data’ parameters during the operational period as a result of normal working conditions and the elements degradation. Consequently, the model should be updated regularly with a newly trained version to maintain the highest performance.
While the work on designing the exact solution that will ensure the required quality is still ongoing, the research has reached the stage at which the actual hardware results are needed. The mapping flow was tested using a Keras model comprised of two LSTM layers, first with 64 cells and second with 32 cells, and a two-unit dense layer (for one-hot encoding). Total number of model parameters can be seen in Table 3.

3.3.1. Initial Conditions Analysis

The tested model comprises of two LSTM layers and a single dense layer. The exact tensors sizes for the used architecture can be seen in Table 3. Equation (1) was used along with the data in Table 3 to compute the critical amount of memory size, which is essential to proceed with the proposed procedures. The calculations are as follows:
memory = ( 17664 + 12416 + 66 ) 1 bit 0.05 1507 bit 188 B .
We also directly mapped the model to using 32-bit fixed-point precision without compression and it turned out that it exceeded available resources on the target FPGA, Xilinx Zynq UltraScale + MPSoC XCZU15EG. This result led us to the conclusion that the proposed methodology is essential in order to map the model to the FPGA.

3.3.2. Pruning/Quantization Optimization

To speed up the optimization process (done according to flow A), we have extracted the testing subset containing 8 % of original samples. The subset size was selected based on the incremental dataset boosting method. At first, mean and variance were calculated for a single batch with size = 16,384). Then, the dataset was expanded by another batch, with mean and variance calculated again. If they changed more than a selected threshold (in our case 1%) when compared to the previous values, the dataset was expanded by a single batch again. In the end, the quality measures for the subset were compared with original ones (as seen in Table 4), and similarity confirmed.
Optimization was run for 3600 steps, and resulted in 34 unique Pareto optimal solutions (Figure 12a), 14 of which retained the required accuracy (drop < 1 p . p . ). For those solutions, the quality score was validated using full test set and the hardware resources consumption and latency were simulated.
The simulation results are presented in Table 5. Different variants of quantization procedure were used along with different bit-width. Many of the solutions exceeded the resources’ capacity of the FPGA chip used for the experiments. However, the results which were obtained show that regardless of the procedure, the best 5 bit to 6 bit quantization leads to negligible accuracy drop and the best processing latency of a single chunk at the level of 210 ns.
We also run a short experiment with combining the sparsity_score and used_bits_score into a single loss value, it, however, yielded inferior results (out of 2400 optimization steps it generated 18 unique Pareto optimal solutions, only two of which retained the required accuracy).

3.3.3. Individualized Pruning and Quantization

The optimization, with pruning and quantization parameters separate for each of the W, U and b tensors, ran for 16,200 steps. It resulted in 110 Pareto solutions (Figure 12b), but only two of those retained the required accuracy (drop < 1 p . p . ), and further 12 results had drop < 2 p . p . The best results, presented in Table A7 (Appendix E), are slightly worse than the solutions found when applying flow A. This, in conjunction with the small number of results retaining the required quality may indicate, that the selected number of optimization steps was too low.

3.3.4. Pruning and Quantization with Retraining

Pruning and retraining can be considered as one of the most flexible compression schemes since it enables weights shaping after each iteration step. However, it is worth noting that optimization with retraining can also be very time consuming, e.g., in our case a single pruning-quantization-retraining-pruning-quantization step took 23 min , so the optimization running for 3600 steps was estimated to take nearly two months. Therefore, we decided to apply the retraining procedure only in conjunction with previously optimized parameters. The results are presented in Table 5 (in parentheses). For retraining, the full dataset was used, and in only in a few cases, the performance (accuracy) of the model improved. Based on those experiments, it can be seen that using the predefined pruning and quantization parameters, even previously optimized, does not guarantee a good starting point for the retraining.

3.3.5. Data Bucketization

We also ran the experiments for flow D, using the recursive_adaptive data bucketization algorithm. It maps the input space to a fixed number of bins in such a way that all the resulting, uneven bins have similar cardinality if possible. For more details, please see Section 2.1 and Appendix A of [17], and Section 4.2 of [16]. The tested model structure was the same (two LSTM layers, with 64 and 32 cells, respectively, and a two-unit dense layer), which allowed us to focus on the differences caused by the data bucketization itself. The training on bucketized data yielded results on par with the original dataset (see Table 4). Also, in this case, for optimization, a test subset of 8 % original size was used. Optimization was run for 3600 steps, and resulted in 42 unique Pareto optimal solutions, eight of which retained the required accuracy (Figure 13a).
The best results, presented in Table 6, show that data bucketization can be beneficial—the latency of the model is in a similar range as in Table 5 with quite low resources consumption.
Applying individualized pruning and quantization, with optimization running for 16,200 steps, yielded 12 results meeting the accuracy criterion (Figure 13b). The best results are shown in Table A8 (Appendix E). It is worth noting that individualized pruning and quantization (flow B) along with data bucketization, in this case, yield better results in terms model size after compression.

3.4. DL2HDL Comparison with Other Frameworks

To our best knowledge, the only high-level tool that can achieve comparable latency for neural network inference in FPGA is hls4ml [10]. This tool was designed to work in particle physics experiments, where response time is crucial. It provides similar functionality using a different approach.
The main difference between our flow and the hls4ml processing architecture is the number of procedure’s stages. In hls4ml, in the first stage, the model is created in one of the high-level DL frameworks, such as Keras or PyTorch, then it is mapped to Vivado HLS, and in the last step, the FPGA RTL structure is generated by the synthesis and implementation tool. Our DL2HDL tool skips the middle step and provides mapping directly from Python to HDL. It is worth noting that the number of conversion steps affects the flexibility of the tool and may a source of potential mapping challenges. Thus, we decided to simplify the flow when designing the DL2HDL.
Since at the time of this article submission the hls4ml support for recurrent neural networks was not yet available, we were not able to test it on network architectures examined in this work. However, it was possible to test the DL2HDL using the very similar network to the one presented in [10].
The tested architecture was a four-layer fully connected network, with ReLU as activation of the first three layers and softmax as output activation. Although we believe that softmax activation can be omitted in this application, we included it for a fair comparison. We used the same 16 bit wide fixed-point representation and pruned the network to the same number of parameters (1338). After HDL generation, the implementation was performed using Vivado software, for Xilinx Kintex Ultrascale xcku115-flvb2104-2-i with a target frequency of 200 MHz, as in the original experiment. Weights were randomly generated with uniform distribution.
Implementation results are summarized in Table 7. DPS usage and latency are on a similar level, although our implementation is slightly faster. Logic utilization, however, is significantly lower when using DL2HDL.
We also compared our flow with the LeFlow [8] tool-kit. In the setup, we used the results for dense_a and dense_b reported in the paper. They are single dense layers including bias and ReLU activation with a single input and 8 and 64 outputs respectively. Using DL2HDL, we have generated layers with the same parameters. Results are summarized in Table 8. Resources utilization is not fully comparable as authors in [8] performed tests on Altera Stratix IV EP4SGX290NF45C3, while our tests were done on Xilinx xczu15egffvc900-1. However, thanks to the full unroll of operations and weights hardcoded in logic, DL2HDL required significantly less time to infer through the layers.

4. Discussion

This paper proposes both methodology and its implementation tools. We did experiments to validate them, which revealed a series of application aspects related to the effectiveness of the steps and their recommended execution. We showed that the presented methodology and the tool could be successfully applied to IoT mapping scenarios for latency and resources consumption estimation and validation.
We proposed a method to estimate model size in Equation (15), which assumes that linear quantization is employed. Despite its simplicity, the method allows picking candidate results among the Pareto front solutions for further processing e.g., mapping to hardware.
Figure 10, Figure 11, Figure 12 and Figure 13 present the optimization results as a function of the estimated model size. Moving towards the origin of the coordinate system leads to a growth of the quality score (degradation of the model performance). In every model, there exist a core amount of resources which captures the essence of the underlying processed modeled by the neural network [37]. Once the critical resources are removed by pruning and quantization, the performance of the model starts to decline very fast. This degradation usually occurs around 5% to 10% of the original model size. We have tested several trendline models and discovered that, in general, the logarithmic trendline yielded good results in terms of R2 metric.
The per-model scheme (flow A) seems to yield satisfactory results in most of the tested cases. The solutions yielded by flow B seem to be inferior to the per-model approach while reaching them required more computation time. We believe, however, that the limiting factor was the selected number of optimization steps, calculated according to Equation (13). The individualized optimization, running for a sufficient number of steps, should be able to reach at least the same performance as the per-model one [37]. Also, when distributed implementation is at the premium, it may turn out that the individualized approach may allow for better optimization from the perspective of each computing node in the IoT network.
In the presented experiments, we limited our retraining setup to a single epoch of training, which does not take a full adventure of this procedure. Training for multiple epochs, especially taking into account loss function change to adjust learning rate, may lead to better results. It is also expected that applying regularization techniques (such as weight decay) during training or retraining process may lead to even better compression results [13,14]. While our setup accounts for this option in general, it should be extended with a series of meta-parameters to use retraining for multiple epochs properly. Careful selection of parameters, such as the number of epochs, learning rate adjustment schedule and dataset size, is vital because retraining, especially with a full dataset is very time consuming and may be counter-productive if not carefully implemented. Using a reduced dataset, possibly newly selected in each epoch, and introduction of sensitivity list for the model’s layers may significantly boost the effects of retraining procedure.
One of the possible compression flows for big models, not discussed in this work, is based on the idea of incremental pruning and quantization. In this flow, introducing the sensitivity list allows picking fragments of the model, which are pruning prone and should be addressed as first. Especially in conjunction with retraining, the sensitivity list should be updated quite often, since the profile of the model changes as the training progress. The process of refreshing of the sensitivity list by itself is also computationally demanding. Therefore, it should also be deliberately adjusted and implemented [38].
We applied bucketization in one of the experiments and achieved comparable results to using continuous data. Though, we noticed that the individualized scheme yielded better results with bucketization. Additionally, in sensors networks with stringent energy and latency budget, data transmission cost plays a critical role in the system. Bucketization considered as a form of a compression scheme, enables dynamic data stream modulation with graceful performance degradation.
Comparison of unstructured pruning applied to FPGA and GPGPU/CPU is quite challenging, since the latter platforms cannot directly benefit from DL models compression unless a dedicated data structuring scheme is implemented [39,40,41,42]. This scheme is essential to take advantage of sparse vector-matrix and matrix-matrix multiplication operations, which are much more efficient than their dense counterparts, provided the data is prepared properly. In contrast, FPGA-based solutions directly benefit from unstructured pruning and quantization as the underlying internal structure of the platforms is adaptable and reconfigurable. For illustrative purposes, in Table 9, we presented the comparison between inference times on different platforms.
There is a range of modifications which may be introduced to the proposed optimization routine based on MO-CMA-ES. One of the most impactful can be the improvement of the loss function, which reformulated may affect the performance of the optimization process. At the early stage of our experiments we made a simple, unsuccessful attempt to merge the sparsity score and used bits score into a single score; however, we believe that a more sophisticated combination may yield better results.
Multi-objective optimization is a quite complex operation; thus it is not easy to come up with a stopping criterion which on hand would allow the process to converge, and on the other hand, would not unnecessarily prolong the process. In this work, we chose to run the optimization for the arbitrary number of steps, which, as mentioned, turned out to be a limiting factor. Using another form of the stopping criterion could potentially lead to better results. An alternative could be developing a different way calculating the maximum number of steps.
An interesting observation in terms of FPGA resources consumption is irregularity of its distribution. For instance, in the course of the experiments, we found out that there is a component in the model, which contributed vastly to the overall resources consumption. Because of the non-hierarchical structure of the generated HDL code using MyHDL, it was hard to determine which section it was. Fortunately, after some examination we determined tanh activation function as the culprit (see Appendix D). As the next step, the module was re-implemented with tanh as a linear approximation of the original function rather than Taylor function expansion. This change significantly reduced the overall resources consumption (see Table A1). Not only it decreased the number of DPS blocks within FPGA, but also changed a profile of available resources to the other submodules within the implemented model, making it more balanced.
DL2HDL allows mapping DL models with arbitrary precision and sparsity to FPGA. It is a part of the whole presented flow. The design choices we made during the tool development have allowed reducing recurrent network inference latency to the scale of tens to hundreds of nanoseconds. The standard interface between individual elements facilitates future development and refactoring of network layers.
As future work, we plan to investigate all the described improvements of the optimization flow, as well as to conduct an in-depth analysis of basic neural operators such as exp and tanh in the context of model pruning and quantization.

5. Conclusions

The proposed mapping methodology and tools may be used in FPGA-based IoT devices for model compression. It can also be employed for distributed systems since its application in every node is independent and also can be ported across processing elements within the sensors network. The methodology also proposes steps to be taken in order to assess potential resources consumption of the system. It may be incorporated as a backbone element in a larger environment for a generation or ad-hoc reconfiguration of a network infrastructure.
Our DL2HDL tool matches or supersedes the state-of-the-art solutions in terms of the achieved latency, but the architecture is more uniform and allows mapping directly from Python to HDL. Our solution generates HDL models with three orders of magnitude lower than LeFlow [8] and comparable to hls4ml [10]. For the LSTM network composed of four cells, it reached as low latency as 27 ns with only 143 LUTs consumed of Xilinx Zynq UltraScale+ MPSoC XCZU15EG while for a three-layer network with 32 and 16 LSTM cells and a two-unit dense layer on top it achieved the latency of 210 ns.

Supplementary Materials

The developed time series analysis software ‘analysta’ is available online at https://bitbucket.org/maciekwielgosz/anomaly_detection. The DL2HDL mapping tool is available at https://bitbucket.org/maciekwielgoszteam/dl2hdl.

Author Contributions

Conceptualization, M.W.; data curation, M.W.; formal analysis, M.W.; investigation, M.W. and M.K.; methodology, M.W.; project administration, M.W.; resources, M.W. and M.K.; Software, M.W. and M.K.; Supervision, M.W.; validation, M.W.; visualization, M.W. and M.K.; writing—original draft, M.W. and M.K.; writing—review and editing, M.W.

Funding

This work was carried out as a part of the statutory tasks of Department of Electronics of AGH University of Science and Technology in Cracow (Poland), within the subsidy of Polish Ministry of Science and Higher Education. The APC was funded by Maciej Wielgosz.

Conflicts of Interest

The authors declare no conflict of interest.

Abbreviations

The following abbreviations are used in this manuscript:
ADCanalog-to-digital converter
APIapplication programming interface
ASICapplication-specific integrated circuit
CERNEuropean Organization for Nuclear Research
CMA-EScovariance matrix adaptation evolution strategy
CNNconvolutional neural network
CPUcentral processing unit
DLdeep learning
ESevolution strategy
FPGAfield-programmable gate array
GAgenetic algorithm
GPGPUgeneral-purpose graphics processing unit
HDLhardware description language
HLhigh-luminosity
HLLhigh-level language
IoTinternet of things
LHCLarge Hadron Collider
LSTMlong short-term memory
MO-CMA-ESmulti-objective covariance matrix adaptation evolution strategy
p.p.percentage point
PMpost mortem
RMSEroot-mean-square error
RNNrecurrent neural network
TSAtime series analysis

Appendix A. Pruning Methods

In experiments, three pruning methods were considered: simple, hist, and hist_amount. In the following equations, w W is used to denote the original value from the layer’s weights W.
The ‘simple’ pruning method sets all weights with an absolute value lower than a fraction f simple of maximal absolute weights’ value to zero:
simple ( w ) = 0 if | w | < f simple · max | min ( W ) | , | max ( W ) | , w otherwise .
In the ‘hist’ method, the weights’ values are divided into 2 12 equal bins. For each bin B with cardinality size ( B ) and lower bin edge value v B (see Figure A1), the score s B is calculated:
s B = size ( B ) · v B 8 3 .
Then, the average score value s ¯ is found and used to calculate a threshold, expressed as a fraction f hist of the average score. The threshold is then compared with each bin’s individual score s B . Finally, all the weights falling into the bins with scores below the threshold are set to zero:
hist ( w ) = 0 if w B : s B < f hist · s ¯ , w otherwise .
Figure A1. The ‘hist’ method concepts visualized using a histogram fragment.
Figure A1. The ‘hist’ method concepts visualized using a histogram fragment.
Sensors 19 02981 g0a1
The ‘hist_amount’ method zeroes weights until a target fraction f hist _ amount of layer weights W is changed (see Algorithm A1). The weights are divided into equal 2 10 bins. The procedure starts with bins containing weights with the lowest absolute value, i.e., the absolute value of lower edge of bin B 0 is smaller than the absolute value of the lower edge of bin B 1 , etc.
Algorithm A1 hist_amount pruning method
pruned ← 0▹ set the number of pruned weights to 0
i ← 0▹ used for bins indexing
while pruned < fhist_amount · size (W) dopruned is lower than the threshold
   for all wBi do▹ set all the weights in the bin Bi to 0
     w ← 0
   end for
   prunedpruned + size (Bi)▹ update the pruned weights amount
   ii + 1
end while
As can be seen in Figure A2, the effect of specific pruning method application depends on the weights distribution. For normally-distributed data, ‘hist’ and ‘hist_amount’ yield similar results, while for uniformly-distributed the similarities exist between ‘simple’ and ‘hist_amount’.
Figure A2. Application of different pruning methods for two tensors: t N —sampled from normal distribution, and t U —sampled from uniform distribution and scaled to (−1,1) range. The tensors length was 104. For each method, the pruning fraction = 0.2 .
Figure A2. Application of different pruning methods for two tensors: t N —sampled from normal distribution, and t U —sampled from uniform distribution and scaled to (−1,1) range. The tensors length was 104. For each method, the pruning fraction = 0.2 .
Sensors 19 02981 g0a2

Appendix B. Quantization Methods

For the presented experiments, we adopted common quantization methods. In the following equations, w W is used to denote the original value from layer’s weights W, and bits is the target number of bits. In the implementation, when taking the logarithm, a tiny constant is added to prevent errors related to taking the logarithm of zero.
It is worth emphasizing that using non-linear quantization procedures, such as presented in Equations (A10)–(A12), requires in-hardware mapping schemes. These schemes are supposed to encode unequally distributed quantized values to equally-spaced memory locations. The mapping is a LUT operation, which outputs quantized values for corresponding input data. In hardware FPGA implementation, it can be implemented by using BRAM or distributed RAM to store the mapping. Access to the memory should be fast with low latency since the mapping procedure will be used for all the operations which involve using quantized values. Fast access is essential since the internal arithmetic modules such as MACs units of multipliers work with evenly-distributed fixed-point numbers. Consequently, from a performance perspective, it is not recommended to keep the maps in an external memory such as SDRAM for which as access time is extended.
The linear quantization can be defined as follows:
linear ( w ) = s linear · clip w s linear + 1 2 , 2 bits 1 , 2 bits 1 1 ,
where scaling factor s linear , the number of bits needed to store the integral part int _ bits , and the clipping function clip ( a , min , max ) are defined as:
s linear = 1 2 bits 1 int _ bits ,
int _ bits = log 2 max ( W ) ,
clip ( a , min , max ) = min if a < min , a if min a max , max otherwise .
Another quantization method is based on finding the extreme values in the set:
minmax ( w ) = s minmax · w min ( W ) s minmax + 1 2 + min ( W ) ,
with scaling factor s minmax :
s minmax = max ( W ) min ( W ) 2 total 1 .
The ‘log’ versions of the above quantization methods can be described as:
log _ linear ( w ) = sgn ( w ) · e linear ln | w | , and
log _ minmax ( w ) = sgn ( w ) · e minmax ln | w | .
The last tested method is based on the hyperbolic tangent:
thq ( w ) = arctanh s thq · tanh ( w ) + 1 s thq + 1 2 1 ,
where scaling factor s thq :
s thq = 2 2 total 1 .

Appendix C. Quality Measures

The root-mean-square error used during experiments was calculated according to the formula:
RMSE = 1 N i = 1 N y r i y p i 2
where y r i and y p i are a time series and its predicted counterpart, respectively, and N is a dataset cardinality.
Given the values t and f representing, respectively, an amount of correctly and incorrectly classified samples, the accuracy can be defined as in (A15):
accuracy = t t + f .
An F score is calculated using two helper metrics, a recall (A16), also called sensitivity, and a precision (A17):
recall = tp tp + fn ,
precision = tp tp + fp ,
where:
  • tp —true positive—item correctly classified as an anomaly,
  • fp —false positive—item incorrectly classified as an anomaly,
  • fn —false negative—item incorrectly classified as a part of normal operation.
The β parameter controls the recall importance in relevance to the precision when calculating an F score:
F β = ( 1 + β 2 ) · recall · precision recall + β 2 · precision .
During the experiments, two β values were used, 1 and 2, to show the impact of the recall on the final score.
For the trendline models in Figure 10, Figure 11, Figure 12 and Figure 13, the R2 (coefficient of determination) score was calculated according to the following formula:
R 2 = 1 i = 1 N y r i y ^ r 2 i = 1 N y r i y p i 2

Appendix D. Tanh Error

Figure A3 presents an error introduced by tanh polynomial approximation using Taylor series according to Equation (A20). The result is clipped to range 1 to 1. Additionally, to ensure that the function is monotonous, the result is set to the closest limit value after the point where monotonicity is broken, this effect is visible for even number of polynomial degree.
tanh ( x ) = x x 3 3 + 2 x 5 15 17 x 7 315 + 62 x 9 2835
It may be noticed that an increase of polynomial degree leads to more accurate approximation for higher values. It is worth noting that for normalized model weights, the values are close to zero. Therefore, using lower polynomial degree may be enough to obtain an accurate result. On the other hand, incorporating more complex approximation leads to the massive growth of the resources consumption, as presented in Table A1.
Figure A3. Tanh error as function of x. Polynomial degree is indicated with different colors.
Figure A3. Tanh error as function of x. Polynomial degree is indicated with different colors.
Sensors 19 02981 g0a3
Table A1. Resources consumption for various tanh ( x ) approximation setups.
Table A1. Resources consumption for various tanh ( x ) approximation setups.
ImplementationBitsLUTFFDSP
#%#%#%
linear3268622.0120620.3000.00
series369,210108.1834,1175.00327392.77
linear1629480.8610380.1500.00
series26,7657.8497161.42208058.96
linear1222120.657820.1100.00
series16,8184.9372831.07108830.84
linear105480.166220.0900.00
series10,3723.0460670.8967219.05
linear83240.094940.0700.00
series45161.3228340.422567.26
linear61470.043980.0600.00
series17640.5213620.202567.26
As polynomial approximation requires a significant amount of resources, linear approximation was also implemented (Equation (A21)). Its accuracy is lower, however maximal error lies around 4–5 bit 0.5 LSB and resource requirements are substantially smaller.
tanh ( x ) = 1 x 1.5 0.25 x 0.25 1.5 x 0.5 x 0.5 x 0.5 0.25 x + 0.25 0.5 x 1.5 1 1.5 x

Appendix E. Detailed Optimization Results

This Appendix contains the detailed results for International Airline Passengers [IAP] (Table A2 and Table A3), Beijing PM2.5 Pollution [PM2.5] (Table A4, Table A5 and Table A6) and Superconducting Magnets [LHC] experiments (Table A7 and Table A8).
Table A2. [IAP] Results for individualized pruning and quantization.
Table A2. [IAP] Results for individualized pruning and quantization.
Pruning MethodPruning FractionQuantization MethodQuantization BitsQuality ScoreSparsity (%)% of Original Size; Equation (15)
LSTMDenseLSTMDense
WUbWbWUbWb
hist_amount0.45740.46440.60990.10760.9933thq201242−36.9147.607.55
hist_amount0.57200.88920.93880.22961thq29149−33.277.164.27
hist_amount0.54100.95810.12261thq210148−31.9378.133.03
hist0.468300.18610.84440.9846thq11265−31.4511.5413.46
hist_amount0.50250.934910.20320.9981thq24145−30.4677.642.32
simple00.35980.889901thq11144−28.9358.655.69
simple0.03970.43400.836301thq11145−28.8459.865.79
hist_amount0.71800.953110.21030.9678thq210159−27.7378.853.03
hist_amount0.636510.97940.06551thq2101411−27.0279.332.04
hist_amount0.594510.9950.10001thq2101410−27.0179.092.17
hist_amount0.6474110.13691thq291412−26.9879.331.92
hist_amount0.5797110.09521thq29149−26.9579.092.04
hist_amount0.56210.986410.10440.9983thq29148−26.9178.852.17
hist_amount0.5374110.06511thq28149−26.8578.852.04
hist_amount0.70210.990610.20201thq2161510−26.7979.812.66
simple0.01570.87500.90710.07460.0917thq21144−26.0268.752.51
simple0.01790.004610.08031thq11143−21.5857.938.01
simple00.015810.00100.9925thq11143−21.5558.417.83
hist0.50160.023900.06481log_linear11134−16.520.969.56
simple0010.03881thq11142−16.0757.696.13
simple00.017510.05861thq11142−16.0558.415.94
simple00.4841100.9919thq51145−15.3269.234.76
hist_amount0.7693110.18150.9834thq39259−11.0079.811.83
simple00.7829100.0960thq21174−7.8471.884.30
hist_amount0.5649110.10790.8284thq252111−5.7779.090.90
simple00.875610.02300.0249thq11174−5.6672.603.90
simple0110.01500.0955thq11153−4.3172.842.75
simple0.00800.45090.899701thq11144−3.7964.184.80
simple00.684710.27210thq11152−3.0671.633.03
simple00.8897100.1217thq11152−2.9872.602.78
simple00.9967100.1295thq11152−1.9872.842.72
hist_amount0.549910.99800.12030.8135thq231110−1.2978.850.68
simple00.937210.00650.0953thq11142−0.7172.842.23
hist_amount0.310400.06040.06771log_linear11131−0.3720.191.73
simple00.92910.97530.04930thq11141−0.3572.602.23
simple0110.03710.046thq111410.4372.842.20
Table A3. [IAP] Results for pruned and quantized model with single retraining epoch added.
Table A3. [IAP] Results for pruned and quantized model with single retraining epoch added.
PruningQuantizationQuality ScoreSparsity (%)% of Original Size; Equation (15)
MethodFractionMethodBits
simple0.3143thq4−32.6137.266.31
simple0.3276thq4−31.2441.116.19
simple0.3488thq4−29.7241.356.06
simple0.3611thq4−20.5245.435.82
simple0.4671thq4−18.2347.604.70
simple0.4682thq4−16.3548.084.46
simple0.4770thq4−1.4448.324.33
Table A4. [PM2.5] Results for pruned and quantized model.
Table A4. [PM2.5] Results for pruned and quantized model.
PruningQuantizationQuality ScoreSparsity (%)% of Original Size; Equation (15)
MethodFractionMethodBits
simple0.0116linear10−0.024.6330.07
simple0.0346linear31−0.0213.6386.79
simple0.0312linear15−0.0113.4642.30
simple0.0378thq31−0.0114.7586.01
simple0.0380log_linear21−0.0114.7558.27
simple0thq9−0.01028.13
simple0.0422linear31−0.0115.9185.08
simple0.0405linear14−0.0114.9538.52
hist_amount0.0744linear80.017.3823.17
simple0.0204linear130.019.8338.04
hist0log_linear70.01021.88
hist0.0144thq130.0210.5636.94
simple0.0294linear100.0411.4828.40
simple0.0218linear80.079.9523.30
simple0.0216linear70.129.9520.39
hist0.0526linear110.2314.6629.47
hist0.0667linear90.3315.9023.77
hist_amount0.1135thq70.3411.1819.39
simple0linear60.34018.75
simple0.0237linear60.3410.0317.42
hist0.0924linear110.3719.2228.26
hist0.1153linear160.4619.6240.36
hist0.1121log_linear130.4719.6032.84
hist0.1145linear80.5219.6220.18
simple0.0596linear310.5320.7380.74
simple0.0675log_linear170.5521.3343.08
simple0.0652linear130.5621.1333.25
simple0.0862linear190.5626.3045.14
simple0.0863log_linear180.5626.3042.77
simple0.0625linear100.6120.9125.83
simple0.0874log_linear160.6326.4037.83
hist0.2085thq90.6522.6521.43
hist0.1185linear50.6519.7012.57
hist0.2323linear140.7322.9132.91
hist0.2074linear80.8022.6519.05
simple0.0786linear70.8324.9317.00
simple0.0879linear180.8527.3742.44
simple0.0908linear180.9928.5041.95
simple0.0811linear130.9925.1331.30
Table A5. [PM2.5] Results for individualized pruning and quantization.
Table A5. [PM2.5] Results for individualized pruning and quantization.
Pruning MethodPruning FractionQuantization MethodQuantization BitsQuality ScoreSparsity (%)% of Original Size; Equation (15)
LSTMDenseLSTMDense
WUbWbWUbWb
simple00001log_linear21273131240077.22
simple0000.03840.9334thq23151315310056.94
hist000.40370.17770.5768thq1091018200.1317.4329.45
hist0.016700.12390.18581thq1521610110.1315.5854.29
hist00.01970.518900.4907thq8597180.2420.8118.76
hist0.10920.22500.37930.18910.7621thq147710260.3923.1524.44
hist0.101300.76070.05421thq87418290.6522.9921.25
hist0.12330.24040.50940.23011thq81458210.7025.2226.54
hist0.15450.226610.50530.9034thq99421300.7228.0521.46
hist000.65680.29330.8720thq813410290.7821.1033.05
hist0.02770210.70450.09770.9789thq59411180.9922.7821.08
Table A6. [PM2.5] Results for pruned and quantized model with single retraining epoch added.
Table A6. [PM2.5] Results for pruned and quantized model with single retraining epoch added.
PruningQuantizationQuality ScoreSparsity (%)% of Original Size; Equation (15)
MethodFractionMethodBits
simple0.0115linear15−0.044.6345.10
simple0.0118log_linear13−0.034.6439.06
hist_amount0.0734linear31−0.037.3789.84
hist_amount0.0732thq19−0.037.3755.06
hist_amount0.0503thq9−0.031.4527.55
hist_amount0.0722log_linear12−0.037.3434.82
hist_amount0.0767linear13−0.037.4837.50
hist_amount0.0527thq9−0.031.6927.30
hist_amount0.0831linear31−0.029.4388.91
hist_amount0.0396thq9−0.022.7728.06
simple0.0369log_linear22−0.0214.6861.23
simple0.0177log_linear19−0.017.7656.20
simple0.0159linear9−0.016.7226.76
simple0log_linear70.010.0021.88
simple0linear80.021.4324.51
hist_amount0.1189log_linear110.0211.3030.32
hist_amount0.0080linear80.022.3524.49
hist0.0405log_linear210.0514.2557.29
hist_amount0.1085thq80.124.5722.42
hist0.0523thq160.1314.7942.63
hist0.0522log_linear180.1414.9447.66
hist_amount0.0104thq70.170.9221.86
hist0.1171log_linear220.1819.8055.06
hist0.1020log_linear210.2019.4753.36
hist_amount0.0134linear70.205.5521.03
hist0.2323thq270.2423.1162.84
simple0.0430thq150.2517.7941.04
hist0.2298log_linear260.2723.0860.60
hist0.2331log_linear260.2723.1960.25
hist0.2140log_linear180.3023.5241.02
simple0linear60.3210.1317.35
simple0.0491thq100.3718.1826.91
simple0.0838linear310.4326.1874.12
simple0.0676linear90.4322.4122.63
hist_amount0.0318thq50.531.8315.61
simple0.0911linear220.6828.5651.13
simple0.0917linear270.6928.5862.66
simple0.0779linear160.8024.0038.95
simple0.0943linear260.8728.7859.73
simple0.0953linear310.9828.8371.07
Table A7. [LHC] Results for model trained on continuous data with individualized pruning and quantization applied.
Table A7. [LHC] Results for model trained on continuous data with individualized pruning and quantization applied.
TensorPruningQuantizationAccuracy Drop (p.p.)Sparsity (%)% of Original Size; Equation (15)
MethodFractionMethodBitsTensorModel
W 1 hist0.3399log_minmax310.781331.9318.1620.73
U 1 0.9195539.48
b 1 030
W 2 0.45972226.43
U 2 0.12321616.36
b 2 0.4078740.63
W D 0.74521315.63
b D 0.9012310
W 1 hist0.3428linear310.319832.0322.9421.88
U 1 0.9289439.52
b 1 0.0007410.55
W 2 0.55872029.76
U 2 0.05721712.18
b 2 0.4647740.63
W D 0.81081315.63
b D 0.8357310
Table A8. [LHC] Results for model trained on bucketized data with individualized pruning and quantization applied.
Table A8. [LHC] Results for model trained on bucketized data with individualized pruning and quantization applied.
TensorPruningQuantizationAccuracy Drop (p.p.)Sparsity (%)% of Original Size; Equation (15)
MethodFractionMethodBitsTensorModel
W 1 simple0.6777linear16−0.68602.1582.629.69
U 1 0.0060280
b 1 03199.61
W 2 0.98682263.00
U 2 0.17822790.41
b 2 0.2978198.44
W D 0.96262395.31
b D 0.2765280
W 1 simple0.7577linear18−0.6787081.4411.71
U 1 0260
b 1 02999.61
W 2 0.96012457.53
U 2 0.15763091.14
b 2 0.3075195.31
W D 0.90112396.88
b D 0.3396250
W 1 simple0.6342linear19−0.4858080.6410.40
U 1 0270
b 1 02899.61
W 2 12672.47
U 2 0.21783182.57
b 2 0.2371186.72
W D 0.83182295.31
b D 0.4590210
W 1 simple0.7174linear21−0.202618.8577.688.96
U 1 0.0498290
b 1 02886.72
W 2 0.78472168.87
U 2 0.20143088.28
b 2 0.2786198.44
W D 0.96752296.88
b D 0.3493210
W 1 simple0.5817linear27031.9373.8414.33
U 1 0.0861265.98
b 1 0.01172287.11
W 2 0.79332448.36
U 2 0.12793186.57
b 2 0.2644188.28
W D 0.84372593.75
b D 0.4712200
W 1 simple0.4912linear260.3418 73.5914.14
U 1 0.0046281.66
b 1 0260
W 2 0.76741583.98
U 2 0.20063168.66
b 2 0.0967144.58
W D 12899.22
b D 0.12402787.50
W 1 hist0.7914thq310.4004051.7435.14
U 1 03117.44
b 1 0.19831071.48
W 2 0.9911316.18
U 2 0.01153045.43
b 2 1164.84
W D 12217.19
b D 0.968510
W 1 hist0.8226thq310.5737051.7435.43
U 1 02917.61
b 1 0.20311071.48
W 2 0.9073316.01
U 2 0.01063145.29
b 2 0.9923164.84
W D 12017.19
b D 0.995610
W 1 hist0.8290thq310.688517.7751.2335.39
U 1 0.06522918.06
b 1 0.21881071.48
W 2 0.9167300
U 2 03044.97
b 2 0.9700164.84
W D 12117.19
b D 0.978810
W 1 hist1log_linear310.7007048.4130.85
U 1 03110.40
b 1 0.0634369.53
W 2 0.75042615.26
U 2 0.11473133.79
b 2 0.4999155.47
W D 0.54761917.19
b D 0.497810
W 1 hist0.8802thq280.8643048.3337.87
U 1 0318.03
b 1 0.0369171.48
W 2 0.8672300
U 2 03026.93
b 2 0.3251161.72
W D 0.90571817.19
b D 0.573410
W 1 hist1thq310.8643046.8939.88
U 1 0310
b 1 0171.48
W 2 1310
U 2 03123.07
b 2 0.2392160.16
W D 0.75072317.19
b D 0.521410

References

  1. Guo, K.; Zeng, S.; Yu, J.; Wang, Y.; Yang, H. A Survey of FPGA-Based Neural Network Accelerator. arXiv 2017, arXiv:1712.08934. [Google Scholar]
  2. He, Y.; Lin, J.; Liu, Z.; Wang, H.; Li, L.J.; Han, S. AMC: AutoML for Model Compression and Acceleration on Mobile Devices. arXiv 2018, arXiv:1802.03494. [Google Scholar]
  3. Garcia Lopez, P.; Montresor, A.; Epema, D.; Datta, A.; Higashino, T.; Iamnitchi, A.; Barcellos, M.; Felber, P.; Riviere, E. Edge-centric Computing: Vision and Challenges. SIGCOMM Comput. Commun. Rev. 2015, 45, 37–42. [Google Scholar] [CrossRef]
  4. Han, S.; Mao, H.; Dally, W.J. Deep Compression: Compressing Deep Neural Network with Pruning, Trained Quantization and Huffman Coding. arXiv 2015, arXiv:1510.00149v5. [Google Scholar]
  5. TensorFlow Lite. Available online: https://www.tensorflow.org/lite/ (accessed on 17 January 2019).
  6. Core ML. Available online: https://developer.apple.com/documentation/coreml (accessed on 17 January 2019).
  7. Azure IoT Edge. Available online: https://azure.microsoft.com/en-us/services/iot-edge/ (accessed on 17 January 2019).
  8. Noronha, D.H.; Salehpour, B.; Wilton, S.J.E. LeFlow: Enabling Flexible FPGA High-Level Synthesis of Tensorflow Deep Neural Networks. arXiv 2018, arXiv:1807.05317. [Google Scholar]
  9. Venieris, S.I.; Kouris, A.; Bouganis, C.S. Toolflows for Mapping Convolutional Neural Networks on FPGAs: A Survey and Future Directions. arXiv 2018, arXiv:1803.05900. [Google Scholar] [CrossRef]
  10. Duarte, J.; Han, S.; Harris, P.; Jindariani, S.; Kreinar, E.; Kreis, B.; Ngadiuba, J.; Pierini, M.; Rivera, R.; Tran, N.; et al. Fast inference of deep neural networks in FPGAs for particle physics. J. Instrum. 2018. [Google Scholar] [CrossRef]
  11. Umuroglu, Y.; Fraser, N.J.; Gambardella, G.; Blott, M.; Leong, P.; Jahre, M.; Vissers, K. FINN: A Framework for Fast, Scalable Binarized Neural Network Inference. arXiv 2016, arXiv:1612.07119. [Google Scholar] [CrossRef]
  12. Wielgosz, M.; Jamro, E.; Wiatr, K. Highly Efficient Twin Module Structure of 64-Bit Exponential Function Implemented on SGI RASC Platform. Comput. Inform. 2009, 28, 127–137. [Google Scholar]
  13. Han, S.; Pool, J.; Tran, J.; Dally, W.J. Learning both Weights and Connections for Efficient Neural Networks. arXiv 2015, arXiv:1506.02626. [Google Scholar]
  14. Dong, X.; Chen, S.; Pan, S.J. Learning to Prune Deep Neural Networks via Layer-wise Optimal Brain Surgeon. arXiv 2017, arXiv:1705.07565. [Google Scholar]
  15. Liu, Z.; Sun, M.; Zhou, T.; Huang, G.; Darrell, T. Rethinking the Value of Network Pruning. International Conference on Learning Representations. arXiv 2019, arXiv:1810.05270v2. [Google Scholar]
  16. Wielgosz, M.; Mertik, M.; Skoczeń, A.; De Matteis, E. The model of an anomaly detector for HiLumi LHC magnets based on Recurrent Neural Networks and adaptive quantization. Eng. Appl. Artif. Intell. 2018, 74, 166–185. [Google Scholar] [CrossRef]
  17. Wielgosz, M.; Skoczeń, A.; De Matteis, E. Protection of Superconducting Industrial Machinery Using RNN-Based Anomaly Detection for Implementation in Smart Sensor. Sensors 2018, 18, 3933. [Google Scholar] [CrossRef] [PubMed]
  18. Shawahna, A.; Sait, S.M.; El-Maleh, A. FPGA-Based Accelerators of Deep Learning Networks for Learning and Classification: A Review. IEEE Access 2019, 7, 7823–7859. [Google Scholar] [CrossRef]
  19. Wang, E.; Davis, J.J.; Zhao, R.; Ng, H.C.; Niu, X.; Luk, W.; Cheung, P.Y.K.; Constantinides, G.A. Deep Neural Network Approximation for Custom Hardware: Where We’ve Been, Where We’re Going. arXiv 2019, arXiv:1901.06955. [Google Scholar] [CrossRef]
  20. Sheng, T.; Feng, C.; Zhuo, S.; Zhang, X.; Shen, L.; Aleksic, M. A Quantization-Friendly Separable Convolution for MobileNets. arXiv 2019, arXiv:1803.08607. [Google Scholar]
  21. Jung, S.; Son, C.; Lee, S.; Son, J.; Kwak, Y.; Han, J.J.; Hwang, S.J.; Choi, C. Learning to Quantize Deep Networks by Optimizing Quantization Intervals with Task Loss. arXiv 2018, arXiv:1808.05779. [Google Scholar]
  22. Li, H.; De, S.; Xu, Z.; Studer, C.; Samet, H.; Goldstein, T. Training Quantized Nets: A Deeper Understanding. arXiv 2017, arXiv:1706.02379. [Google Scholar]
  23. Rastegari, M.; Ordonez, V.; Redmon, J.; Farhadi, A. XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks. arXiv 2016, arXiv:1603.05279. [Google Scholar]
  24. Ha, D. A Visual Guide to Evolution Strategies. Available online: http://blog.otoro.net/2017/10/29/visual-evolution-strategies/ (accessed on 9 June 2019).
  25. Gomez, F.; Miikkulainen, R. Incremental Evolution of Complex General Behavior. Adapt. Behav. 1997, 5, 317–342. [Google Scholar] [CrossRef]
  26. Stanley, K.O.; Miikkulainen, R. Evolving Neural Networks Through Augmenting Topologies. Evol. Comput. 2002, 10, 99–127. [Google Scholar] [CrossRef] [PubMed]
  27. Hansen, N.; Ostermeier, A. Adapting arbitrary normal mutation distributions in evolution strategies: the covariance matrix adaptation. In Proceedings of the IEEE International Conference on Evolutionary Computation, Nagoya, Japan, 20–22 May 1996; pp. 312–317. [Google Scholar] [CrossRef]
  28. Hansen, N.; Müller, S.D.; Koumoutsakos, P. Reducing the Time Complexity of the Derandomized Evolution Strategy with Covariance Matrix Adaptation (CMA-ES). Evol. Comput. 2003, 11, 1–18. [Google Scholar] [CrossRef] [PubMed]
  29. Auger, A.; Hansen, N. A restart CMA evolution strategy with increasing population size. In Proceedings of the 2005 IEEE Congress on Evolutionary Computation, Edinburgh, Scotland, UK, 2–5 September 2005; Volume 2, pp. 1769–1776. [Google Scholar] [CrossRef]
  30. Igel, C.; Hansen, N.; Roth, S. Covariance Matrix Adaptation for Multi-objective Optimization. Evol. Comput. 2007, 15, 1–28. [Google Scholar] [CrossRef] [PubMed]
  31. NovaSyst chocolate.MOCMAES. Available online: https://chocolate.readthedocs.io/api/search.html#chocolate.MOCMAES (accessed on 4 July 2019).
  32. Wróbel, K.; Pietroń, M.; Wielgosz, M.; Karwatowski, M.; Wiatr, K. Convolutional Neural Network compression for Natural Language Processing. arXiv 2018, arXiv:1805.10796. [Google Scholar]
  33. MyHDL. Available online: http://www.myhdl.org/ (accessed on 4 July 2019).
  34. AMBA AXI4-Stream Protocol Specification. Available online: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ihi0051a/index.html (accessed on 4 July 2019).
  35. Hyndman, R.; Yang, Y. tsdl: Time Series Data Library. v0.1.0. Available online: https://pkg.yangzhuoranyang.com/tsdl/ (accessed on 31 May 2019).
  36. Liang, X.; Zou, T.; Guo, B.; Li, S.; Zhang, H.; Zhang, S.; Huang, H.; Chen, S.X. Assessing Beijing’s PM2.5 pollution: severity, weather impact, APEC and winter heating. Proc. R. Soc. A Math. Phys. Eng. Sci. 2015, 471, 20150257. [Google Scholar] [CrossRef]
  37. Frankle, J.; Carbin, M. The Lottery Ticket Hypothesis: Training Pruned Neural Networks. arXiv 2018, arXiv:1803.03635. [Google Scholar]
  38. Marculescu, D.; Stamoulis, D.; Cai, E. Hardware-Aware Machine Learning: Modeling and Optimization. arXiv 2018, arXiv:1809.05476. [Google Scholar]
  39. Chen, X. Escort: Efficient Sparse Convolutional Neural Networks on GPUs. arXiv 2018, arXiv:1802.10280. [Google Scholar]
  40. Wen, W.; Wu, C.; Wang, Y.; Chen, Y.; Li, H. Learning Structured Sparsity in Deep Neural Networks. arXiv 2016, arXiv:1608.03665. [Google Scholar]
  41. Yu, J.; Lukefahr, A.; Palframan, D.; Dasika, G.; Das, R.; Mahlke, S. Scalpel: Customizing DNN pruning to the underlying hardware parallelism. In Proceedings of the 2017 ACM/IEEE 44th Annual International Symposium on Computer Architecture (ISCA), Toronto, ON, Canada, 24–28 June 2017; pp. 548–560. [Google Scholar] [CrossRef]
  42. Yao, Z.; Cao, S.; Xiao, W.; Zhang, C.; Nie, L. Balanced Sparsity for Efficient DNN Inference on GPU. arXiv 2018, arXiv:1811.00206. [Google Scholar]
Figure 1. Data flow and processing stages in a standard system setup.
Figure 1. Data flow and processing stages in a standard system setup.
Sensors 19 02981 g001
Figure 2. Constrains and demands for Deep Learning models compression.
Figure 2. Constrains and demands for Deep Learning models compression.
Sensors 19 02981 g002
Figure 3. Simplified data flow during inference; fl ( m , e ) denotes a number in floating-point notation, with m bits for mantissa and e bits for exponent; fx ( i , f ) denotes a number in fixed-point notation, with i bits for integral part and f bits for fractional. In the simplest case m 0 = m 1 = = m k , e 0 = e 1 = = e k , i 0 = i 1 = = i n and f 0 = f 1 = = f n , however those values can be arbitrary chosen to achieve the best resources utilization.
Figure 3. Simplified data flow during inference; fl ( m , e ) denotes a number in floating-point notation, with m bits for mantissa and e bits for exponent; fx ( i , f ) denotes a number in fixed-point notation, with i bits for integral part and f bits for fractional. In the simplest case m 0 = m 1 = = m k , e 0 = e 1 = = e k , i 0 = i 1 = = i n and f 0 = f 1 = = f n , however those values can be arbitrary chosen to achieve the best resources utilization.
Sensors 19 02981 g003
Figure 4. Strategies for mapping a pre-trained model.
Figure 4. Strategies for mapping a pre-trained model.
Sensors 19 02981 g004
Figure 5. Advanced strategies for model mapping.
Figure 5. Advanced strategies for model mapping.
Sensors 19 02981 g005
Figure 6. Sample multi-objective covariance matrix adaptation evolution strategy phases. (a) Explore—algorithm samples the whole search space; (b) exploit—algorithm starts to converge to the best solutions.
Figure 6. Sample multi-objective covariance matrix adaptation evolution strategy phases. (a) Explore—algorithm samples the whole search space; (b) exploit—algorithm starts to converge to the best solutions.
Sensors 19 02981 g006
Figure 7. DL2HDL flow.
Figure 7. DL2HDL flow.
Sensors 19 02981 g007
Figure 8. Field-programmable gate array (FPGA) network implementation schematic. N—bit width, M—# of elements in a feature map.
Figure 8. Field-programmable gate array (FPGA) network implementation schematic. N—bit width, M—# of elements in a feature map.
Sensors 19 02981 g008
Figure 9. Summation scheme in linear layer.
Figure 9. Summation scheme in linear layer.
Sensors 19 02981 g009
Figure 10. [IAP] Unique first Pareto front results. (a) Flow A: per-model pruning and quantization. trendline ( x ) = 89.1 48.2 ln x ; (b) Flow B: individualized pruning and quantization. trendline ( x ) = 275 74 ln x ; (c) Flow C-A: pruning and quantization with single retraining epoch. trendline ( x ) = 320 109 ln x .
Figure 10. [IAP] Unique first Pareto front results. (a) Flow A: per-model pruning and quantization. trendline ( x ) = 89.1 48.2 ln x ; (b) Flow B: individualized pruning and quantization. trendline ( x ) = 275 74 ln x ; (c) Flow C-A: pruning and quantization with single retraining epoch. trendline ( x ) = 320 109 ln x .
Sensors 19 02981 g010
Figure 11. [PM2.5] Unique first Pareto front results. (a) Flow A: per-model pruning and quantization. trendline ( x ) = 6.6 12 ln x ; (b) flow B: individualized pruning and quantization. trendline ( x ) = 4.65 8.13 ln x ; (c) flow C-A: pruning and quantization with single retraining epoch. trendline ( x ) = 5.87 9.04 ln x .
Figure 11. [PM2.5] Unique first Pareto front results. (a) Flow A: per-model pruning and quantization. trendline ( x ) = 6.6 12 ln x ; (b) flow B: individualized pruning and quantization. trendline ( x ) = 4.65 8.13 ln x ; (c) flow C-A: pruning and quantization with single retraining epoch. trendline ( x ) = 5.87 9.04 ln x .
Sensors 19 02981 g011
Figure 12. [LHC] Unique first Pareto front results for model trained on continuous data. (a) Flow A: per-model pruning and quantization. trendline ( x ) = 0.364 1.63 ln x ; (b) flow B: individualized pruning and quantization. trendline ( x ) = 1.02 1.81 ln x .
Figure 12. [LHC] Unique first Pareto front results for model trained on continuous data. (a) Flow A: per-model pruning and quantization. trendline ( x ) = 0.364 1.63 ln x ; (b) flow B: individualized pruning and quantization. trendline ( x ) = 1.02 1.81 ln x .
Sensors 19 02981 g012
Figure 13. [LHC] Unique first Pareto front results for model trained on bucketized data. (a) Flow D-A: per-model pruning and quantization. trendline ( x ) = 6.16 1.19 ln x ; (b) Flow D-B: individualized pruning and quantization. trendline ( x ) = 1.42 2.01 ln x .
Figure 13. [LHC] Unique first Pareto front results for model trained on bucketized data. (a) Flow D-A: per-model pruning and quantization. trendline ( x ) = 6.16 1.19 ln x ; (b) Flow D-B: individualized pruning and quantization. trendline ( x ) = 1.42 2.01 ln x .
Sensors 19 02981 g013
Table 1. [IAP] Results for pruned and quantized model. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip.
Table 1. [IAP] Results for pruned and quantized model. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip.
PruningQuantizationQuality ScoreSparsity (%)% of Original Size; Equation (15)#LUT#DSPLatency (ns)
MethodFractionMethodBits
simple0thq4−27.08012.50143 (0.04%)0 (0%)27
hist_amount0.1916linear5−8.5223.0812.38427 (0.13%)0 (0%)37
hist_amount0.2379thq5−2.5423.3212.22403 (0.12%)0 (0%)36
simple0.1286thq130.8927.6430.571634 (0.48%)85 (2.41%)111
Table 2. [PM2.5] Selected results for pruned and quantized model. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip. Full results are available in Table A4.
Table 2. [PM2.5] Selected results for pruned and quantized model. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip. Full results are available in Table A4.
PruningQuantizationQuality ScoreSparsity (%)% of Original Size; Equation (15)#LUT#DSPLatency (ns)
MethodFractionMethodBits
simple0.0312linear15−0.0113.4642.3021,125 (6.19%)1559 (44.19%)110
simple0.0380log_linear21−0.0114.7558.2736,393 (10.66%)1634 (46.32%)132
simple0.0237linear60.3410.0317.425422 (1.59%)0 (0%)54
hist0.0924linear110.3719.2228.2618,886 (5.53%)655 (18.57%)101
simple0.0596linear310.5320.7380.7446,441 (13.61%)3178 (90.08%)184
simple0.0675log_linear170.5521.3343.0823,024 (6.75%)1499 (42.49%)113
simple0.0862linear190.5626.3045.1424,703 (7.24%)1424 (40.36%)120
simple0.0625linear100.6120.9125.8327,095 (7.94%)0 (0%)84
simple0.0874log_linear160.6326.4037.8320,003 (5.86%)1382 (39.17%)111
hist0.2085thq90.6522.6521.4317,697 (5.19%)0 (0%)70
hist0.1185linear50.6519.7012.57972 (0.28%)0 (0%)57
hist0.2323linear140.7322.9132.9119,383 (5.68%)1316 (37.3%)110
hist0.2074linear80.8022.6519.0512,411 (3.64%)0 (0%)69
simple0.0786linear70.8324.9317.007751 (2.27%)0 (0%)60
simple0.0908linear180.9928.5041.9522,591 (6.62%)1375 (38.97%)119
simple0.0811linear130.9925.1331.3018,170 (5.32%)1166 (33.05%)112
Table 3. [LHC] Sizes of tensors containing the model weights.
Table 3. [LHC] Sizes of tensors containing the model weights.
LSTM1LSTM2DenseTotal
W 1 U 1 b 1 Total W 2 U 2 b 2 Total W D b D Total
102416,38425617,6648192409612812,4166426630,146
Table 4. [LHC] Models’ predictions quality depending on test set size. For quality measures definitions see Appendix C.
Table 4. [LHC] Models’ predictions quality depending on test set size. For quality measures definitions see Appendix C.
DataBucketizationAccuracyF1 ScoreF2 ScorePrecisionRecallTotal SamplesAnomalous Data (%)
allno0.86040.78920.79130.78570.792749902032.96
yes0.86340.78690.77380.80980.7654
subsetno0.85860.78880.79100.78530.79244096033.34
yes0.86090.78570.77330.80740.7652
Table 5. [LHC] Results for pruned and quantized model trained (and retrained) on continuous data. In ‘quality score’ and ‘sparsity’ columns, values in parentheses indicate results obtained when using model retraining (see Section 3.3.4), with results better than with no retraining marked in bold. Pauses indicate results, for which the resources consumption exceeded the XCZU15EG FPGA capacity. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip.
Table 5. [LHC] Results for pruned and quantized model trained (and retrained) on continuous data. In ‘quality score’ and ‘sparsity’ columns, values in parentheses indicate results obtained when using model retraining (see Section 3.3.4), with results better than with no retraining marked in bold. Pauses indicate results, for which the resources consumption exceeded the XCZU15EG FPGA capacity. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip.
PruningQuantizationQuality ScoreSparsity (%)% of Original Size; Equation (15)#LUT#DSPLatency (ns)
MethodFractionMethodBitsOptimizationFull
hist_amount0.0816linear16−0.3955 (−0.0293)−0.40588.10  (8.10) 46.01
hist_amount0.3365minmax13−0.1953 (0.8179)−0.164533.71 (33.54)26.93
hist_amount0.3385linear26−0.1709 (−0.4004)−0.149533.76 (33.76)53.77
hist_amount0.3392linear29−0.1660 (−0.0269)−0.147933.76 (33.76)59.97
simple0.0035minmax6−0.1514 (−0.1831)−0.22222.13  (4.2818.4841,991 (12.30%)4 (0.11%)263
hist_amount0.4199linear31−0.0806 (51.8018)−0.174141.86 (41.86)56.06
hist_amount0.3449linear26−0.0244 (0.9424)0.057334.71 (34.71)53.24
hist_amount0.1391linear11−0.0024 (−0.2466)0.014213.96 (13.96)29.61260,116 (76.22%)1729 (49.01%)477
hist_amount0.1764linear110.0049 (1.0889)0.046517.25 (17.42)28.32253,541 (74.29%)1711 (48.50%)443
simple0thq50.0537 (0.0537)0.11480 (0)15.6313,694 (4.01%)4 (0.11%)210
hist_amount0.3499linear250.0659 (0.1050)0.117035.08 (35.08)50.64
hist_amount0.3474linear220.0732 (0.0122)0.134534.77 (34.77)44.94
hist_amount0.3541log_minmax60.2588 (0.1929)0.295035.80 (35.80)12.1438,147 (11.18%)4 (0.11%)253
hist_amount0.4812linear260.9326 (51.4990)0.968347.88 (41.86)42.03
Table 6. [LHC] Results for a pruned and quantized model trained on bucketized data. Pauses indicate results, for which the resources consumption exceeded the XCZU15EG Field-programmable gate array (FPGA) capacity. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip.
Table 6. [LHC] Results for a pruned and quantized model trained on bucketized data. Pauses indicate results, for which the resources consumption exceeded the XCZU15EG Field-programmable gate array (FPGA) capacity. Percentages in the ‘#LUT’ and ‘#DSP’ refer to the overall resources available on the chip.
PruningQuantizationQuality ScoreSparsity (%)% of Original Size; Equation (15)#LUT#DSPLatency (ns)
MethodFractionMethodBitsOptimizationFull
hist_amount0.2266linear11−0.3735−0.293222.5026.51243,216 (71.27%)1693 (47.99%)443
hist_amount0.1984linear10−0.2856−0.205819.4225.08199,905 (58.58%)292 (8.28%)376
hist_amount0.2318log_minmax22−0.2344−0.191822.6452.77
hist_amount0.0909thq7−0.2173−0.11329.0119.8968,903 (20.19%)6 (0.17%)354
hist_amount0.2314linear16−0.2051−0.178822.5538.49
hist_amount0.1665linear7−0.0854−0.066316.6318.2366,714 (19.55%)6 (0.17%)344
hist_amount0.2090linear9−0.0781−0.041921.3022.20140,061 (41.40%)298 (8.45%)376
simple0.0429minmax40.33940.340131.429.959067 (2.66%)9299 (1.36%)210
Table 7. Comparison with hls4ml framework, with percentage difference to original experiment [10].
Table 7. Comparison with hls4ml framework, with percentage difference to original experiment [10].
hls4ml [10]DL2HDL
#DSP48E9541069(112.05%)
#LUT + #FF88,79738,146(42.96%)
latency (ns)7570(93.33%)
Table 8. Comparison with the LeFlow framework.
Table 8. Comparison with the LeFlow framework.
LeFlow [8]DL2HDL
#LEMemBLatency (ns)#LUT#FF#DSPLatency (ns)
dense_a174310561421110300164.83
dense_b1749822410,343484821541245.15
Table 9. Inference times for a single sample on various devices. The general-purpose graphics processing unit (GPGPU) and central processing unit (CPU) experiments were done with uncompressed models, since unstructured pruning and quantization does not significantly affect the performance. For FPGA, the best per-model pruning and quantization results were used.
Table 9. Inference times for a single sample on various devices. The general-purpose graphics processing unit (GPGPU) and central processing unit (CPU) experiments were done with uncompressed models, since unstructured pruning and quantization does not significantly affect the performance. For FPGA, the best per-model pruning and quantization results were used.
GPGPU (ns)CPU (ns)FPGA (ns)
Nvidia GeForce GT 730MIntel i5-4210MXilinx Zynq UltraScale+ MPSoC XCZU15EG
[IAP]0.72 × 1060.81 × 10627
[PM2.5]5.33 × 1067.22 × 10654
[LHC]39.5 × 10642.19 × 106210

Share and Cite

MDPI and ACS Style

Wielgosz, M.; Karwatowski, M. Mapping Neural Networks to FPGA-Based IoT Devices for Ultra-Low Latency Processing. Sensors 2019, 19, 2981. https://doi.org/10.3390/s19132981

AMA Style

Wielgosz M, Karwatowski M. Mapping Neural Networks to FPGA-Based IoT Devices for Ultra-Low Latency Processing. Sensors. 2019; 19(13):2981. https://doi.org/10.3390/s19132981

Chicago/Turabian Style

Wielgosz, Maciej, and Michał Karwatowski. 2019. "Mapping Neural Networks to FPGA-Based IoT Devices for Ultra-Low Latency Processing" Sensors 19, no. 13: 2981. https://doi.org/10.3390/s19132981

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop