HLS调用vitis库
文章目录
- HLS Standalone Mode
- Tcl Script Mode
- GUI Mode
- Constraints for Co-simulation
- AXI Video Interface Functions
- AXIvideo2xfMat
- xfMat2AXIvideo
- cvMat2AXIvideoxf
- AXIvideo2cvMatxf
- 将HLS视频库迁移到Vitis vision
- 基础结构函数和类
- Classes
- Funtions
- xf::cv::window
- xf::cv::LineBuffer
- 视频处理功能
- 使用Vitis视觉库
- 改变硬件内核配置
- 在硬件上使用Vitis的视觉库函数
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_ptrxf::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 /visoin/L1/examples//build/xf_config_params.h file.
在硬件上使用Vitis的视觉库函数
下表列出了Vitis vision库函数和在硬件上运行相应示例的命令。假设您的设计已经完全完成,并且板已经正确启动。
HLS调用vitis库相关推荐
- H5播放HLS之hls.min.js库
H5播放HLS之hls.min.js库 视频推流 H播放HLS 视频推流 为了产生HLS视频,我们可以借助srs来实现rtmp推流并生成HLS流,具体详细使用可以参考我之前的文章,这里不再赘述. 我们 ...
- linux下Qt调用C++库文件(.so)程序实现
文章目录 主要内容 一.编程环境及实现方法 二.项目实现 1.创建项目 2.导入库文件 三.项目中遇到的问题 总结 主要内容 如标题所示,在linux下使用qtcreator创建项目调用C++库文件, ...
- Dictionary作为数据源绑定,调用c++库中返回为BYTE*的函数,listView项排序
最近在做一个电子档案管理的项目.现在还处于初期,只是做一个简单demo拿去跟客户演示.至于最后谈不谈得下来,到底做不做,反正我是不看好,但没因为这样就马马虎虎.草草了事.这个项目算是b/s加c/s混合 ...
- .NET 调用c++库注意事项
原文:.NET 调用c++库注意事项 很久没有更新了,主要还是因为自己懒吧,希望从今天开始坚持至少一周写一篇文章. 调用函数库是正常的,调用完成后,在使用EF进行数据更新时,将发生如下异常信息,而且几 ...
- python 调用 so 库 需要注意的地方
2019独角兽企业重金招聘Python工程师标准>>> 使用C++而不是C来编写so库时往往会遇到一些问题,这里着重探讨一下linux环境下C++编写so库 及python调用so库 ...
- 【C 语言】动态库封装与设计 ( 动态库调用环境搭建 | 创建应用 | 拷贝动态库相关文件到源码路径 | 导入头文件 | 配置动态库引用 | 调用动态库中的函数 )
文章目录 一.在 Visual Studio 2019 中创建 " 控制台应用 " 程序 二.拷贝 xxx.lib.xxx.dll.xxx.h 到源码路径 三.导入 xxx.h 头 ...
- 【C 语言】动态库封装与设计 ( Windows 动态库简介 | Visual Studio 调用动态库 )
文章目录 一.Windows 动态库简介 二.Visual Studio 调用动态库 一.Windows 动态库简介 在 C:\Windows\System32 目录中 , 存放着 Windows 中 ...
- linux用c++调用动态库
1.3 用c++静态方式调用动态库libsthc.so: /*cpptest.cc*/ //linux下的c++后缀有cc,cxx, cpp #include "libsthc.h&q ...
- C#.net调用动态库dll注意事项
C#.net调用动态库dll注意事项 本文主要描述作者在工作中所遇到技术难点及问题,最后提出相关的解决方案 场景 公司有个业务需求涉及到ID读卡器,构建成在ID卡读卡器一刷ID卡,系统就自动显示其ID ...
最新文章
- css3弹性盒子模型之box-flex
- [poj] 2318 TOYS || 判断点在多边形内
- php热门标签,PHP显示最流行的标签
- COMCMS_CORE 起步篇,如何运行和部署
- 百度地图android绘图类,Class:android总类/android离线地图类
- Java常见的几种设计模式
- C++:构造函数重载类内定义函数(内联函数)
- 微信 - 微信语音转发好友 / 朋友圈方法
- 无限浏览器代理服务器,老司机浏览器无限版
- ensp官方停止下载
- 三维向量的一些运算技巧,如何计算坐标
- discuz模板机制
- 银河麒麟服务器修改ip,银河麒麟配置DNS服务器
- 条件运算符(三目运算符)
- 第八章 界面外观——Qt
- 盘点激光雷达常用的10大数据处理软件
- 如何阻止迅雷自动下载?
- QtAV学习笔记 解决RTSP流无法播放问题(三)
- H323——H239演示功能
- java 练习03 - 判断是否是闰年