HLS Lesson15-for循环优化:其他方法

时间:2022-04-28
本文章向大家介绍HLS Lesson15-for循环优化:其他方法,主要内容包括例1:、例2:pipeline+rewind、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

例1:

void for_merge(data_t a[N],data_t b[N],data_t c[N],data_t d[N])
{
data_t x_a = 0;
data_t y_a = 0;
int i;
int j;
sum_x:
for(i=0;i<N;i++)
{
x_a+=a[i];
c[i]=x_a;
}
sum_y:
for(j=0;j<N;j++)
{
y_a+=b[j];
d[j]=y_a;
}
}

采用allocation将两个for循环进行并行执行。

#include"for_merge.h"
void accumulator(data_t a[N],data_t b[N])
{
data_t a_t=0;
sum:
for(int i=0;i<N;i++)
{
a_t+=a[i];
b[i]=a_t;
}
}
void for_merge(data_t a[N],data_t b[N],data_t c[N],data_t d[N])
{
accumulator(a,c);
accumulator(b,d);
}

例2:pipeline+rewind

例3:给当循环变量是变量时

(1)使用trip count directive

(2)使用ap_int<w>定义变量类型

(3)使用assert宏:消耗资源最少,latency最小