Vitis软件图像处理硬核加速例程和官指三坑
在介绍具体例程之前,先介绍几个基本概念:
AXI4-Stream interface: Specify on input arguments or output arguments only, not on input/output arguments.
AXI4-Lite interface: Specify on any type of argument except streams.
AXI4 master interface: Specify on arrays and pointers (and references in C++) only.
SDSVHLS macro:
guard code in a function definition that differs depending on whether it is used by Vivado HLS to generate hardware or used in a software implementation.
C++0x:
C++11之前被称为C++0x,因为原本计划在2010年发布,所以之前一些编译器使用C++11的编译参数是:-std=c++0x,后面使用:-std=c++11。
下载例程源程序:
Vitis_Libraries/vision/L1 at master · Xilinx/Vitis_Libraries https://github.com/Xilinx/Vitis_Libraries/tree/master/vision/L1
Prerequisites
- Valid installation of Vitis™ 2019.2 or later version and the corresponding licenses.
- Install the xfOpenCV libraries, if you intend to use libraries compiled differently than what is provided in Vitis.
- Install the card for which the platform is supported in Vitis 2019.2 or later versions.
- Xilinx® Runtime (XRT) must be installed. XRT provides software interface to Xilinx FPGAs.
- libOpenCL.so must be installed if not present along with the platform.
将下面的文件拷入Ubuntu系统
Vitis_Libraries/vision at master · Xilinx/Vitis_Libraries https://github.com/Xilinx/Vitis_Libraries/tree/master/vision
GUI Mode
Use the following steps to operate the HLS Standalone Mode using GUI:
- Open Vivado® HLS in GUI mode and create a new project
- Specify the name of the project. For example - Dilation.
- Click Browse to enter a workspace folder used to store your projects.
- Click Next.
- Under the source files section, add the accel.cpp file which can be found in the examples folder. Also, fill the top function name (here it is dilation_accel).
- Click Next.
- Under the test bench section add tb.cpp.
- Click Next.
- Select the clock period to the required value (10ns in example).
- Select the suitable part. For example, xczu9eg-ffvb1156-2-i.
- Click Finish.
- Right click on the created project and select Project Settings.
- In the opened tab, select Simulation.
- Files added under the Test Bench section will be displayed. Select a file and click Edit CFLAGS.
- Enter -I -D__SDSVHLS__ -std=c++0x.
- Select Synthesis and repeat the above step for all the displayed files.
- Click OK.
- Run the C Simulation, select Clean Build and specify the required input arguments.
- Click OK.
- All the generated output files/images will be present in the solution1->csim->build.
- Run C synthesis.
- Run co-simulation by specifying the proper input arguments.
- The status of co-simulation can be observed on the console.
Ubuntu命令行输入下面的命令,启动HLS:
vivado_hls
输入项目名称和选定例程中的L1中的dilation目录
打开Project Settings
在CFLAGS中指定include目录和参数
确定仿真参数开始逻辑仿真Simulation
勾选Clean Build
出现错误:
官方指导文件坑一:找不到头文件xf_dilation_config.h,找到该文件所在目录:
在加上xf_dilation_config.h所在目录:
-I/home/john/Vitis/vision/L1/include -I/home/john/Vitis/vision/L1/examples/dilation/build -D__SDSVHL__ -std=c++0x
再次仿真,新错误出现:
libopencv_highgui.so: undefined reference to
INFO: [SIM 2] *************** CSIM start ***************
INFO: [SIM 4] CSIM will launch GCC as the compiler.
Compiling …/…/…/…/xf_dilation_tb.cpp in debug mode
Compiling …/…/…/…/xf_dilation_accel.cpp in debug mode
Generating csim.exe
Makefile.rules:401: recipe for target ‘csim.exe’ failed
/home/john/Vitis/Vivado/2019.2/tps/lnx64/binutils-2.26/bin/ld: warning: libjpeg.so.62, needed by /home/john/Vitis/Vivado/2019.2/lnx64/tools/opencv/opencv_gcc/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
/home/john/Vitis/Vivado/2019.2/tps/lnx64/binutils-2.26/bin/ld: warning: libpng12.so.0, needed by /home/john/Vitis/Vivado/2019.2/lnx64/tools/opencv/opencv_gcc/libopencv_highgui.so, not found (try using -rpath or -rpath-link)
官方指导文件坑二:缺少依赖库libjpeg62

/home/john/Vitis/Vivado/2019.2/lnx64/tools/opencv/opencv_gcc/libopencv_highgui.so: undefined reference to `[email protected]_0’
官方指导文件坑三:缺少库文件libpng12.so.0
查询相似安装库:
[email protected]:~/Vitis/vision/L1/examples/dilation/build$ apt-cache search libpng
libpng-dev - PNG library - development (version 1.6)
libpng-tools - PNG library - tools (version 1.6)
libpng16-16 - PNG library - runtime (version 1.6)
fp-units-gfx - Free Pascal - graphics-library units dependency package
fp-units-gfx-3.0.4 - Free Pascal - graphics-library units
libpng+±dev - C++ interface to the PNG (Portable Network Graphics) library
以上库均安装失败,本机查找文件libpng12.so.0,找到后拷贝到用户库目录:
[email protected]:~/vmware-tools-distrib/lib/lib64/libpng12.so.0$ sudo find / -name libjpeg.so.62
/home/john/petalinux2019.2/sysroots/aarch64-xilinx-linux/usr/lib/libjpeg.so.62
/home/john/Vitis/DocNav/lib/libjpeg.so.62
/usr/lib/x86_64-linux-gnu/libjpeg.so.62
[email protected]:~/vmware-tools-distrib/lib/lib64/libpng12.so.0$ sudo cp libpng12.so.0 /usr/lib/x86_64-linux-gnu/
再次仿真:
INFO: [SIM 211-2] *************** CSIM start ***************
INFO: [SIM 211-4] CSIM will launch GCC as the compiler.
Compiling …/…/…/…/xf_dilation_tb.cpp in debug mode
Compiling …/…/…/…/xf_dilation_accel.cpp in debug mode
Generating csim.exe
Invalid Number of Arguments!
Usage:
错误是由未设置Arguments所致,加入包括绝对路径的图像文件:
Simulation仿真成功
开始Cosimulation
Cosimulation设置参数:
Cosimulation仿真成功
有告警,未研究
Since the only kind of statements allowed in a canonical dataflow region are variable declarations and function calls, the compiler may not be able to correctly handle the region: /home/john/Vitis/vision/L1/include/common/xf_utility.hpp:301:2
两次处理的图片目录如下:
[email protected]:~/Vitis/vision/L1/examples/dilation$ find ./ -name *.jpg
./Dilation/solution1/sim/wrapc/out_ocv.jpg
./Dilation/solution1/sim/wrapc_pc/out_ocv.jpg
./Dilation/solution1/csim/build/out_ocv.jpg
原图像:
处理后图像: