前言
本次实验使用了两种方法,分别是直接调用组件和以流水线的方式调用组件。
流水线使用到的函数
1.排队函数
ihc_hls_enqueue(void *retptr, void *funcptr,/*function arguments*/)
参数:
retptr:返回值
funcptr:将要调用的HLS component
这个函数对HLS组件的一次调用进行排队。返回值存储在第一个实参中,该实参应该是指向返回类型的指针。在调用ihc_hls_component_run_all()之前,组件不会运行。
2.没有返回类型的排队函数
ihc_hls_enqueue_noret(void* funcptr,/*function arguments*/)
参数:
funcptr:将要调用的HLS component
这个函数对HLS组件的一次调用进行排队。当HLS组件的返回类型为void时,应该使用这个函数。在调用ihc_hls_component_run_all()之前,组件不会运行。
3.开启组件函数
ihc_hls_component_run_all(void* funcptr)
参数:
funcptr:将要调用的HLS component
这个函数接受一个指向HLS组件函数的指针。组件的所有排队调用在运行时将被推入,当组件能够接受新的调用时,HDL模拟器就能以最快的速度运行。
参考文章
https://blog.csdn.net/qq_42585108/article/details/120614492
一、直接调用组件
#include<HLS/stdio.h>
#include<HLS/hls.h>
#include<assert.h>
#include<stdlib.h>
component int multiplication(int a,int b) {
return a * b;
}
int main() {
srand(0);
int i, x[10] = { 0 }, y[10] = {0}, z[10] = { 0 };
for (i = 0; i < 10; i++) {
x[i]= rand() % 10;
y[i]= rand() % 10;
z[i]= multiplication(x[i], y[i]);
printf("%d = %d * %d \n", z[i],x[i],y[i]); //打印查看是否正确
assert(z[i] == x[i] * y[i]); //调用断言函数
}
return 0;
}
1.生成hls环境
2.使用i++ -march=x86-64 multiplication.c -v
查看C语言是否编写正确。并运行生成的a.exe。
3.使用i++ -march=CycloneV multiplication.c -v -ghdl
进行hls上的编写
4.运行生成的a.exe文件并运行vsim a.prj/verification/vsim.wlf
进行仿真
二、使用流水线的方法
#include<HLS/stdio.h>
#include<HLS/hls.h>
#include<assert.h>
#include<stdlib.h>
component int multiplication(int a,int b) {
return a * b;
}
int main() {
srand(0);
int i, x[10] = { 0 }, y[10] = {0}, z[10] = { 0 };
for (i = 0; i < 10; i++) {
x[i]= rand() % 10;
y[i]= rand() % 10;
// z[i]= add(x[i], y[i]);
// printf("%d = %d + %d \n", z[i],x[i],y[i]);
ihc_hls_enqueue(&z[i], &add, x[i], y[i]);
//ihc_hls_enqueue_noret(&add, x, y);
//assert(z[i] == x[i] + y[i]);
}
ihc_hls_component_run_all(add);
return 0;
}
前面三步与上面的一样,我们直接来看仿真
三、两种模式的对比
1.仿真
通过两者的仿真可以清楚的看到,我们在直接调用组件的时候启动了10次组件,而在使用流水线时,就只调用了1次组件。这大大节约了我们的硬件资源。
2.报告
报告地址:a.prj/reports/report.html
通过报告可以明显的看到,第一种方法并没有排队的组件,而第二种方法就有10个。