使用HLS各种问题
关于求指数函数 exp(x)
在HLS中使用exp(x),也就是指数函数。不能导出RTL到EDK也就是Pcore 只能导出为VIVADO IP:相关解释:见官方论坛
http://forums.xilinx.com/t5/High-Level-Synthesis-HLS/pow-function-in-Pcore-Export/td-p/470178
解决办法只能通过通过vivado来做:http://www.xilinx.com/support/documentation/sw_manuals/xilinx2013_2/ug994-vivado-ip-subsystems.pdf http://www.xilinx.com/support/documentation/sw_manuals/xilinx2013_2/ug902-vivado-high-level-synthesis.pdf
我的解决办法是非不入流:我用VS2010或者matlab计算相应从0到30000的指数函数结果,然后保存到文件中,之后在HLS中通过查表法去访问我需要的指数函数计算结果,这种方法是你需要提前能预测你需要的区间。这种方法从计算的角度是可以简化时间的。
Unsupported C Constructs(HLS可综合化 )
UG902 page326
虽然HLS支持大部分C语言原型,但是有部分还是不能支持,总的来说可综合化有下面几点要求:
To be synthesized:
• The C function must contain the entire functionality ofthe design. • None of the functionality can be performed by system calls to the operatingsystem.
不能系统调用操作系统 • The C constructs must be of a fixed or bounded size.
C的构造中必须是定长或者有边界的 • The implementation of those constructs must be unambiguous
必须是明确的构造
不支持以下操作
System Calls
不能在函数实现中调用系统函数,类似与printf、getc、time、等等,可以用宏 __SYNTHESIS__ 来处理可综合与不可综合的代码。列入以下程序
include hier_func4.h int sumsub_func(din_t *in1, din_t *in2, dint_t *outSum, dint_t *outSub) { *outSum = *in1 + *in2; *outSub = *in1 - *in2; } int shift_func(dint_t *in1, dint_t *in2, dout_t *outA, dout_t *outB) { *outA = *in1 >> 1; *outB = *in2 >> 2; } void hier_func4(din_t A, din_t B, dout_t *C, dout_t *D) { dint_t apb, amb; sumsub_func(&A,&B,&apb,&amb); #ifndef __SYNTHESIS__ //通过宏来处理可综合与不可综合代码,但是在仿真的时候却是可以起作用的!! FILE *fp1;// The following code is ignored for synthesis char filename[255]; sprintf(filename,Out_apb_%03d.dat,apb); fp1=fopen(filename,w); fprintf(fp1, %d \n, apb); fclose(fp1); #endif shift_func(&apb,&amb,C,D); }
Dynamic MemoryUsage
Any system callsthat manage memory allocation within the system, for example,malloc(), alloc(),and free() are using resources that exist in the memory of the operating systemand are created and released during run time: to be able to synthesize ahardware implementation the design must be fully self-contained, specifying allrequired resources. Memory allocation system calls mustbe removed from the design code before synthesis.Because dynamic memoryoperations are used to define the functionality of the design,they must betransformed into equivalent bounded representations. The following code exampleshows how a design using malloc() can be transformed into asynthesizableversion and highlights two useful coding style techniques:
HLS不支持动态内存分配,也就是不支持在程序运行时才分配内存,反之就是只支持在程序编译的时候就要确定大小的代码。
.The design doesnot use the __SYNTHESIS__ macro.
Theuser-defined macro NO_SYNTH is used to select between the synthesizable andnon-synthesizable versions. This ensures that the same code is simulated in Cand synthesized in Vivado HLS.
.The pointers inthe original design using malloc() do not need to be rewritten towork withfixed sized elements.
Fixed sizedresources can be created and the existing pointer can simply be made to pointto the fixed sized resource. This technique can prevent manual re-coding of theexisting design.
Transformingmalloc() to Fixed Resources(修改代替malloc函数的方法)
#include malloc_removed.h #include <stdlib.h> //#define NO_SYNTH dout_t malloc_removed(din_t din[N], dsel_t width) { #ifdef NO_SYNTH //不可综合的代码,包括malloc函数 long long *out_accum = malloc (sizeof(long long)); int* array_local = malloc (64 * sizeof(int)); #else long long _out_accum; long long *out_accum = &_out_accum;//指针必须指向的是定长的变量 int _array_local[64];//只支持在编译时候就定长的数组 int* array_local = &_array_local[0]; #endif int i,j; LOOP_SHIFT:for (i=0;i<N-1; i++) { if (i<width) *(array_local+i)=din[i]; else *(array_local+i)=din[i]>>2; } *out_accum=0; LOOP_ACCUM:for (j=0;j<N-1; j++) { *out_accum += *(array_local+j); } return *out_accum; }
Because thecoding changes here impact the functionality of the design, Xilinx does notrecommend using the __SYNTHESIS__ macro. Xilinx recommends that you:
1. Add the user-defined macro NO_SYNTH to the code and modify thecode.
2. Enable macro NO_SYNTH, execute the C simulation and saves the results.
3. Disable the macro NO_SYNTH (for example comment out, as in Example 50),execute the C simulation to verify that the results are identical. 4. Perform synthesis with the user-defined macro disabled.
XILINX推荐使用条件编译来修改可综合与不可综合的代码,这样在程序更新的时候更加方便
As withrestrictions on dynamic memory usage in C, Vivado HLS does not support (forsynthesis) C++ objects that are dynamically created or destroyed. This includesdynamic polymorphism and dynamic virtual function calls.
不支持C++中类的动态创建与销毁,列入如下C++代码: Unsynthesizable Code Coding Example
PointerLimitations(指针限制)
General Pointer Casting
Vivado HLS does not support general pointer casting,but supports pointer casting between native C types. For more information onpointer casting, see Example 3-36.
Pointer Arrays(指针数组)
Vivado HLSsupports pointer arrays for synthesis, provided that each pointer points toa scalar or an array of scalars. Arrays of pointers cannot point toadditional pointers.
支持指针数组,但是指针数组必须是指向一个定长或者标量的数组,不能用于指向另外一个指针。
Recursive Functions(递归函数)
递归函数不支持
Standard TemplateLibraries(标准的模板类)
不支持(由于含有动态内存分配)
参考:
http://shakithweblog.blogspot.com/2012/12/getting-sobel-filter-application.html
http://www.zedboard.org/content/implementing-xapp1167-application-note-example-zedboard
http://www.zedboard.org/content/accelerating-opencv-zynq-zedboard-xilinx-appnote-1167
http://www.zedboard.org/node/830
https://www.google.com.hk/#newwindow=1&q=XAPP890&safe=strict
https://www.google.com.hk/#newwindow=1&q=xapp1167++zedboard&safe=strict
VDMA driver:https://ez.analog.com/message/70323#70323
ug871是xilinx公开提供的HLS教程,包括11个例子: C ValidationInterface SynthesisArbitrary Precision TypesDesignAnalysisDesign OptimizationRTL VerificationUsing HLS IP in IP IntegratorUsingHLS IP in a Zynq Processor DesignUsing HLS IP in System Generator forDSP ug871:http://www.xilinx.com/support/documentation/sw_manuals/xilinx2013_1/ug871-vivado-high-level-synthesi...
参考设计源代码:http://www.xilinx.com/cgi-bin/docs/rdoc?v=2013.2;t=vivado+tutorials 第三, 13个Xilinx专家讲解视频,包括讲座和演示 地址: www.xilinx.com/training/vivado 1.Getting Started withVivado High-Level Synthesis2.Verifying your VivadoHLS Design3.Packaging Vivado HLSIP for use from Vivado IP Catalog4.Generating Vivado HLSblock for use in System Generator for DSP5.Generating Vivado HLSpcore for use in Xilinx Platform Studio6.Analyzing your VivadoHLS design7.Specifying AXI4interfaces for your Vivado HLS design8.Using Vivado HLSC/C++/SystemC block in System Generator9.Using Vivado HLSC/C++/SystemC based pcores in XPS10.Floating-Point Designwith Vivado HLS11.Using Vivado HLS SWlibraries in your C, C++, SystemC code12.Using the Vivado HLSTcl interface13.Leveraging OpenCV and High LevelSynthesis with Vivado 第四,不停更新的武林秘籍 www.xilinx.com/hls XAPP745 ProcessorControl of Vivado HLS Designs XAPP793 ImplementingMemory Structures for Video Processing in the Vivado HLS Tool XAPP599 Floating Point Design with Vivado HLS XAPP890 Zynq AllProgrammable SoC Sobel Filter Implementation Using the Vivado HLS Tool XAPP1163 -Floating-Point PID Controller Design with Vivado HLS and System Generatorfor DSP XAPP1167 Accelerating OpenCVApplications with Zynq using Vivado HLS Video Libraries