Programming an FPGA: An Introduction to How It Works

The line between software and hardware engineering is blurrier than it might seem. Devices called field-programmable gate arrays (FPGAs), whose physical attributes can be manipulated through the use of hardware description languages (HDLs), bridge the gap between programming software and programming hardware.

But FPGAs have been typically thought of as devices only hardware engineers can program. Thankfully, that is no longer the case, due to modern unified software platforms that plug into common development tools in order to make the process of programming FPGAs more accessible.

Indeed, software developers can also learn how to program FPGAs. We’ll cover the basics of FPGAs in this article, such as how they work and why they’re used. Then, we’ll discuss the tools you need to design and execute your first FPGA application.


What Is an FPGA and Why Is It Used?

An FPGA is an integrated circuit (IC) equipped with configurable logic blocks (CLBs) and other features that can be programmed and reprogrammed by a user. The term “field-programmable” indicates that the FPGA’s abilities are adjustable and not hardwired by the manufacturer like other ICs.

FPGAs are integrated circuits (ICs) that fall under the umbrella of programmable logic devices (PLDs). The fundamental functionality of FPGA technology is built on adaptive hardware, which has the unique ability to be modified after manufacture. Arrays of hardware blocks, each configurable, can be connected as needed, allowing highly efficient, domain-specific architectures to be built for any application.

This hardware adaptability is a unique differentiator from CPUs and GPUs.  

CPUs are highly flexible, but their underlying hardware is fixed. Once a CPU is manufactured the hardware cannot be changed. It relies on software to tell it which specific operation (arithmetic function) to perform, on which data in memory. The hardware must be capable of performing all possible operations, which are called using software instructions and can generally only execute one instruction at a time. FPGAs in contrast can process massive amounts of data in parallel. The benefit of adaptive hardware over CPUs varies by application—largely depending on the nature of the computation and its ability to be parallelized, but it’s not uncommon to see a 20X performance improvement vs. a CPU implementation of functions that can be highly parallelized.

GPUs address a major drawback of CPUs – the ability to process a large amount of data in parallel and can operate on very wide data sets. Fundamentally, GPUs are CPU-like because they have fixed hardware and operate using software instructions. A single instruction could process a thousand pieces of data or more,  making them suitable for specific domains such as graphics acceleration, high performance computing, video processing, certain forms of machine learning, and more. Fundamentally, however, a GPU’s basic architecture and data flow are fixed prior to manufacturing.

FPGAs give programmers and designers the ability to adapt and update the compute architecture with greater flexibility —resulting in domain-specific architectures that are more specific to their requirements. FPGAs are not new, but are becoming more necessary due to the speed of innovation in areas like artificial intelligence. The first commercial-use FPGA was invented in 1985 by AMD, which dominates 60%-70% of today’s market for FPGAs.

An Introduction to Adaptive Computing

Free Ebook Download
An Introduction to Adaptive Computing


FPGA Uses and Applications

The applications for FPGAs are vast. Today, they’re used in data center, aerospace engineering, defense, artificial intelligence (AI), industrial IoT (internet of things), wired and wireless networking, automotive, and countless other industries. Such devices are often in environments where users need real-time information. For example, a home security camera needs to relay instant images to the homeowner’s smart devices—with high resolution and minimal latency. These expectations will only increase as consumers become more reliant on instant information at their fingertips.

FPGAs also assist in acceleration of functions that would otherwise be done in software. That makes FPGAs a helpful tool for offloading performance-heavy tasks, such as deep neural networks (DNN) inference for artificial intelligence.


FPGAs and Hardware Acceleration

The architecture of FPGAs makes them an efficient solution for hardware acceleration. Devices such as ASICs and GPUs use an antiquated method of jumping between programming and memory. They also don’t accommodate applications where real-time information is needed, since the high amount of power required for storage and retrieval tasks causes performance lags. 

Unlike ASICs and GPUs, FPGAs don’t need to jump between memory and programming, which makes the process of storing and retrieving data more efficient. And since FPGA architecture is more flexible, you can customize how much power you’d like an FPGA to utilize for a specific task. 

That flexibility can help offload energy-consuming tasks to one or several FPGAs from a conventional CPU or another device. And since many FPGAs can be reprogrammed, you can easily implement upgrades and adjustments to a hardware acceleration system.

How Does FPGA Programming Work?

FPGA programming uses an HDL to manipulate circuits depending on what capabilities you want the device to have. The process is different from programming a GPU or CPU, since you aren’t writing a program that will run sequentially. Rather, you’re using an HDL to create circuits and physically change the hardware depending on what you want it to do.

The process is similar to programing software in that you write code that is turned into a binary file and loaded onto the FPGA. But the outcome is that the HDL makes physical changes to the hardware, rather than strictly optimizing the device to run software.

A program on an FPGA pieces together lower-level elements like logic gates and memory blocks, which work in concert to complete a task. Because you’re manipulating the hardware from the ground up, FPGAs allow a great deal of flexibility. You can adjust basic functions such as memory or power usage depending on the task.


