This is an article about using Microsoft’s Visual Studio Code (VSCode) IDE to develop on Xilinx Zynq devices using the Remote Development Extension. In general, this means you can now develop on Zynq devices using its native compilers all from within a VSCode session… and that session is hosted on your laptop. Okay, let’s first unpack the technologies.
Microsoft’s VSCode is the most popular integrated development environment (IDE) according to the 2019 Stack Overflow Developer Survey. This is impressive, as VSCode was only announced in 2015 and now can be used with many programming languages. And its free to download and use.
There is also a lot of great technology inside VSCode itself - including the Language Server Protocol, which simplified how language parsers interact with code editors and also its use of the GitHub Electron framework to enable a cross-platform desktop application. Above is a screenshots of an active VSCode C++ debug session.
Finally, VSCode is also open source under an MIT license. Its extensions however are shipped as binaries that are free to use though often the source code is not available. If you’d like to use a completely open source IDE building tool, we recommend looking at Eclipse Theia. From a PYNQ team perspective, we’ve been using PyCharm for most of our development efforts but started tracking VSCode ever since it started showing up in Anaconda Navigator.
The Remote Development Extension
How is this remote development possible with Xilinx platforms? Well, the remote development extension from Microsoft allows VSCode to interact with targets (and their compilers) over SSH.
Notice from the VSCode screenshot above that (1) remote ARM architectures are supported regardless of the host machine and that (2) Debian/Ubuntu based Linux’s are both called out as supported target operating systems.
Looking into the details a bit further in the figure above, VSCode does not install compilers on the remote targets, but rather leverages what is already there. In many ways, this mirrors Jupyter’s server/client split, where the remote machine runs everything locally, while the host machine manages the user experience.
This means, PYNQ with its Ubuntu-based Linux is a candidate target for VSCode. PYNQ SD cards ship with gcc, g++, and Python3 among other compilation tools. PYNQ SD cards can be runtime updated through
cmake and now with VSCode extensions. Arm64 architectures are supported by VSCode’s code server, so Zynq UltraScale’s ARM Cortex-A53s should be supported, but of course I’ll prove that in the remainder of this blog.
And remember, PYNQ supports a variety of Xilinx platforms including the Xilinx RFSoC, so what is
shown here is applicable across a wide range of Zynq UltraScale+ devices.
Example #1 Vitis-AI C++ Debug
To demonstrate installation and use of VSCode with a Xilinx platform, I will first take an existing Xilinx Vitis-AI application and show the C++ debugging inside a VSCode session targeting a Xilinx ZCU104 board. Vitis-AI users will recognize the C++ from the Vitis-AI GitHub repository. This code is typically cross compiled into the final application, but here this can all be done interactively on the target within VSCode.
Additionally, I will also use the DPU-PYNQ overlay to download the hardware design and a resnet50 model using steps from the DPU-PYNQ repository.
- a Xilinx ZCU104 with a PYNQ v2.5 SD card image and Internet connectivity. This board and PYNQ version support the Vitis AI application I’ll use as a demonstrator.
- Your host machine can access the ZCU104 over a network or a static IP address.
Download and install VSCode on your host machine – make sure you get a version 1.51.0 or greater – this version has good stability for C++ debugging remotely on ARM64 platforms. VSCode also has downloads for Windows, MAC, and Linux machines. After download and the easy installation, you now have VSCode and could start developing local Python or C++ … but of course, we are here for remote development.
Open VSCode and install the Remote Development Extension – see screenshot below for (1) opening the extensions marketplace, (2) searching the remote development extension and then simply (3) click the ‘install’ box.
Enable root SSH access on the ZCU104 on top of a PYNQv2.5 image. We will use a v2.5 image, as this is supported by the DPU-PYNQ overlay we’ll use later. To enable root access, SSH onto the board and run the following commands below. This is the only modification we need to the ZCU104.
# Run on the ZCU104 sudo chmod u+w /etc/ssh/sshd_config sudo echo "PermitRootLogin yes" >> /etc/ssh/sshd_config sudo service sshd restart
Now follow steps here on VSCode’s Remote Development using SSH documentation to connect to your ZCU104 over SSH (username: root). At this point, we are logged into the board as a superuser which is required for the Vitis-AI application. Installation completed in under 1 minute – the ZCU104 had to download the VS Code server and install it locally as I saw in the terminal output. In the screenshots below, VSCode sets up the server on the ZCU104 and then I search the extension marketplace for the C/C++ extension. A green install box now says “install in SSH: ZCU104_IP_Address”. With a quick click – the extensions now are available on the ZCU104. Installation completed in seconds.
Now with SSH access, this is a good opportunity to pause and install the DPU-PYNQ overlay on the ZCU104. From a terminal in the VSCode remote session (
Terminal -> New Terminal) , run the following script on the ZCU104 (~30 minutes to run due to building some packages from source code).
# Run on the ZCU104, PYNQv2.5 # source: https://github.com/Xilinx/DPU-PYNQ cd /tmp git clone --recursive --shallow-submodules https://github.com/Xilinx/DPU-PYNQ.git cd DPU-PYNQ/upgrade make pip3 install pynq-dpu cd $PYNQ_JUPYTER_NOTEBOOKS pynq get-notebooks pynq-dpu -p . python3 -c 'from pynq_dpu import DpuOverlay ; \ overlay = DpuOverlay("dpu.bit") ; \ overlay.load_model("/home/xilinx/jupyter_notebooks/pynq-dpu/dpu_resnet50_0.elf") '
This installs the DPU-PYNQ overlay, its Jupyter notebooks and software dependencies. The last python call loads the Vitis-AI DPU core onto the programmable logic and additionally loads the resnet50 model.
For reference, a screenshot of that terminal running is below - this is a standard terminal from the ZCU104 for entering bash commands.
- VSCode is now completely ready to go and is installed on both your host machine and the target ZCU104 board. This helloworld tutorial is a good reference for running a simple application. Otherwise, for this blog, I will directly take the Vitis-AI C++ codebase to step through a resnet50 inference application. Here are the VSCode steps specific to setting up my Vitis-AI C++ project:
- From the VSCode explorer view, add a new file
dpu.cpp(see GIST for file contents)
- Terminal -> Configure Default Build Task…
g++as the compiler
- Modify tasks.json with new compiler flags (see GIST for file contents)
Ctrl-Shift-Bto build the C++ project
Below is a before and after screenshot for the dpu.cpp and tasks.json files … the tasks.json is a configuration script that VSCode uses to build the design. Users can also choose a makefile flow which might be easier for porting existing codebases into VSCode.
At this point, the software can be compiled and debugged interactively (press
F5). Below is a screenshot of the resnet50 C++ application with a breakpoint showing what images have been collected for use in inference loop. Notice the rich syntax highlighting, the active breakpoint triggered and variable inspection views… this is all standard VSCode C++ debugging. The software and debugging are all hosted and running on the ZCU104.
Example #2 Python & Jupyter in VSCode
But now, a question for the PYNQ community readers – wait, where are the Jupyter notebooks and
where is the Python? It turns out VSCode’s most popular extension is the Python language extension
with over 27 million downloads … and that extension includes Jupyter notebook support … and it all
works over the remote development framework. I’ll end this article with a quick Python session, just
because it’s too easy to show off.
- Install the Python language extension onto the ZCU104 all from inside VSCode on your laptop –
again, this is all done using the Remote Development Extension. In the same process for the C/C++ extension, I install the Python extension onto the ZCU104 – note here as well, the Python extension requires a valid Python installation to already exist on the platform – I use the Python 3.6 interpreter since PYNQ requires Python3.
- By double clicking a given notebook in the Explorer tab, the notebook first shows up as raw text and then VSCode spins up its own Jupyter server and renders the notebook – very cool! I took two screenshots below from two notebooks to show visualization and cell execution working as expected.
At this point, I could go on and on showing VSCode extensions (e.g. GitHub, other languages, etc.) and how they work inside VSCode targeting Xilinx platforms – but I’ll conclude with two points.
First, this was all possible with a series of downloads, clicks and following of instructions online – nothing here is custom. If you have VSCode and a PYNQ enabled Xilinx platform, you have an IDE for developing on target. Clearly though, finding exciting applications to write and hardware to synthesize is left to the community – some examples are here.
And finally, I’ll conclude with Microsoft’s own first motivating point as to why remote development is so valuable:
Developing on the same deployment target is extremely valuable for final integration of complex
specialized hardware. Additionally, developing for heterogeneous systems is hard enough - with
VSCode, the world’s most popular IDE, developers have a new (yet familiar) IDE for Xilinx platforms.