Implementing FPGA designs in the cloud

If you are working with FPGA, maybe you use different environments for write your code and for implement your design or perform continuous integration (CI/CD). In my case, in my job I use a Windows PC for write the code and document it, and a remote machine with Linux to implement my design and execute some automated tasks. I can do this because we have a couple of server in the company to do this, but usually, we only have one computer to write the code and implement it. Work with a single PC is some inefficient because the requirements of a computer to write code and write documentation are less than the requirements needed to implement a design, so have two options, have a overpowered, which meets the requirements for implement a design, or a pc with the requirements for write code and document, that spends many time to implement a design. Also you can have a balanced computer, that the one I have in home, which is a bit overpowered for write code and write the blog articles, but it has power enough to implement a design in an acceptable time. But if we are looking for to be efficient since our salaries depends of that, definitely two different computers are the best choice.

In a professional environment, two different computers are two devices that we have to maintain and also, two different devices consuming electricity, which is an extra cost. In addition, this machines will be turned old in a few years, so we also have to add the cost os renew that machines every 5 or 7 years. The third option we have, that fix some of this problems, is keep the computers for write code and emails, and have the implementations machines in the cloud. This allow us to pay only for the time that we are using the implementation machines, and give us the opportunity to adapt the machine exactly to our needs on each case.

In this article I am going to talk about Google Cloud Shell, a free cloud shell with 5 GB of non volatile storage which will be enough for many projects. The working flow is almost the same if we are using other kind of virtual machines with more power, so this article might be used as a reference.

First of all we need to create a Google cloud account in cloud.google.com, then, once the account is created, you will see the main window of Google cloud.

I have also create a project named fpga in order to enable other different features, but for the purpose of this article, a project is not needed. Next, on the top right of the window, we can see the icon of the Google cloud shell, which is a complete shell in a remote virtual machine hosted in the Google’s servers.

When we click on the Cloud Shell icon, a shell will be opened. If you have a project created, the shell will show something like this. if yo do not have a project created, the output of the terminal will be similar without references to the project.

Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to fpga-364317.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
pablo@cloudshell:~ (fpga-364317)$ ls
README-cloudshell.txt

At this point we have a remote machine running. This remote machine has some limitations. This first one is the space we have available in the hard disk, which is only 5 GB (remember that this is a free version), and the second one is that only one thread will be available. For many purposes like unit testing of modules, 5 GB is far enough, but if you want to perform a simulation of the entire system, or a implementation of a medium design, you will need to change your account to a complete account and pay for it for increase the size of the hard disk and also use more than one thread.

As I mentioned before, since we only have 5 GB in the hard disk, we must forget to install Vivado, but fortunately Vivado is not the only option. As we have seen in this blog, we can use the toolchain F4PGA in order to implement designs for Xilinx 7 series FPGA. Also, in that article we have seen how we can use a container to execute it. The really good part of Google Cloud Shell is that it comes with Docker pre installed, so we can use it to create an F4PGA environment.

pablo@cloudshell:~ (fpga-364317)$ docker -v
Docker version 20.10.21, build baeda1f

This time we are not going to create the docker image from zero, but we are going to use a prebuilt image with all the tools installed. We might download the image from hdl.github.io, a repository of images with several FPGA tools installed like F4PGA for implementation, iverilog or verilator for simulation. If we navigate to the F4PGA images, we can see several images with its size. We can select the image according the part we need are using. For the Arty board for example, the image conda/f4pga/xc7/toolchain will be enough. When we click oer the image, we will see that the image is stored in google cloud (the circle is closed). Then, on the right of the image there are 3 points. If we click over them, we can see that, for the free version of Google Cloud, all the options except one are greyed, the only option available is which let us see the command to download this image, and also there is an option to execute that command directly on Google cloud shell. If we already have a Google cloud shell opened, we can copy the command and paste it in the terminal, but if we execute the command directly, the instance of the shell will be the same. In any case, the output of the terminal will be the next.

pablo@cloudshell:~$ docker pull gcr.io/hdl-containers/conda/f4pga/xc7/toolchain:latest
latest: Pulling from hdl-containers/conda/f4pga/xc7/toolchain
e9995326b091: Pull complete
154e7aaac0e0: Pull complete
be846ce6e85d: Pull complete
a1bdf656600c: Pull complete
96bbfd278410: Pull complete
Digest: sha256:bf039c8874bd563f533a6d33c334980902448921428a450367b5428bfaffdf38
Status: Downloaded newer image for gcr.io/hdl-containers/conda/f4pga/xc7/toolchain:latest
gcr.io/hdl-containers/conda/f4pga/xc7/toolchain:latest

Once the image is downloaded, we can create a container using that image running the command docker run -it.

pablo@cloudshell:~$ docker image list
REPOSITORY                                        TAG       IMAGE ID       CREATED      SIZE
gcr.io/hdl-containers/conda/f4pga/xc7/toolchain   latest    08585f926121   2 days ago   2.01GB
pablo@cloudshell:~$ docker run -it --name f4pga 08585f926121
(xc7) root@f14510f87812:/#

On this container we have all the needed dependencies to use F4PGA, but we have not the files to implement the design. In order to upload files, in the Google cloud shell window, we have to click over the three point in the top right of the window, and select Upload.

In this window we can select the source and destination folder, then the files will be uploaded.

pablo@cloudshell:~$ ls
README-cloudshell.txt  volume_control

Now, we need to create a container adding a shared volume in order to let the container access to the host folder.

pablo@cloudshell:~$ docker run -it --name f4pga -v ~/volume_control:/volume_control 08585f926121
(xc7) root@9eab6b6b4700:/# ls
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr  volume_control

Once we have all the files of the project accessible from the container, we can launch the implementation.

(xc7) root@9eab6b6b4700:/volume_control# TARGET="arty_35" make -C volume_control

Execute the implementation of an FPGA design in the cloud is very useful when we are working from a very limited computer or even a Single Board Computer (SBC) like Raspberry Pi or Lite Panda. Also, for a large designs, if we want to use our computer for any other tasks while the implementation id running, we can use a Google cloud instance to run the implementation while we are working in the documentation of the project. But when this kind of tools are very useful, is in automated verification tasks. We might have a VM configured and run it when a new commit is upload to the repository, then all the test are run in this virtual machine.

Leave a Reply