程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> HLS入門,葫蘆絲入門學習

HLS入門,葫蘆絲入門學習

編輯:關於C語言

HLS入門,葫蘆絲入門學習


使用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中通過查表法去訪問我需要的指數函數計算結果,這種方法是你需要提前能預測你需要的區間。這種方法從計算的角度是可以簡化時間的。

wxFillExpLut(float *lut, int size) {                
       for (int i=0; i< size; i++)  
            {
                      lut[i]=   expf( - (float) i / LUTPRECISION);
                      //debug_lut[i] = lut[i];
             }
}

其中size就是我們需要計算的區間,LUT就是一張表 

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

Class A {
public:
virtual void bar() {…};
};
void fun(A* a) {
       a->bar();
}
A* a = 0;
if (base)
       a = new A();
else
       a = new B();
foo(a);

 

 

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

         http://www.logicbricks.com/logicBRICKS/Reference-logicBRICKS-Design/Xylon-Reference-Designs-Navigation-Page.aspx

        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 


初學者,怎來學葫蘆絲

一、自學。
1、購買一本葫蘆絲練習教材。有了教材,你就可以了解葫蘆絲,了解音階指法,了解練習的辦法,教材裡也會有針對性的練習曲與數量可觀的葫蘆絲曲。教材版本很多,推薦選購李春華的綠面教材《葫蘆絲 巴烏實用教材》,這是目前最常用的一本,我帶學生練習時,也用這個版本。
2、掌握音階指法。即知道吹各個音時,手指要怎麼按,多吹幾天,就會記住。
3、從一開始就養成正確的吹奏習慣:身體姿勢、手型、吹嘴在嘴裡的位置等。
4、馬上著手基本的氣息訓練:一是低音要重吹,高音要輕吹。二是開始長音練習。即按好某個音,深呼吸,把這個音吹響,過程中要盡量保持此音的穩定,一直吹到氣用完,然後換別的音再吹長音,這樣既可提高發音的穩定性,又可幫你快速提高肺活量。
5、開始吹簡單的練習曲。不建議在剛開始學時就上葫蘆絲曲。
6、進行顫音及手活指練習。讓手指變得靈活,幫助你在以後可以從容應對快板部分。
7、走到這兒,你就可以進入中高級的訓練了,到此時,再訓練各種指法技巧:打音、滑音、疊音、波音等;學習吐苦技法,訓練更高標准的氣息要求:強弱音、尾音弱收、余氣釋放、氣震音、循環換氣等。
二、如果你的目標不只是學學會,而是想吹好,建議你找個葫蘆絲老師。
三、建議:
1、不管你是自學還是拜師,你的首只葫蘆絲一定要選專業的,不要買景點裡幾十元錢的,也不要買塑料的。建議買一支價格在200至300元之間用葫蘆與竹子制成的葫蘆絲,否則會影響你形成正確的氣息力度。
2、盡量多用時間,葫蘆絲的學習過程,既講究應知,更講究應會。練習的時間與你的技術成正比。
以上建議,供你參考。希望對你有所幫助。
 

【葫蘆絲初學者】迷茫啦,對於指法

葫蘆絲之所以能夠普及、能夠被人們喜愛,有兩個原因:

1、真的很好聽、不吵不鬧的。
2、太簡單,上手太快了

葫蘆絲之所以好學,其實呢就是音域窄,技巧簡單,有點吹奏類樂器基礎的人可以說是幾天就可以學會。

音域窄同時又是葫蘆絲的缺點,演奏上就有局限性了,通常只能演奏一些葫蘆絲自身的音樂,那葫蘆絲自身的音樂還是比較多的。
例如我比較喜歡的:《月光下的鳳尾竹》《多情的巴烏》《竹林情歌》《竹林深處》《侗鄉之夜》《婚誓》《牧歌》等等

你學學這幾個曲子吧,吹出韻味得幾年了。

先買本葫蘆絲教程,要買李春華版本的,綠色封面,定價22元的。

先買把差不多的練著,通常一年的時間就會有很大的變化,還想玩下去,就買把名人制作的好一些的,大概在500 - 800 之間,純手工制作的,很考究,味道很正的。

大半夜,我回答的多認真啊,而且我可是個葫蘆絲高手,不明白的還可以問我,分拿來吧~~~
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved