版权声明:转载注明出处:邢翔瑞的技术博客https://blog.csdn.net/weixin_36474809 https://blog.csdn.net/weixin_36474809/article/details/85257372
背景:第一次编写的IPcore存在问题,没有加入偏置与ReLU
目的:给IPcore加入偏置和ReLU。
一、最终BRAM尺寸的确定
1.1 IBRAM
//calculate parameters about IBRAM
printf("inWidth = %d, in_ChannelNum = %d \n",inWidth, inChanNum);
int input_pixel = inWidth*inChanNum*NUM_IMG_CACHE_LINES;
if (input_pixel > Max_input_image_pixels)
Max_input_image_pixels = input_pixel;
printf("-----------Max_input_image_pixels = %d-----------\n",Max_input_image_pixels);
输入的图片尺寸的大小,
1.2 WBRAM
//calculate parameters about WBRAM
int out_channelNum=OutChanNum;
printf("OutchanelNum = %d , inChannelNum = %d \n",out_channelNum, inChanNum);
int max_co_Num_per_PE=(out_channelNum+N_PE-1)/N_PE;
printf("max_co_Num_per_PE= %d \n",max_co_Num_per_PE);
int max_filters_per_PE=max_co_Num_per_PE*inChanNum;
printf("max_filters_per_PE= %d\n \n",max_filters_per_PE);
if(max_co_Num_per_PE>MAXCO_PER_PE)MAXCO_PER_PE=max_co_Num_per_PE;
if(max_filters_per_PE>MAX_FILTERS_PER_PE)MAX_FILTERS_PER_PE=max_filters_per_PE;
printf("-----------%d %d --------\n",MAXCO_PER_PE,MAX_FILTERS_PER_PE);
1.3 OBRAM
//calculate parameters about OBRAM
printf("\nCo num = %d \n",OutChanNum);
if(out_channelNum > max_out_channelNum) max_out_channelNum=out_channelNum;
printf("******** max_out_channelNum = %d *********\n",max_out_channelNum);
1.4 加入BBRAM
表示偏移的BRAM,尺寸为最大的输出通道的个数。
float BiasCache::BBRAM[MAX_NUM_CHOUT];
1.4 定义
// ==========================
// = Architecture Constants =
// ==========================
// Number of Image Cache Lines (need 3, use 4 for simplified Addressing HW)
const int NUM_IMG_CACHE_LINES = 4;
// Number of Processing Elements
const int N_PE = 8;
const int DRAM_DEPTH = 5932576;
//IBRAM, OBRAM, WBRAM size (this value need to be changed by network)
const int MAX_IMAGE_CACHE_SIZE = 8704;
const int MAX_NUM_CHOUT = 128;
//const int MAX_CO_PER_PE=8;
// const int MAX_2D_FILTERS_PER_PE=1024;
const int MAX_2D_FILTERS_PER_PE= 2048;
//-------------Cache BRAM variable----------------
float OutputCache::OBRAM[MAX_NUM_CHOUT];
float ImageCache::IBRAM[MAX_IMAGE_CACHE_SIZE];
float WeightsCache::WBRAM[N_PE][MAX_2D_FILTERS_PER_PE][9];
二、程序之中结构嵌套及
未完