FPGA(HLS)实现神经网络的 Add函数、Maxpool函数、upsample2D函数

#include"addp_upool.h"
#include "string.h"

Dtype_16f maxfour(Dtype_16f a,Dtype_16f b,Dtype_16f c,Dtype_16f d){
	return max(max(a,b),max(c,d));
}
void cpy_poolbuf(Dtype_16f* In_ddr,Dtype_16f pool_bus1[Tww],INT8 Tw,int of){
	memcpy(pool_bus1, (Dtype_16f *)(In_ddr + of), Tw*sizeof(Dtype_16f));
}
void addcpdr2_lin(Dtype_16f* In_ddr,Dtype_16f* In_ddr2,Dtype_16f pool_bus1[Tww],Dtype_16f pool_bus2[Tww],Dtype_11f hz,Dtype_11f wz,Dtype_11f cz,Dtype_11f win,
		Dtype_19f winxhin,Dtype_16f t,Dtype_11f inchan,INT8 Tw,Dtype_16f inxTh){
	if(t>=inxTh)
		return;
	Dtype_11f t1=t%inchan;
	Dtype_11f t2=t/inchan;
	Dtype_11f c=t1+cz;
	Dtype_11f h=t2+hz;
	int of=c*winxhin+h*win+wz;
	cpy_poolbuf(In_ddr, pool_bus1, Tw, of);
	cpy_poolbuf(In_ddr2, pool_bus2, Tw, of);
}
void addcplin2_buf(Dtype_16f pool_in[inchannel][Thh][Tww],Dtype_16f pool_bus1[Tww],Dtype_16f pool_bus2[Tww],
			Dtype_16f t,Dtype_11f inchan,INT8 Tw){
	if(t<0)
		return;
	INT8 t3;
	Dtype_11f t1=t%inchan;
	Dtype_11f t2=t/inchan;
	for(t3=0;t3<Tw;t3++){
#pragma HLS PIPELINE II=1
		pool_in[t1][t2][t3]=pool_bus1[t3]+pool_bus2[t3];
	}

}
void Add(Dtype_16f* In_ddr,Dtype_16f* In_ddr2,Dtype_16f pool_in[inchannel][Thh][Tww],
		INT8 Th,INT8 Tw, Dtype_11f hz,
Dtype_11f wz,Dtype_11f cz,Dtype_11f win,Dtype_11f chin, Dtype_19f winxhin){
		if(cz>=chin)
			return;
		INT8 cc,hh,ww;
		Dtype_11f inchan=inchannel;
//		int of;
		Dtype_16f t;
		static Dtype_16f pool_bus1[Tww];
		static Dtype_16f pool_bus2[Tww];
		static Dtype_16f pool_busb1[Tww];
		static Dtype_16f pool_busb2[Tww];
		if(cz+inchannel>chin)
			inchan=chin-cz;
		Dtype_16f inxTh=inchan*Th;
		bool pp=true;
		for(t=0;t<inxTh+1;t++){
			if(pp)
			{
				addcpdr2_lin( In_ddr, In_ddr2, pool_bus1, pool_bus2, hz, wz, cz, win,
						 winxhin, t, inchan, Tw,inxTh);
				addcplin2_buf( pool_in, pool_busb1, pool_busb2,
							 t-1, inchan, Tw);
				pp=false;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值