George Wang – Xilinx DSP Specialist
1Vivado HLS 简介
Xilinx Vivado High-Level Synthesis (HLS) 工具将 C, C++,或者 SystemC 设计规范,算法转成 Register Transfer Level (RTL)实现,可综合到Xilinx FPGA。
将DSP算法快速转到RTL FPGA 实现
将C 至 RTL时间缩短 4 倍
基于 C 语言的验证时间缩短100倍
RTL 仿真时间缩短 3 倍
2创建一个Vivado-HLS工程
2.1打开Vivado HLS GUI
双击桌面上Vivado HLS GUI 图标, 或从Start > All Programs >
Vivado > Vivado HLS GUI
打开GUI之后,Vivado-HLS welcome界面如下所示:
2.2创建新工程
在 Welcome Page, 选择Create New Project
2.3添加源文件
本除法器设计采用移位算法
#include "radix2div.h"
quotient_t radix2div (
dividend_t dividend, // (numerator)
divisor_t divisor, // (denominator)
remainder_t *remainder //
) {
#pragma AP latency max=3
#pragma AP pipeline
quotient_i_t quo, y; // +1 bits unsigned
subtract_t sub_out, rem_r; //
+1 bits signed
boolean_t last_bit, next_bit;
loop_cnt_t i;
///
last_bit = 0;
rem_r = 0;
if (LOOP_MAX > 32)
quo = 0ULL;
else
quo = 0;
//
div_booth_label0: for (i = 0; i < LOOP_MAX; i = i+1) {
// concurrent blocks
sub_out = rem_r - divisor;
y = dividend & 1 << (LOOP_MAX-i-2);
if ( y == 0 )
next_bit = 0;
else
next_bit = 1;
if (sub_out < 0) { // remainder - denominator is negative
quo = quo << 1;
if (i != LOOP_MAX-1) {
rem_r = rem_r << 1;
rem_r = rem_r | next_bit;
}
}
else { // remainder - denominator is positive
quo = quo << 1;
quo = quo | 1;
if (i != LOOP_MAX-1) {
rem_r = sub_out << 1;
rem_r = rem_r | next_bit;
}
else
rem_r = sub_out;
}
} // end for
*remainder = rem_r;
return quo;
}
2.4添加测试文件
#include #include
#include "radix2div.h"
//
quotient_t radix2div (
dividend_t dividend, // (numerator)
divisor_t divisor, // (denominator)
remainder_t *remainder //
);
//
int test_divider (dividend_t dividend,
divisor_t divisor
)
{
quotient_t quotient;
remainder_t remainder;
quotient = radix2div(dividend,divisor,&remainder);
fprintf(stdout, ">>>>>>>>> dividend = %u, divisor = %u quotient = %u remainder = %u \n",
dividend, divisor, quotient, remainder);
fprintf(stdout, ">>>>>>>>>-------------------- \n");
if ((quotient == dividend/divisor) && (remainder == dividend-(divisor*quotient)) ) {
printf ("PASS \n");
}
else {
printf ("FAIL \n");
return 1;
}
}
//
int main () {
int i, j;
dividend_t max_num;
max_num = 0;
j = LOOP_MAX-1;
for (i = 0; i < j; i = i+1) {
max_num = max_num + pow(2,i);
}
//
test_divider (max_num,1);
test_divider (2,pow(2,9)-1);
test_divider (max_num,pow(2,9)-1);
test_divider (8,1);
test_divider (99,10);
//
}
2.5创建solution
3C Validation
在将c/c++/system c 转换成RTL之前,必须先验证C 设计,确保其功能是正确的
4C Synthesis
现在可以对设计做C 综合,生成RTL代码. 当综合完成,, GUI 更新综合结果. 包括资源使用,latency等。
为了达到了预先要求为3 个时钟周期, 将latency 的directive设置为3。
5Explore 不同新的Solution
project -> new solution。