TDEB Top Bar

Trending
Semiconductor Industry News — The Digital Electronics Blog
Follow Us

TDEB Masthead

The Semiconductor Hub

Semiconductors.  Chips and Systems.  Innovation.

Indexed by leading Search Engines, AI and referenced by Engineers worldwide 500+ Articles 10M+ Pageviews 30+ Reports 50+ Citations

FPGA Based Machine Learning Inference: Concepts, Flow and Trade-offs

Murugavel Ganesan
by
0
Share Facebook X LinkedIn WhatsApp Email

FPGA based machine learning inference means running an already trained model on an FPGA, with the network's layers built as custom hardware pipelines instead of instructions on a CPU or GPU. The model is usually quantized to low-precision integers, mapped onto the FPGA's DSP blocks and on-chip memory either directly or through a programmable overlay engine, and connected to a host processor that sends inputs and collects results. The payoff is low, predictable latency and good energy efficiency, especially at batch size one, at the cost of a harder design flow.

Machine learning acceleration flow on FPGA, from trained model to deployed FPGA accelerator
Picture courtesy: https://logictronix.com/

Machine learning (ML) is a branch of artificial intelligence that enables computers to learn from data and make predictions or decisions. ML applications are becoming more widespread and diverse, ranging from image recognition, natural language processing and recommender systems to self-driving cars. However, ML models are often computationally intensive and need high-performance hardware to run efficiently.

Key takeaways

  • Inference is running a trained model on new data; it has different needs from training (latency, power, cost per inference).
  • FPGAs suit inference when latency must be low and fixed, when the batch size is small, or when the model uses unusual precision or structure.
  • Quantization (for example FP32 to INT8) is almost always the first step, because it cuts DSP, memory and bandwidth needs several times over.
  • There are two broad styles: a dataflow design built for one model, or an overlay engine that runs many models.
  • Off-chip memory bandwidth, not arithmetic, is often the real limit.

What inference needs

One of the challenges of ML is deploying the trained models on target devices, such as edge devices, embedded systems or cloud servers. This step is called ML inference: executing the model on new input data and producing the output. Inference has different requirements depending on the application, such as latency, accuracy, power consumption or scalability. A self-driving car needs a fixed answer within milliseconds for one camera frame; a photo-tagging service cares more about images per second per watt across a large batch.

Why FPGAs for ML inference

FPGAs have several advantages for ML inference, such as:

  • High performance: FPGAs can exploit parallelism and pipelining to achieve high throughput and low latency. They can also support custom data types and operations optimized for ML models, such as 4-bit weights or binary networks.
  • Low power: FPGAs run at low core voltage and modest clock frequencies and, depending on the device, can adjust power to the workload through clock gating, lower-voltage operating modes or powering down unused regions. They also reduce memory access and data movement by keeping weights and intermediate results in on-chip memory, and data movement is a large share of energy in ML.
  • Flexibility: FPGAs can be reprogrammed to adapt to different ML models and algorithms, as well as different hardware platforms and interfaces. They also support hardware/software co-design and co-optimization.

The deep dive below puts these claims side by side with CPUs, GPUs and inference ASICs in a table, and works through a sizing example.

Two ways to build it: dataflow or overlay

In a dataflow design, each layer gets its own hardware stage and data streams through them, like a factory line. It gives the lowest latency but must be rebuilt for each model, and only fits models small enough for the device. An overlay is a programmable neural-network processor (a grid of MAC units with its own instruction set) placed on the FPGA once; new models are compiled to it like software. Vendor deep learning processing units are of this kind. Overlays trade some efficiency for much faster model updates.

What this series covers

In this series we introduce the key concepts and techniques for FPGA based ML inference:

For background on accelerators in general, see What is an FPGA accelerator, and for frameworks see FPGAs and AI: frameworks, architectures and applications.

Common mistakes

  • Comparing peak TOPS only. Real performance depends on utilization and memory bandwidth; ask for measured throughput on your model.
  • Skipping accuracy checks after quantization. Always measure accuracy on a validation set after converting to INT8 or lower.
  • Ignoring the host. Pre-processing, data transfer over PCIe and driver overhead can dominate latency for small models.
  • Choosing a dataflow design for a model that changes monthly. An overlay or a GPU may be the better fit.

FAQ

Can FPGAs be used for training as well?

