Open main menu

DAVE Developer's Wiki β

Changes

BELK-TN-005: Running PYNQ on Bora

1,181 bytes added, 11:13, 22 November 2021
no edit summary
{{Applies To Bora}}
{{Applies To BoraX}}
{{AppliesToBORA_TN}}
{{AppliesToBORA_Xpress_TN}}
{{InfoBoxBottom}}
|-
|1.1.0
|October November 2018|Moved to PYNQ 2.3<br>Added sections about FIR filter implementation and testing
|}
This Technical Note shows hot to run PYNQ on Bora platform. It is worth remembering that, even though the procedure was tested on Bora, it should work on BoraX as well without any modification.
To see PYN PYNQ in action, please see [https://www.youtube.com/watch?v=LoLCtSzj9BU this clip].
==Testbed's hardware Hardware and software configurationSoftware Configuration==
As stated before, the procedure was tested on Bora/BoraEVB hardware platform.
With regard to the software configuration, the following versions were used:
*[[BELK/BXELK_software_components#Kits.27_composition|U-Boot 20142018.07 released with 1 (at the time of this writing, '''this version was not officially supported by any BELK 2.1.0]]release yet''')*Linux kernel 4.14.0 (at the time of this writing, '''this version was not officially supported by any BELK release yet''')*root file systemRoot filesystem: extracted from [http://files.digilent.com/Products/PYNQ/pynq_z1_v2.3.zip Pynq-Z1 v2.3 image] and mounted from microSD card.
Original root file system included several kernel drivers built as modules. The Linux kernel used for this test was different than the kernel released along with the PYNQ's root file system, however. Consequently, these modules were not compatible with the kernel running on Bora. To overcome this issue, these drivers were linked statically into the kernel image.
==Setting up Up the boardBoard==
U-Boot environment was configured in order to retrieve the kernel image and the device tree blob from the microSD card. Also, it was configured to make the kernel to mount the root file system from a partition of the microSD card.
The following box shows the full boot process (clock on the "Expand" box):
<pre class="workstation-terminal mw-collapsible mw-collapsed">
 
# SETTING UP THE BOARD
 
U-Boot environment was configured in order to retrieve kernel image and device tree blob on mmc.
Also, it was configured to make the kernel to mount the root file system on mmc.
 
/* a test completati ti passo l'immagine della mmc con il rfs contenente anche gli esempi di questa guida */
 
The following box shows the full boot process (clock on the "Expand" box):
 
/* vedi boot_process.txt */
 
 
 
# open jupyter notebook
 
In order to open the Jupyter Notebook web dashboard:
- open the browser (only Google Chrome is supported)
- go to http://192.168.2.99:9090 if your board is connected to a computer via static IP address or to http://pynq:9090 if your board is connected to a router on network
- log in with username "xilinx" and password "xilinx"
 
/*
immagine : jupyter_welcome.png
*/
 
U-Boot 2018.01-00022-g322f20f (Aug 28 2018 - 11:20:19 +0200)
</pre>
==Testing the PYNQ frameworkFramework==
The following image shows the PYNQ processes running.
 
[[File:PYNQ-htop1.png|thumb|center|600px|Running processes ordered by memory occupation]]
To test the whole framework, the following testbed was used.
 
 
[[File:BELK-TN-005-block-diagram1.png|thumb|center|600px|Testbed block diagram]]
 
The test consisted of the following steps:
*First, a software implementation of an FIR filter was created*A hardware implementation of the same FIR filter was generated using the wizard [https://www.xilinx.com/products/intellectual-property/fir_compiler.html FIR Compiler] provided by Vivado.
*The resulting IP was instantiated in Programmable Logic (PL).
*Using Jupyter Notebooks, the a simple Python test code was edited and runto exercise the filter.
**Two different approaches were used: generic driver and IP-specific driver.
This example was inspired by [[http://www.fpgadeveloper.com/2018/03/how-to-accelerate-a-python-function-with-pynq.html|this tutorial]].
===Basic operationsOperations===
*In order to open the Jupyter Notebook web dashboard, do the following steps:
**Open the browser (only Google Chrome is supported)
**Go to http://<IP address>:9090 if your board is connected to a computer via static IP address or to <nowiki>http://pynq:9090 </nowiki> if your board is connected to a router on networkhost can resolve the target's hostname**Log in with username ''<code>xilinx'' </code> and password ''<code>xilinx''</code>.
[[File:TBDPYNQ-jupyter-welcome.png|thumb|center|600px|captionJupyter Notebook web dashboard]]
*To move files to/from Jupyter Notebook it is convenient to share the home directory of the target's <code>xilinx </code> user. For instance, to access the Pynq home area as a network drive via Samba protocol:
*Open a file browser and click "Go" > "Enter Location"
*Insert location <code>smb://192.168.2.99/xilinx</code>*Log as <code>xilinx</code> with password <code>xilinx</code>. ===Editing and executing Python functions===Before implementing the FIR filter in PL, we created a software implementation with the [https://www.scipy.org/ SciPy] library. To verify it, we applied it to a noisy signal. In essence we* created a new notebook by clicking on the ''xilinxNew'' button at the top and select ''Python 3''[[File:PYNQ-jupyter-new-file.png|thumb|center|600px|Creating a new notebook]]  *selected ''Code'' with password on the top bar and write some Python code[[File:PYNQ-jupyter-start-writing-python.png|thumb|center|600px|Writing Python code]]  * clicked ''xilinxRun''on the top bar to run code on a kernel.  The following image shows the noisy and the filtered signals.
# WRITE AND RUN PYTHON FUNCTIONS
This section describes how to write and run python code on the web interface. [[File:PYNQ-jupyter- create a new notebook by clicking on the "New" button at the top and select "Python 3" FIR- select "Code" on top bar result.png|thumb|center|600px|Input and write some Python code - click "Run" on top bar to run code on kerneloutput signals]]
/*
immagine : jupyter_new_file.png
immagine : jupyter_start_writing_python.png
*/
The procedure was tested For more details, please refer to the section [http://www.fpgadeveloper.com/2018/03/how-to-accelerate-a-python-function-with a -pynq.html ''Software FIR filter from using SciPy library applied to a noisy signal''].
/* ===Implementing a Hardware-Accelerated Version of the FIR Filter in PL=== vedi http://www.fpgadeveloper.com/2018/03/howTo access an hardware-accelerated function from Python, PYNQ requires to-accelerate-load a-python-function-custom overlay. Overlays are built with-pynqVivado and are composed by:*an FPGA bitstream (.html fino al paragrafo "Software FIR filter using SciPy"bit file) */a block design (.tcl file)
====Creating and Running a New Custom Overlay: Approach #1====
We created a custom overlay associated with the hardware implementation of the FIR filter. This first approach made use of the FIR Compiler tool provided by Vivado.
The fundamental steps required to do this are:
*Opening a new Vivado project, selecting ''RTL project'' and ''Bora SOM'' as the target board
*Creating your block design
**Adding ''FIR compiler'' block (included in Vivado default IP) and setting it up
**Adding ''AXI direct memory access'' block and setting it up
**On ''ZYNQ7 Processing System'' block, enabling a ''High-Performance AXI 32b/64b Slave Ports'' on interface HP0
**Connecting AXIS_DATA bus of AXI and FIR block
**''Runnin Connection Automation'' to complete wiring
*Creating Hierarchy of AXI and FIR block named <code>filter</code>
*Exporting bitstream file running ''Generate Bitstream''
*Exporting block design using Tcl console command <code>write_bd_tcl </path/name>.tcl</code>
*Renaming generated files as <code>overlay_name>.bit</code> and <code><overlay_name>.tcl</code>
*Creating a folder named <code><overlay_name></code> and inserting generated files
*Copying the folder to the target's filesystem in <code>pynq/overlays/</code> direcrtory.
# ACCELERATE A PYTHON FUNCTIONThe overlay is ready to be used in the PYNQ Python console.
# INTRO
To accelerate a Python function on the Zynq-7000, PYNQ can load a custom overlay.
Overlays are built with Vivado 2018.2 and are composed by:
- fpga bitstream (*.bit file)
- block design (*.tcl file)
The test consisted of the following steps[[File: PYNQ-jupyter-vivado- First, a FIR filter was generated using the wizard provided by Vivado. - png|thumb|center|600px|The resulting IP was instantiated in Programmable Logic (PL). - Using Jupyter Notebooks, the Python test code was edited and run.design]] - Two different approaches were used: generic driver and IP-specific driver.
=====Running Custom Overlays with Generic Driver =====
To access the overlay with the generic driver:
*Load <code>Overlay</code> and <code>Xlnx</code> modules from <code>pynq</code> and <code>pynq.lib.dma</code>.
*Create <code>Overlay</code> and <code>Xlnk</code> objects
These steps allows you to communicate directly through a DMA buffer.
# CREATE A NEW CUSTOM PYNQ OVERLAY // titolo specifico per filtro fir?
/* sezione da approfondire */
- For more details, please refer to the section [http:/* instruzioni di setup vivado */ - Open a new Vivado project, select "RTL project" and "BORA SOM" as target board - Create your block design - Add "FIR compiler" block (included in Vivado default IP) and setup itwww.fpgadeveloper. To create a new filter block starting from the code c read the paragraph %CREATE A NEW BLOCK IP FROM C CODE% - Add "AXI direct memory access" block and setup it - Enable on "ZYNQ7 Processing System" block an "High Performance AXI 32bcom/2018/03/64b Slave Ports" on interface HP0 - Connect AXIS_DATA bus of AXI and FIR block how- "Run Connection Automation" to complete wiring - create Hierarchy of AXI and FIR block named "filter" accelerate- export bitstream file running "Generate Bitstream" a- export block design using tcl console command "write_bd_tcl </path/name>.tcl" python- rename generated files as "<overlay_name>.bit" and "<overlay_name>.tcl" function- create folder <overlay_name> and insert generated files with- copy folder in PYNQ target in pynq/overlays/.html ''Hardware FIR Implementation''].
Overlay is ready =====Running Custom Overlays with IP-Specific Driver =====To access the overlay with a specific driver:*Import <code>DefaultHierarchy</code> from <code>pynq</code>*create a new class for FIR filter with a method to use in PYNQ Python console.communicate directly thorough a DMA buffer*create a <code>checkhierarchy</code> method to check the IP contained under ''filter'' hierarchy
/*
immagine: jupyter_vivado_filter.png
*/
For more details, please refer to the section [http://www.fpgadeveloper.com/2018/03/how-to-accelerate-a-python-function-with-pynq.html ''Driver for FIR accelerator''].
====Creating and Running a New Custom Overlay: Approach # RUN CUSTOM PYNQ OVERLAY WITH GENERIC DRIVER 2====This approach makes use of a different method to implement the filter. In this case, the filter was written in C++ and implemented by using [https:// titolo specifico per filtro fir?www.xilinx.com/products/design-tools/vivado/* sezione da approfondire e riscrivere meglio *integration/esl-design.html Vivado High-Level Synthesis (HLS)].
- Load Overlay The fundamental steps required to do this are: *Opening a new Vivado HLS project, selecting Bora SOM as the target board*Creating a new C++ source file*Writing C++ code of FIR custom IP**Creating AXI Stream interfaces for input and Xlnx modules from pynq output**Defining FIR coefficients and pynq.lib.dma.normalizing their values**Using some #pragmas to optimize the execution of the algorithm - Create Overlay *Synthesizing new IP running ''Run C synthesis''*Exporting new IP running ''Export RTL''*Opening a new Vivado project, selecting RTL project and Xlnk objectBora SOM as the target board*Adding the new IP in IP list**Opening ''IP Catalog'' - you can comunicate directly on dma buffer.**Adding repository of the custom IP
/* vedi http://www.fpgadeveloper.com/2018/03/how-To complete the procedure and export the Vivado project, the same steps described previously have to-accelerate-a-python-function-with-pynqbe done.html paragrafo "Hardware FIR Implementation" */
# RUN CUSTOM PYNQ OVERLAY WITH IP-SPECIFIC DRIVER // titolo specifico per filtro fir?/* sezione da approfondire e riscrivere meglio *//* da testare exportazione con diversi setaggi da vivado per checkhierarchy *The data flows are implemented as AXI streams. The following images show the input and the output to/from the filter respectively.
- import DefaultHierarchy from pynq
- create a new class for fir filter with a method to comunicate directly on dma buffer
- create a checkhierarchy method to check ip contained under "filter" hierarchy
/* vedi http[[File://www.fpgadeveloper.com/2018/03/how-to-accelerate-aPYNQ-pythonCustom-functionIP-withAxiS-pynqinput.html paragrafo "Driver for FIR accelerator" */png|thumb|center|600px|Input stream]]
# CREATE A NEW BLOCK [[File:PYNQ-Custom-IP FROM C CODE/* sezione da scrivere la prossima settimana */-AxiS-output.png|thumb|center|600px|Output stream]]
8,226
edits