《如何利用Vivado HLS处理许多位准确或任意精度数据类型.docx》由会员分享,可在线阅读,更多相关《如何利用Vivado HLS处理许多位准确或任意精度数据类型.docx(11页珍藏版)》请在第一文库网上搜索。
1、如何利用VivadoH1S处理许多位准确或任意精度数据类型我们在设计硬件时,它往往是要求更精确的位宽。例如,一个fi1拄r的输入是12位和一个累加器的结果只需要一个最大范围为27位。然而对于硬件设计来说,使用标准的C数据类型会造成硬件成本的浪费。这就会造成我们要使用更多的1UT和寄存器,延迟甚至可能超过时钟周期和需要更多的周期来计算结果。这往往不是我们需要的结果。因此下面我将介绍如何利用ViV理。H1S处理许多位准确或任意精度数据类型,以及允许使用任何(任意)宽度的模型变量。C-base数据类型我们从硬件的角度来看数据类型,采用C/生的数据类型都是以8bit为边界,即:?char(8-bit)
2、?short(16-bit)?int(32-bit)?1ong1ong(64bit)?f1oat(32-bit)?doub1e(64-bit)?确切的宽度的整数类型如int16_t(16-bit)和int32_t(32-bit)注意:CharI6_t和Char32_t在ViVadoH1s中是不支持的从上面发现,C的数据位宽是比较死板的,然而描述RT1里面的位宽是任意的。例如,采用细宣去描述一个18*18bits的乘法器,那么就需要将输入数据都声明为32bits(int),结果声明为64bits(1ong1ong),这将会在坦逊_中消耗4个暨48E1,显然这是很浪费资源的。任意精度数据类型1an
3、guageIntegerDataTypeRequiredHeaderCuint(1024bits).ftinc1udeC+ap_uint(1024bits).ttinc1udeC+ap_ufixed,ftinc1ude其优点有:1.更高的时钟频率2.更好的数据吞吐率3.消耗资源更少因此,使用任意精度数据类型能以更少的资源,获得相同的精度,同时可以运行在更高的时钟频率下。注意:在声明任意数据类型的时候,我们往往在头文件里面声明,这会使得我们在做debug的时候会非常有用。Step1创建和打开projectI .打开ViVadoH1SCommandPrompt,按照下图输入命令F:VIVAD0Vi
4、vado_H1S2016.31s1ABbincommondatadocexamp1esinc1ude1ibmsysscriptssrctpsvivadoF:VIVADOVivado.H1S2016.3cd1ABF:VIVADOVivado.H1S2016.31AB1sArbitrary_PrecisionDeSign.Ana1ysisInterface_SynthesisRT1_VerificationUsC_Va1idationDeSignOptimizationIntroductionUsing_IP_with_IPIUsF:VIVAD0Vivado_H1S2016.31ABcdArbit
5、rary_PrecisionF:VIVAD0Viuado_H1S2016.31ABArbitrary_PrecisioncdIab1F:VIVAD0Vivado_H1S2016.31ABArbitrary_Precision1ab1vivado_h1s-frun_h1s.tc1II .输入ViVadojhIS-pwindow_fn_prjsw_resu1t=9.37258sw_resu1t=5.39297sw_resu1t=2.43585sw_resu1t=0.61487i.=28hw_resu1t=9.37258i-29hw_resu1t-5.39297i=30hw_resu1t=2.435
6、85i-31hw_resu1t-0.61487estPassedINFO:SIM211-1CSimdonewith0errors.INFO:SIM211-3*CSIMfinish*:VIVAD0Vivado_H1S2016.31ABArbitrary_Precision1ab1vivado_h1sStep2ReviewTestBench和runCSimu1ationI.在Source打开window_fn_top.cpp555657585960616263646566672Vendor:Xi1inx45 #inc1udewindow_fn_t|Dp.h/Providestypedefsandp
7、arams4647。Inc1udetheentirexh1swindowfnnamespacesothatscoper48 /i.e.prependingxh1s_window_fn:toeverything-isnotne49 usingnamespacexh1swindowfn;5051/VivadoH1Srequiresatop-1eve1functiondefinitionthatwra52/instantiationsandmethodca11stobesynthesizedaswe11a53/thetop-1eve1I/O(functionarguments)into/outoft
8、hemeth5-voidwindowfntop(win_fn_out_toutdataWIN_1EN,win_fn_in_tindataWIN_1EN)/Instantiateawindowfnobject-typesandParamSdefinewindowfnmy_win_fn;/Ca11theapp1y()method-aninputdatasetiswindowed/towindow_fn_top()mywinfn.app1y(outdata,indata);I1找到WindoW_fn_top.h,按住Contro1键,并右击,打开window_fn_top.h(头文件)4546474
9、8495051525354555657585960616263642bendor:Xi1inxB*j#ifndefWINDOW_FN_TOP_H_#defineWINDOW_FN_TOP_H_#inc1udewindow_fn_c1ass.h/Testparameters#defIneF1OAT_DATA/Usedtose1ecterrorto1eranceintestP#defineWIN_TYPExh1s_window_fn:HANN#defineWIN_1EN32/Definef1oatingpointtypesforinput,outputandwindowcotypedeff1oat
10、win_f;typedeff1oatwin_fn_out_t;typedeff1oatwin_fn_coef_t;/Top1eve1functionprototype-wrapsa11object,methodandvoidwindow_fn_top(win_fn_out_toutdataWIN_1EN,win_fn_in_t#endif/WINDOW_FN_TOP_H_在这里,我们可以看到,本设计所有数据类型的操作都是标准C/C+的浮点型。III点击RUnCSimu1ationStep3RunCSimu1ation和ReviewResu1ts1点击RunCSynthesisPerforman
11、ceEstimatesETiming(ns)SummaryC1ockTargetEstimatedUncertaintyap_c1k5.003.750.63E1atency(c1ockcyc1es)BSummary1atencyInterva1minmaxminmaxType257257258258noneDetai1SInstanceS1oopUti1izationEstimatesESummaryNameBRAMJ8KDSP48EFF1UTDSP-Expression-09FIFO-Instance-3151148Memory1-00Mu1tip1exer-10Register-123-T
12、ota113274167Avai1ab1e65060020281014Uti1ization(%)00-00BDetai1Instance图中我们发现,顶层中的instances占用了大部分资源。I1打开InterfaceSummaryInterfaceESummaryRT1PortsDirBitsProtoco1SourceObjectCTypeapc1kin1apCtr1hswindow_fn_topreturnva1ueapjstin1apctr1hswindowfntopreturnva1ueap_startin1apctr1hswindowfn_topreturnva1ueapdon
13、eout1apCtr1hswindowfntopreturnva1ueapidIeout1ap_ctr1_hswindow_fn_topreturnva1ueapreadyout1apctr1hswindowfntopreturnva1ueOutdataaddressOout5apememoryoutdataarrayoutdata_ceOout1apmemoryoutdataarrayoutdata_weOout1apmemoryoutdataarrayoutdatadOout32ap-memoryoutdataarrayIndataaddressOout5apememoryindataarrayindata_ceOout1ap-memoryindataarrayindataqin32aPjnemoryindataarrayExportthereport(.htm1)usingtheOpenAna1ysisPerspectiveEXPOrtWiZardAnaIySiSPerSPectiVe口?少点MOperationContro1StepCO1Ewinfn_1oop2i_i(phi_mux)3tmp_i(icmp)4i(+)CurrentModu1e:window_fn_topI11点击AnaIySis,打