写在前面

库的说明
“math.h”是C语言中数学函数库,包含我们常用的一些数学计算上会使用到的函数。
C++中有对应相同作用的头文件“cmath”,当然C++中两个头文件都可以使用,C++向C兼容。
即C-math.h, C++-cmath.h

lab1

// 命令行指令汇总,便于复制粘贴
// Chapter5 Lab1
// 进入指定目录运行
cd C:\Users\RicNid\Desktop\ug871-design-files\Arbitrary_Precision\lab1
vivado_hls -f run_hls.tcl
vivado_hls -p window_fn_prj

window_fn是什么?是一个模板类型,用类模板定义对象的写法如下:
类模板名<真实类型参数表> 对象名(构造函数实际参数表);
window_fn WIN_LEN,WIN_TYPE> my_win_fn;
上面表达的实质:窗函数的类模板实例名称

下面是本例中模板类型的代码
// The window_fn template class
// TI: input type - can be any floating or fixed point (ap_fixed<>) type
// TO: ouput type - same as TI
// TC: coefficient type - same as TI
// SZ: window size
// FT: function type - Hann, Hamming, etc; enumerated above
template
class window_fn {
const int win_len;
const win_fn_t win_type;

public:
window_fn(void) : win_len(SZ), win_type(FT) {};

// The method that convolves indata w/ the window coeffs
void apply(TO outdata, TI indata);

// Get methods for polling class instance info - if not used, no hardware
// will be created for them
int get_len(void) { return win_len; };
win_fn_t get_type(void) { return win_type; };
};

// Define floating point types for input, output and window coefficients
typedef float win_fn_in_t;
typedef float win_fn_out_t;
typedef float win_fn_coef_t;
使用typedef为现有类型创建别名,定义易于记忆的类型名
使用别名,易于记忆,易于分类,易于阅读
win_fn_in_t其实就是float浮点型
不过,win_fn_t是一个enum枚举型

17.4版本的HLS没有格子线,综合的资源有差异,少了Available SLR,少了Utilization SLR
Utilization-利用率

SLR是什么?
“Stacked Silicon Interconnect (SSI) Technology”
堆叠硅互连(SSI)技术
“A Super Logic Region (SLR) is a single FPGA die slice contained in an SSI device”
超级逻辑区域(SLR)是包含在SSI设备中的单个FPGA芯片
所以,SLR代表超级逻辑区域,我的理解是这反映高端FPGA的资源情况。
观察ug871给出的截图,可知使用SLR资源只使用普通资源的1/3。

hw_result代表硬件结果,sw_result代表软件结果,这是由用户testbench定义的。
两者相同则测试通过,因为Checking results against a tolerance of 0
容忍度设置为0,因为两者的精度相同,所以可以做全等比较

换用18.3版本的HLS后有了格子线,但是综合资源还是有差异,也没有SLR部分结果。

下图为Design Analysis中的时序
第一个周期是读内存,最后一个周期是写内存,所以中间的部分是计算
可能是综合策略问题,我综合的结果要比ug871中长2个周期
image.png

lab2

// Chapter5 Lab2
// 进入指定目录运行
cd C:\Users\RicNid\Desktop\ug871-design-files\Arbitrary_Precision\lab2
vivado_hls -f run_hls.tcl
vivado_hls -p window_fn_prj

lab2更换了数据类型
typedef float变成typedef ap_fixed
• W_IN defines the total word length.总长度
• IW_IN defines the number of integer bits. 整数部分长度
• The number of fractional bits is therefore the first term minus the second.小数部分长度
使用任意精度类型来改善代码,一般会去减少数据类型的大小
这可以使得运算使用更少的操作、更小的面积、更短的周期

一个DSP48E最多可以执行18*27的乘法

与lab1不同,lab2设置的tolerance变成了0.001
hw_result和sw_result不再做全等比较
因为数据精度的不同,硬件部分是ap_fixed,软件部分的预期结果还是float
所以这会导致小数点后几位有差异,需要设置tolerance

Design Analysis
image.png
时序部分由8周期变成3周期,主要变化在乘法

资源比较
lab1
image.png
image.png
image.png
lab2
image.png
image.png
image.png
lab1是3个DSP48E,而lab2出现了DSP资源,只用了1个DSP48E
我的理解lab1因为单个DSP48E无法完成,由3个DSP48E和许多FF、LUT构成了一个fmucud;lab2是直接使用了一个乘法器模块mulcud,所以DSP=1,DSP48E=1
可以看出op lantency由4减少到0,由跨越4个时钟周期到在1个时钟周期完成
DSP是18*27
lab1
image.png
lab2
image.png
lab1用了BRAM_18K,而lab2没有。具体是1个bram变成17FF和9LUT
书上说是总内存开销小于1024-bits,自动使用LUTs和FFs来代替block memory.
乘法器、寄存器开销减少
从Interface summary中可以看到outdata_V_d0从32位下降到24位,indata_V_q0从32位下降到8位

总结

本章介绍了如何使用任意精度类型以及其优势。