文章目录
Vitis视觉库可用于构建Vivado®HLS中的应用程序。本节详细介绍如何将Vitis vision库组件集成到Vivado HLS 2019.2的设计中。本节提供了有关如何通过Vivado HLS 2019.2 use flow运行单个库组件的步骤,其中包括C仿真、C合成、C/RTL联合仿真以及将RTL作为IP导出。
需要做以下更改,以促进Vivado HLS 2019.2中使用模型的正常运行:
- 使用适当的编译时选项——在HLS中使用Vitis vision函数时,需要在编译时提供- d_ sdsvhls__和-std=c++0x选项
- 将接口pragma指定为接口级参数——对于具有顶级接口参数的函数,指针(具有多个读/写访问权限),必须指定m_axi接口pragma。例如,
void lut_accel(xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPC1> &imgInput, xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPC1> &imgOutput, unsigned char *lut_ptr)
{
#pragma HLS INTERFACE m_axi depth=256 port=lut_ptr offset=direct bundle=lut_ptr
xf::cv::LUT< TYPE, HEIGHT, WIDTH, NPC1> (imgInput,imgOutput,lut_ptr);
}
HLS Standalone Mode
Tcl Script Mode
使用以下步骤,使用Tcl脚本操作 HLS Standalone 模式:
在Vivado®HLS tcl脚本文件中,更新所有add_files部分中的cflag。
将路径追加到vision / L1 / include目录,因为它包含库所需的所有头文件。
添加-D__SDSVHLHLS__和-std = c ++ 0x编译器标志。
注意:在Windows操作系统中使用Vivado HLS时,仅为C-Sim和Co-Sim提供-std = c ++ 0x标志。 执行synthesis时不要包括该标志。
例如:
Setting flags for source files:
add_files xf_dilation_accel.cpp -cflags “-I -D__SDSVHLS__ -std=c++0x”
Setting flags for testbench files:
add_files -tb xf_dilation_tb.cpp -cflags “-I -D__SDSVHLS__ -std=c++0x”
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.
Note: When using Vivado HLS in the Windows operating system, make sure to provide the -std=c++0x flag only for C-Sim and Co-Sim. Do not include the flag when performing synthesis. - 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.
例如 -I C:/workplace/HLS/Vitis_Lib/vision/L1/include -D__SDSVHLS__ -std=c++0x
Constraints for Co-simulation
There are few limitations in performing co-simulation of the Vitis vision functions. They are:
- Functions with multiple accelerators are not supported.
- Compiler and simulator are default in HLS (gcc, xsim).
- Since HLS does not support multi-kernel integration重要, the current flow also does not support multi-kernel integration. Hence, the Pyramidal Optical flow and Canny Edge Detection functions and examples are not supported in this flow.
- The maximum image size (HEIGHT and WIDTH) set in config.h file should be equal to the actual input image size.
AXI Video Interface Functions
Vitis vision具有将 xf::cv::Mat转换为Xilinx®Video Streaming interface 的功能,反之亦然。
xf::cv::AXIvideo2xfMat() 和 xf::cv::xfMat2AXIVideo() 充当Vivado®IP集成器中Vitis视觉功能IP的视频接口。
主机端使用cvMat2AXIvideoxf 和AXIvideo2cvMatxf 。
Table. AXI Video Interface Functions
Video Library Function | Description |
---|---|
AXIvideo2xfMat | Converts data from an AXI4 video stream representation to xf::cv::Mat format. |
xfMat2AXIvideo | Converts data stored as xf::cv::Mat format to an AXI4 video stream. |
cvMat2AXIvideoxf | Converts data stored as cv::Mat format to an AXI4 video stream |
AXIvideo2cvMatxf | Converts data from an AXI4 video stream representation to cv::Mat format. |
AXIvideo2xfMat
The AXIvideo2xfMat function receives a sequence of images using the AXI4 Streaming Video and produces an xf::cv::Mat representation.
AXIvideo2xfMat函数接收一系列使用AXI4流视频的图像,并生成xf :: cv :: Mat表示形式。
API Syntax
template<int W,int T,int ROWS, int COLS,int NPC>
int AXIvideo2xfMat(hls::stream< ap_axiu<W,1,1,1> >& AXI_video_strm, xf::cv::Mat<T,ROWS, COLS, NPC>& img)
Parameter Descriptions
The following table describes the template and the function parameters.
This function will return bit error of ERROR_IO_EOL_EARLY( 1 ) or ERROR_IO_EOL_LATE( 2 ) to indicate an unexpected line length, by detecting TLAST input.
For more information about AXI interface see UG761.
xfMat2AXIvideo
Mat2AXI视频功能接收图像序列的xf :: cv :: Mat表示形式,并使用AXI4流视频协议对其进行正确编码。
template<int W, int T, int ROWS, int COLS,int NPC>
int xfMat2AXIvideo(xf::cv::Mat<T,ROWS, COLS,NPC>& img,hls::stream<ap_axiu<W,1,1,1> >& AXI_video_strm)
此函数返回值0。
注意:数据流中所有函数的NPC值必须遵循相同的值。 如果不匹配,则会在HLS中引发编译错误。
cvMat2AXIvideoxf
The cvMat2Axivideoxf function receives image as cv::Mat representation and produces the AXI4 streaming video of image.
API Syntax
template<int NPC,int W>
void cvMat2AXIvideoxf(cv::Mat& cv_mat, hls::stream<ap_axiu<W,1,1,1> >& AXI_video_strm)
Parameter Descriptions
The following table describes the template and the function parameters.
Table. AXIvideo2cvMatxf Function Parameter Description
NPC
Parameter | Description |
---|---|
W | Data width of AXI4-Stream. Recommended value is pixel depth. |
NPC | Number of pixels to be processed per cycle. Possible options are XF_NPPC1 and XF_NPPC8 for 1-pixel and 8-pixel operations respectively. |
AXI_video_strm | HLS stream of ap_axiu (axi protocol) type. |
cv_mat | Input image. |
AXIvideo2cvMatxf
The Axivideo2cvMatxf function receives image as AXI4 streaming video and produces the cv::Mat representation of image
The Axivideo2cvMatxf function receives image as AXI4 streaming video and produces the cv::Mat representation of image
将HLS视频库迁移到Vitis vision
HLS视频库将很快被弃用。HLS视频库中的所有功能和大部分基础设施现在都可以在Vitis vision中使用,只是它们的名称发生了变化,并做了一些修改。这些HLS视频库功能移植到Vitis vision也支持构建流。
本节详细介绍如何使用c++视频处理函数和HLS视频库中提供的基础结构。
基础结构函数和类
所有从HLS视频库导入的函数现在都使用xf::cv::Mat(与Vitis vision库同步)来表示图像数据,而不是HLS::Mat。两者之间的主要区别是,hls::Mat使用hls::stream来存储数据,而xf::cv::Mat使用一个指针。因此,对于迁移来说,hls:: Mat不能完全替换为xf::cv::Mat。
下表总结了hls::Mat与xf::cv::Mat成员函数的区别。
HLS视频库中的基础结构文件hls_video_core.h, hls_video_mem.h, hls_video_types.h被移动到Vitis 视觉库中xf_video_core.h, xf_video_mem.h, xf_video_types.h
和hls_video_imgbase.h是弃用的。
这些文件中的代码没有改变,只是现在位于xf::cv::namespace之下。
Classes
Memory Window Buffer
hls::window is now xf::cv::window. No change in the implementation, except the namespace change. This is located in “xf_video_mem.h” file.
Memory Line Buffer
hls::LineBuffer is now xf::cv::LineBuffer. No difference between the two, except xf::cv::LineBuffer has extra template arguments for inferring different types of RAM structures, for the storage structure used. Default storage type is “RAM_S2P_BRAM” with RESHAPE_FACTOR=1. Complete description can be found here xf::cv::LineBuffer. This is located in xf_video_mem.h file.
Funtions
OpenCV接口功能
这些函数将OpenCV Mat格式的图像数据转换成(to/from)HLS AXI格式。HLS视频库有14个接口函数,其中有两个在Vitis vision库有效:位于“xf_axi.h”的cvMat2AXIvideo和AXIvideo2cvMat”文件。其余的废弃。
AXI4-Stream I/O函数
将hls::Mat转换为/从axi4流兼容数据类型(hls::stream)的I/O函数是hls::AXIvideo2Mat, hls::Mat2AXIvideo。现在,这些函数被弃用,并添加了两个新函数xf::cv::AXIvideo2xfMat和xf::cv:: xfMat2AXIvideo,以方便xf::cv::Mat的转换。要使用这些函数,头文件“xf_infra”。h "必须包括在内。
将hls::Mat与AXI4-Stream兼容数据类型(hls::stream)相互转换的I/O函数是hls :: AXIvideo2Mat,hls :: Mat2AXIvideo。 现在不推荐使用这些功能,并添加了2个新功能xf::cv::AXIvideo2xfMat 和 xf::cv:: xfMat2AXIvideo,以促进xf :: cv :: Mat 到/从 to/from的转换。 要使用这些函数,必须包含头文件“ xf_infra.h”。
xf::cv::window
表示2D窗口缓冲区的模板类。它有三个参数来指定:窗口缓冲区中的行数、列数和像素数据类型
template<int ROWS, int COLS, typename T>
class Window {
public:
Window()
/* Window main APIs */
void shift_pixels_left();
void shift_pixels_right();
void shift_pixels_up();
void shift_pixels_down();
void insert_pixel(T value, int row, int col);
void insert_row(T value[COLS], int row);
void insert_top_row(T value[COLS]);
void insert_bottom_row(T value[COLS]);
void insert_col(T value[ROWS], int col);
void insert_left_col(T value[ROWS]);
void insert_right_col(T value[ROWS]);
T& getval(int row, int col);
T& operator ()(int row, int col);
T val[ROWS][COLS];
#ifdef __DEBUG__
void restore_val();
void window_print();
T val_t[ROWS][COLS];
#endif
};
Member Function Description
…
xf::cv::LineBuffer
表示2D行缓冲区的模板类。它有三个参数来指定窗口缓冲区中的行数、列数和像素数据类型。
…
视频处理功能
下表总结了从HLS视频库移植到Vitis vision库的视频处理函数以及API的修改。
…
使用Vitis视觉库
本节介绍如何在Vitis开发环境中使用Vitis vision库。
include文件夹包含使用库构建计算机视觉或图像处理流水线所需的所有组件。
文件夹common和core包含库函数用于基本函数、Mat类和宏所需的基础结构。
库函数根据其执行的操作分为4个文件夹:feature、video、dnn和imgproc。文件夹的名称是不言自明的。
…
改变硬件内核配置
Update the
在硬件上使用Vitis的视觉库函数
下表列出了Vitis vision库函数和在硬件上运行相应示例的命令。假设您的设计已经完全完成,并且板已经正确启动。