2 创建一个Vivado-HLS工程 - Xilinx Forums
- 格式:doc
- 大小:829.50 KB
- 文档页数:15
用Vivado-HLS实现低latency 除法器George Wang – Xilinx DSP Specialist
Table of Contents
1VIVADO HLS 简介 (3)
2创建一个VIVADO-HLS工程 (4)
2.1打开V IVADO HLS GUI (4)
2.2创建新工程 (5)
2.3添加源文件 (6)
2.4添加测试文件 (8)
2.5创建SOLUTION (10)
3 C VALIDATION (12)
4 C SYNTHESIS (13)
5EXPLORE 不同新的SOLUTION (15)
1 Vivado 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 <version> > 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; // <quo>+1 bits unsigned
subtract_t sub_out, rem_r; // <divisor>+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<stdio.h>
#include<math.h>
#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
创建solution, 时钟约束, 并选器件.
打开包括工程信息Vivado HLS GUI.
3 C Validation
在将c/c++/system c 转换成RTL之前,必须先验证C 设计,确保其功能是正确的点击“Run C Simulation”图标,
4 C Synthesis
现在可以对设计做C 综合,生成RTL代码. 当综合完成,, GUI 更新综合结果. 包括资源使用,latency等。
为了达到了预先要求为3 个时钟周期,将latency 的directive设置为3。
5 Explore 不同新的Solution
project -> new solution。
在同一个工程里面,可以使用同一套源代码,进行不同solutions的尝试。