It is possible and has been researched, but training needs high precision, large memory and fast-changing software, so GPUs and dedicated accelerators dominate it.

Do I need to write Verilog to deploy a model on an FPGA?

Not always. Vendor AI toolchains and overlays let you compile a model from a framework, and HLS lets you write C++. Custom high-performance designs still benefit from RTL skills.

Which models suit FPGAs best?

Small to medium CNNs, models with low-precision or sparse weights, and anything where a fixed, very low latency matters, such as in networking, trading, industrial vision and physics experiments.

We hope this post gives you a useful overview of FPGA based ML inference. The linked articles go into each step in more detail, and this post will be extended as the series grows.

Deep dive: the numbers and details

This part holds the platform comparison, quantization arithmetic, memory hierarchy and a worked sizing example. Skip it if the overview is all you need.

FPGA against CPU, GPU and ASIC

The comparison with other platforms is a trade-off, not a clear win:

CriterionCPUGPUFPGAInference ASIC / NPU
Latency at batch 1MediumMedium to highLow, deterministicLow
Peak throughputLowVery highMedium to highHigh
Energy per inferenceHighMediumLow to mediumLowest
Support for new layer typesImmediateFast (software)Needs hardware workLimited to what was built
Development effortLowestLowHighVery high (for the chip maker)

Quantization: why INT8, and how many MACs per DSP

Models are trained in 32-bit floating point, but inference rarely needs that precision. Converting weights and activations to 8-bit integers usually loses little accuracy, especially with quantization-aware training, and an INT8 multiplier is far smaller than an FP32 one. On AMD (Xilinx) UltraScale and UltraScale+ devices, one DSP48E2 slice can perform two INT8 multiply-accumulates per cycle when the two operations share the same weight, by packing two 8-bit activations into the 27-bit input of its 27 x 18 multiplier. Xilinx white paper WP486, Deep Learning with INT8 Optimization on Xilinx Devices (2016), describes the method and claims 1.75 times the peak INT8 operations of competing FPGAs with the same DSP count, whose 18 x 19 multipliers manage one INT8 MAC per DSP. Packing therefore depends on the DSP architecture; check the vendor documentation before assuming two MACs per DSP.

Rough relative cost, per multiply: an INT8 operand is a quarter of the bits of an FP32 one, so weights take a quarter of the memory and a quarter of the bandwidth. A 25 million parameter model drops from 100 MB in FP32 to 25 MB in INT8, which is the difference between needing external memory for every layer and keeping a large share of the weights on chip.

Memory hierarchy

Weights and feature maps live in external DDR or HBM, block RAM and UltraRAM on the chip, and registers in the datapath. Good designs tile each layer so that data loaded from external memory is reused many times on chip before being discarded.

A worked sizing example

The figures below are illustrative, chosen to show the method, not a benchmark of any device.

  • Model: an image classifier needing 4 billion MACs per image (in the range of a mid-sized CNN).
  • FPGA: 2,000 DSP blocks, each doing 2 INT8 MACs per cycle, at 300 MHz.
  • Peak: 2,000 x 2 x 300 million = 1.2 trillion MACs per second.
  • Realistic utilization: 50 percent, after memory stalls and layers that map poorly, giving 0.6 trillion MACs per second.
  • Throughput: 0.6 trillion / 4 billion = 150 images per second, or about 6.7 ms per image if processed one at a time.

Now check bandwidth. If the model has 25 million INT8 weights (25 MB) and they do not fit on chip, reading them once per image at 150 images per second needs about 3.75 GB/s for weights alone, before feature maps. That is within the reach of a single DDR4 channel, but feature maps for early layers can add much more; this is why tiling and on-chip reuse decide real performance.

Further reading

Murugavel Ganesan
About the Author
Murugavel Ganesan
Product Director | SerDes · IVN · Edge AI · Compute | Ex Intel · Infineon

A semiconductor product leader working across product architecture, definition, strategy, and silicon and software execution, from concept through volume production. He has worked with teams across Asia, Europe and the USA, including at Intel, Infineon and ArrayComm.

His work covers ASICs, SoCs, FPGAs and chiplets for wireless, wireline, automotive, IoT and AI, including PCIe, CXL and DDR interfaces alongside RF and mixed-signal design.

Share Facebook X LinkedIn WhatsApp Email

Post a Comment

0 Comments

Your comments will be moderated before it appears here.

Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!