HLS实验一--乘法器


前言

本次实验使用了两种方法,分别是直接调用组件和以流水线的方式调用组件。

流水线使用到的函数

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个。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值