Languages Used to Program FPGAs

It might seem that FPGAs primarily lie in the domain of chip designers, rather than engineers who specialize in software development. After all, most HDLs used to write FPGA code are lower-level languages that hardware engineers are likely more familiar with than software engineers. But some HDLs are more similar to common software languages than you might think. 

When we use the word “programming” in regard to FPGAs, it’s not exactly the same as creating software, due to the way the program is set up and how it is executed. But using this term does encompass the idea that writing and executing FPGA code is similar in process to creating a software algorithm. The old way of thinking was that FPGAs could only be programmed by hardware engineers designing at the circuit level. Today, that's no longer the case.

With the help of unified software platforms, software developers can use their preferred languages to program FPGAs without being well versed in HDLs. That takes the stress out of having to pivot to a new programming language, and it can help software developers focus on concepts rather than hardware. These platforms work by essentially translating higher-level languages to lower-level ones so that an FPGA can execute the desired function. Languages that can be used with unified software platforms to program FPGAs include:

  • AI framework like TensorFlow and Pytorch - With Vitis AI, AI scientists can now directly take their trained deep learning models from TensorFlow or Pytorch and compile for FPGA acceleration. This not only eliminates the need for low-level hardware programming, but it also achieves blazing-fast compilation time in minutes, matching the typical software compiling experience using CPUs and GPUs.

  • C and C++ - Thanks to high-level synthesis (HLS), C-based languages can now be used for FPGA design. Specifically, the AMD Vivado™ HLS compiler provides a programming environment that shares key technology with both standard and specialized processors for the optimization of C and C++ programs. This allows software engineers to optimize code without having to deal with the roadblock of limited memory space or computational resources. 

  • Python - Designers can use the Python language and libraries to create high-performance applications and program FPGAs with PYNQ—an open-source project from AMD that makes it easier to use AMD platforms.

There are also a number of mainstream HDLs that are primarily used in FPGA programming today. Here’s a brief rundown on their names and main attributes:

  • Lucid - This language was made specifically for FPGAs and overcomes some of the pitfalls of more archaic languages, such as Verilog.

  • VHDL - An acronym for VHSIC (Very High Speed Integrated Circuits) Hardware Description Language, this language first appeared in the 1980s and was based off of Ada and Pascal.

  • Verilog - The first HDL ever created, Verilog today is used mainly for test analysis and verification. The core of this language was based on C.


How to Program an FPGA

Though FPGAs had exclusively existed in the domain of hardware engineers, AI scientists and software programmers can now access new platforms that make the process feel the same as writing software. With the right tools, you will find a solution for programming FPGAs that meets you at your current knowledge level of software and hardware.

If you’re used to programming GPUs, the process of writing FPGA code will feel very similar, even if the outcome is a little different. Programming an FPGA consists of writing code, translating that program into a lower-level language as needed, and converting that program into a binary file. Then, you’ll feed the program to the FPGA just like you’d do for a GPU reading a piece of software written in C++. It’s as simple as that. 

But in order to streamline this programming process, you’ll need access to the right platform. Thankfully, AMD has the perfect solution—a groundbreaking suite of tools that can aid software developers in every step of the FPGA programming process. 


Make FPGA Programming Easy with the Vitis™ Unified Software Platform

The Vitis™ Unified Software Platform is a cutting-edge application that streamlines the FPGA programming process for software engineers, data scientists, and AI developers. It includes an expansive open-source library optimized for AMD FPGA and ACAP hardware platforms, and a core development kit that allows you to seamlessly build accelerated applications without extensive hardware experience.

Vitis™ also includes the Vitis Model Composer, which offers a toolbox within MATLAB® and Simulink®. It streamlines the process of designing and testing new applications.



How to Get Started with Vitis Software for Application Acceleration

Vitis™ helps you design accelerators for data and compute-intensive applications at the edge, on-premise, or in the cloud in a four-step process:

  1. Identify the performance-critical portions of your application that demand acceleration.

  2. Design accelerators using Vitis Accelerated libraries, or develop your own in C, C++, OpenCL, or RTL.

  3. Build, analyze, and debug to verify functional correctness and ensure performance goals are met.

  4. Deploy accelerated applications on AMD platforms at the edge, on-premise, or in the cloud.

AMD Is the No. 1 FPGA Vendor

While FPGAs might seem daunting to program without hardware expertise, platforms like Vitis™ make the process accessible for software developers. AMD is the top FPGA vendor by revenue and an industry leader in offering resources for software engineers to create FPGA applications.

Using the AMD Vitis™ HLS Tool for FPGAs, you can program functions in C, C++, and OpenCL™ and integrate them onto hardware. The HLS tool automates code modifications to make updates simple and optimizes C/C++ code for low latency and high throughput in each of your applications.

Time for you to try programming FPGAs. Pick the approach thats right for you.