An FPGA can implement a neural network at whatever numeric precision each layer needs. Boutros and Betz list custom-precision datapaths among the reasons FPGAs became attractive for inference, noting that the precision a network needs depends on the model and can differ between layers of the same model [1]. Low-precision multiply-accumulate units with operands of 8 bits or less can be built efficiently in the LUT fabric, not only in DSP blocks [1].
The precision decision, though, is only half of the design. The other half is the architecture: does every layer get its own hardware, or do all layers share one engine? This article compares the two, using three open frameworks and the results their authors measured.
Two ways to map a network
Dataflow. FINN builds a separate compute engine for each layer, sized to that layer’s work, and connects the engines with on-chip streams [2]. Each engine starts as soon as the previous one produces output, so computation of successive layers overlaps [2]. All weights stay in on-chip memory, which avoids most off-chip accesses [2]. The cost is flexibility: a different network topology needs a different bitstream [2]. FINN-R calls this style a feed-forward dataflow (DF) architecture [3]. Because the slowest layer sets the throughput, the layers are rate-balanced so that each takes roughly the same number of cycles per frame [2,3].
Layer-sequential. The alternative is a fixed set of compute resources that layers are scheduled onto one after another. FINN’s survey of prior work calls this a single processing engine, usually a systolic array, that processes each layer in turn [2]. FINN-R implements its own version as the multilayer offload (MO) architecture, in which feature maps loop back through the offloaded compute engine several times [3]. Boutros and Betz mention a related approach, a processor overlay with an application-customized pipeline and instruction set [1].
FINN-R states the trade-off directly. The cost of a dataflow design is the sum of the costs of all its layers, while the cost of a multilayer offload design is set by the largest layer it must run [3]. That makes the offload style the better fit for deep networks on resource-limited devices [3]. For throughput, the authors expect the two styles to be roughly equivalent for the same compute resources. For latency, they expect dataflow to win because less buffering sits between layers, though at the time of writing they had not confirmed this experimentally [3].
Run-time parameterization also costs logic. In FINN-R, a sliding-window unit for the dataflow style needs 426 LUTs and no DSPs, because its dimensions are fixed at compile time [3]. The run-time-configurable version for multilayer offload needs 1,050 LUTs and 15 DSPs [3].
What quantization buys in hardware
FINN-R models the LUT cost of a dot product as roughly proportional to N × W × A: the vector length times the weight and activation bit widths [3]. Under that model, halving either width roughly halves the arithmetic. Memory falls with width too. Binarization reduces VGG-16 from 4.4 Gbit of weights to 138 Mbit, and YOLOv2 from 1.6 Gbit to 50 Mbit [3]. For some quantized networks, the whole working set then fits in on-chip memory [3].
Binarized networks go furthest. With weights and activations restricted to −1 and +1, FINN replaces each multiply with an XNOR and the accumulation with a popcount [2]. At a 200 MHz target, a 128-bit popcount-accumulate needed 376 LUTs and 29 flip-flops, against 759 LUTs and 84 flip-flops for a signed accumulate [2]. Batch normalization followed by the sign function collapses into a single threshold comparison computed at compile time. HLS reports showed 6 LUTs for the threshold against 2 DSPs, 55 flip-flops and 40 LUTs for the original batchnorm-and-sign [2]. Max-pooling of binary values becomes a Boolean OR [2].
The catch is accuracy per parameter. On MNIST, with a three-hidden-layer fully connected network, FINN’s authors found that binarized networks needed 2 to 11 times more parameters and operations to match floating-point accuracy [2]. On harder tasks the gap shows up as accuracy loss. FINN-R’s Tincy YOLO, with mostly 1-bit weights and 3-bit activations, reached 50.1% mAP on VOC 2007 against 57.1% for floating-point Tiny YOLO [3]. Its DoReFa-Net/PF variant reached 50.3% top-1 on ImageNet against 55.9% for the floating-point DoReFa-Net [3]. FINN-R’s authors leave it to the application to decide whether such losses are acceptable [3].
Bit width also interacts with the weight representation. FINN-R found that moving from plain 1-bit integer weights to bipolar binary weights raised LUT cost by 35%, because the negative multiple needs a sign bit, unless activations are also 1-bit [3].
Measured results and their conditions
Each framework’s numbers apply to its own devices, clocks and networks. We reproduce them with those conditions attached.
FINN (2017). All prototypes ran on a Zynq-7000 ZC706 board with a Z7045 device of 218,600 LUTs and 545 block RAMs, built with Vivado HLS and Vivado 2016.3 at a 200 MHz target clock [2]. Power was measured both on the FPGA supply rails and at the wall [2].
| Prototype | Dataset, accuracy | Throughput | Latency | Wall power |
|---|---|---|---|---|
| SFC-max | MNIST, 95.83% | 12.36 M frames/s | 0.31 µs | 21.2 W |
| LFC-max | MNIST, 98.4% | 1.56 M frames/s | 2.44 µs | 22.6 W |
| CNV-max | CIFAR-10 80.1%, SVHN 94.9% | 21.9 k frames/s | 283 µs | 11.7 W |
Sources for the table: Table 3 and Section 5.1 of [2].
Two details from the same evaluation are useful for planning. The board idled at about 7 W, which sets a floor on every wall-power figure [2]. And when the authors slowed SFC-max to a 250 kHz clock to meet a fixed 9,000 frames/s target, it delivered 15,731 frames/s at 0.2 W of FPGA power and was over twice as energy-efficient as the design built specifically for that target [2]. The authors conclude that a high degree of parallelism benefits energy efficiency as long as the FPGA resources are available [2].
FINN-R (2018). FINN-R targeted three platforms: PYNQ-Z1 (Zynq XC7Z020, 28 nm), Ultra96 (Zynq UltraScale+ XCZU3EG, 16 nm) and AWS F1 (XCVU9P, 16 nm) [3]. The XCVU9P is a Virtex UltraScale+ device [4]. Selected results, all measured:
| Network, precision | Platform, architecture | Clock | Throughput | Board power |
|---|---|---|---|---|
| MLP-4, W1A1 | AWS F1, DF | 232.9 MHz | 50,776 GOp/s | not reported |
| CNV-6, W1A1 | Ultra96, DF | 300 MHz | 2,318 GOp/s | 10.7 W |
| Tincy YOLO, W1A3 | Ultra96, MO | 220 MHz | 288 GOp/s | 9.7 W |
| DoReFa-Net/PF, W1A2 | AWS F1, DF | 155.8 MHz | 11,431 GOp/s | not reported |
| DoReFa-Net/PF, W1A2 | PYNQ-Z1, MO | 100 MHz | 129 GOp/s | 2.5 W |
Source for the table: Table 5 of [3].
The platform overhead is part of the result. On the Zynq boards, the shell that moves data between processor and fabric used 8 BRAM18s and 2.6 kLUTs, because the memory controllers are hardened in the processing system [3]. On AWS F1, the shell needed soft memory controllers, a PCIe DMA engine and an AXI interconnect, and used 1,090 BRAM18s and 297 kLUTs [3]. Any comparison of accelerator sizes across platforms should subtract the shell first.
hls4ml (2018). hls4ml targets a different regime: small fully connected networks with sub-microsecond latency for the CERN Level-1 trigger [5]. The study used a 16-input network with three hidden layers and five outputs, synthesized with Vivado HLS 2017.2 for a Kintex UltraScale xcku115 at 200 MHz [5]. Pruning removed 70% of the parameters, 3,051 of 4,389 [5]. A fixed-point format of about 16 total bits, with 6 integer bits, matched the floating-point AUC closely: the pruned model’s AUC ratio was 99.55% [5].
At that precision and full parallelism, HLS estimated 954 DSP48E slices for the pruned network against 3,329 unpruned, with the same 75 ns latency [5]. A reuse factor controls how many times each multiplier is shared. Raising it cuts DSP use proportionally, and each increment added 4 clocks of latency for this four-layer network [5].
The implementation step changed some of those numbers. In implementation tests, which used a smaller one-hidden-layer network because of the pin count, HLS flip-flop estimates were typically 2 to 4 times higher than the placed-and-routed result [5]. Timing went the other way: the clock period targeted in HLS was not met at implementation, and a 32-bit version of the pruned three-hidden-layer network needed 8 ns where HLS had designed for 5 ns [5]. Both effects argue for running the full implementation flow before trusting any resource or latency figure.
Choosing an approach
We start an inference assessment from the following questions. They come from the trade-offs above, not from a general rule.
- What is the latency requirement? If it is a fixed number of clock cycles, as in the trigger case, a fully pipelined dataflow design is the natural starting point [5].
- Do all weights fit on chip at the chosen precision? If they do, a dataflow design avoids off-chip memory traffic. If they do not, a layer-sequential engine or further quantization is needed [2,3].
- How much accuracy can the application give up? Binarized and 2- to 3-bit networks deliver the largest hardware savings, with accuracy losses of several points on ImageNet and VOC in FINN-R’s results [3].
- How often will the model change? A dataflow design needs a new bitstream for each topology [2]. A multilayer offload engine is parameterized at run time and executes different layers on the same hardware, at a higher logic cost per unit [3].
- Which numbers are estimates? Roofline peaks, HLS reports and post-implementation measurements are different things. Plan from the measured ones [2,5].
For the arithmetic behind these choices, see our article on fixed-point DSP on FPGAs. For the platform decision itself, see when an FPGA is the right platform.
Where Takumetra can help
We can assess a trained or planned network for FPGA deployment, estimate resources and latency for dataflow and layer-sequential implementations, and evaluate whether FINN, hls4ml or a custom RTL design fits the requirement. See our FPGA services for the engagement types.