日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Xilinx HLS FFT IP核运行时动态配置FFT长度

發布時間:2024/3/12 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Xilinx HLS FFT IP核运行时动态配置FFT长度 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


如上圖所示,xilinx hls的fft ip核不僅可以計算固定長度的FFT變換,還可以在運行時動態配置fft變換長度,但其可配置的長度僅限于小于等于最大長度的所有可能的2的冪,即若該fft ip可支持的最大長度為32,那么配置選項為32,16,8…
運行時實時參數的配置可通過如下方式實現

config_t fft_config; fft_config.setDir(0); //用來配置FFT:0正向 1反向 fft_config.setSch(0x57B);//用來設置縮放因子[01 01 01 11 10 10] fft_config.setNfft(nfft); //用來設置FFT點數

以下是整個工程的代碼,分為fft_top.h,fft_top.cpp,fft_tb.cpp,前兩者為源文件(設計文件),最后者為測試平臺。在本工程示例中,fft ip可以支持的最大長度為32,我們通過運行時fft變換長度的動態配置,實現了16點fft的計算。
fft_top.h:

// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689 /******************************************************************************* Vendor: Xilinx Associated Filename: fft_top.h Purpose: Xilinx FFT IP-XACT IP in Vivado HLS Revision History: September 26, 2013 - initial release******************************************************************************* #- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved. #- #- This file contains confidential and proprietary information #- of Xilinx, Inc. and is protected under U.S. and #- international copyright and other intellectual property #- laws. #- #- DISCLAIMER #- This disclaimer is not a license and does not grant any #- rights to the materials distributed herewith. Except as #- otherwise provided in a valid license issued to you by #- Xilinx, and to the maximum extent permitted by applicable #- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND #- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES #- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING #- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- #- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and #- (2) Xilinx shall not be liable (whether in contract or tort, #- including negligence, or under any other theory of #- liability) for any loss or damage of any kind or nature #- related to, arising under or in connection with these #- materials, including for any direct, or any indirect, #- special, incidental, or consequential loss or damage #- (including loss of data, profits, goodwill, or any type of #- loss or damage suffered as a result of any action brought #- by a third party) even if such damage or loss was #- reasonably foreseeable or Xilinx had been advised of the #- possibility of the same. #- #- CRITICAL APPLICATIONS #- Xilinx products are not designed or intended to be fail- #- safe, or for use in any application requiring fail-safe #- performance, such as life-support or safety devices or #- systems, Class III medical devices, nuclear facilities, #- applications related to the deployment of airbags, or any #- other applications that could lead to death, personal #- injury, or severe property or environmental damage #- (individually and collectively, "Critical #- Applications"). Customer assumes the sole risk and #- liability of any use of Xilinx products in Critical #- Applications, subject only to applicable laws and #- regulations governing limitations on product liability. #- #- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS #- PART OF THIS FILE AT ALL TIMES. #- ************************************************************************This file contains confidential and proprietary information of Xilinx, Inc. and is protected under U.S. and international copyright and other intellectual property laws.DISCLAIMER This disclaimer is not a license and does not grant any rights to the materials distributed herewith. Except as otherwise provided in a valid license issued to you by Xilinx, and to the maximum extent permitted by applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and (2) Xilinx shall not be liable (whether in contract or tort, including negligence, or under any other theory of liability) for any loss or damage of any kind or nature related to, arising under or in connection with these materials, including for any direct, or any indirect, special, incidental, or consequential loss or damage (including loss of data, profits, goodwill, or any type of loss or damage suffered as a result of any action brought by a third party) even if such damage or loss was reasonably foreseeable or Xilinx had been advised of the possibility of the same.CRITICAL APPLICATIONS Xilinx products are not designed or intended to be fail-safe, or for use in any application requiring fail-safe performance, such as life-support or safety devices or systems, Class III medical devices, nuclear facilities, applications related to the deployment of airbags, or any other applications that could lead to death, personal injury, or severe property or environmental damage (individually and collectively, "Critical Applications"). Customer assumes the sole risk and liability of any use of Xilinx products in Critical Applications, subject only to applicable laws and regulations governing limitations on product liability. THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES.*******************************************************************************/#include "ap_fixed.h" #include "hls_fft.h"// configurable params const char FFT_INPUT_WIDTH = 16; const char FFT_OUTPUT_WIDTH = FFT_INPUT_WIDTH; const char FFT_CONFIG_WIDTH = 16; const char FFT_NFFT_MAX = 5; const int FFT_LENGTH = 1 << FFT_NFFT_MAX; #include <complex> using namespace std;struct config1 : hls::ip_fft::params_t {static const unsigned ordering_opt = hls::ip_fft::natural_order;static const unsigned config_width = FFT_CONFIG_WIDTH;//static const unsigned max_nfft=4;static const bool has_nfft = true;static const unsigned max_nfft = FFT_NFFT_MAX; };typedef hls::ip_fft::config_t<config1> config_t; typedef hls::ip_fft::status_t<config1> status_t;typedef ap_fixed<FFT_INPUT_WIDTH,1> data_in_t; typedef ap_fixed<FFT_OUTPUT_WIDTH,FFT_OUTPUT_WIDTH-FFT_INPUT_WIDTH+1> data_out_t; typedef std::complex<data_in_t> cmpxDataIn; typedef std::complex<data_out_t> cmpxDataOut;void dummy_proc_fe(bool direction,config_t* config, cmpxDataIn in[FFT_LENGTH], cmpxDataIn out[FFT_LENGTH]);void dummy_proc_be(status_t* status_in, bool* ovflo,cmpxDataOut in[FFT_LENGTH], cmpxDataOut out[FFT_LENGTH]);void fft_top(bool direction,cmpxDataIn in[FFT_LENGTH],cmpxDataOut out[FFT_LENGTH],bool* ovflo);

這里通過static const bool has_nfft = true語句激活了運行時fft變換長度動態可配置的功能。
fft_top.cpp:

// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689 /******************************************************************************* Vendor: Xilinx Associated Filename: fft_top.cpp Purpose: Xilinx FFT IP-XACT IP in Vivado HLS Revision History: September 26, 2013 - initial release******************************************************************************* #- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved. #- #- This file contains confidential and proprietary information #- of Xilinx, Inc. and is protected under U.S. and #- international copyright and other intellectual property #- laws. #- #- DISCLAIMER #- This disclaimer is not a license and does not grant any #- rights to the materials distributed herewith. Except as #- otherwise provided in a valid license issued to you by #- Xilinx, and to the maximum extent permitted by applicable #- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND #- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES #- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING #- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- #- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and #- (2) Xilinx shall not be liable (whether in contract or tort, #- including negligence, or under any other theory of #- liability) for any loss or damage of any kind or nature #- related to, arising under or in connection with these #- materials, including for any direct, or any indirect, #- special, incidental, or consequential loss or damage #- (including loss of data, profits, goodwill, or any type of #- loss or damage suffered as a result of any action brought #- by a third party) even if such damage or loss was #- reasonably foreseeable or Xilinx had been advised of the #- possibility of the same. #- #- CRITICAL APPLICATIONS #- Xilinx products are not designed or intended to be fail- #- safe, or for use in any application requiring fail-safe #- performance, such as life-support or safety devices or #- systems, Class III medical devices, nuclear facilities, #- applications related to the deployment of airbags, or any #- other applications that could lead to death, personal #- injury, or severe property or environmental damage #- (individually and collectively, "Critical #- Applications"). Customer assumes the sole risk and #- liability of any use of Xilinx products in Critical #- Applications, subject only to applicable laws and #- regulations governing limitations on product liability. #- #- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS #- PART OF THIS FILE AT ALL TIMES. #- ************************************************************************This file contains confidential and proprietary information of Xilinx, Inc. and is protected under U.S. and international copyright and other intellectual property laws.DISCLAIMER This disclaimer is not a license and does not grant any rights to the materials distributed herewith. Except as otherwise provided in a valid license issued to you by Xilinx, and to the maximum extent permitted by applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and (2) Xilinx shall not be liable (whether in contract or tort, including negligence, or under any other theory of liability) for any loss or damage of any kind or nature related to, arising under or in connection with these materials, including for any direct, or any indirect, special, incidental, or consequential loss or damage (including loss of data, profits, goodwill, or any type of loss or damage suffered as a result of any action brought by a third party) even if such damage or loss was reasonably foreseeable or Xilinx had been advised of the possibility of the same.CRITICAL APPLICATIONS Xilinx products are not designed or intended to be fail-safe, or for use in any application requiring fail-safe performance, such as life-support or safety devices or systems, Class III medical devices, nuclear facilities, applications related to the deployment of airbags, or any other applications that could lead to death, personal injury, or severe property or environmental damage (individually and collectively, "Critical Applications"). Customer assumes the sole risk and liability of any use of Xilinx products in Critical Applications, subject only to applicable laws and regulations governing limitations on product liability. THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES.*******************************************************************************/#include "fft_top.h"void dummy_proc_fe(bool direction,config_t* config, cmpxDataIn in[FFT_LENGTH], cmpxDataIn out[FFT_LENGTH]) {int i; config->setDir(direction);config->setSch(0xA);config->setNfft(4); //用來設置FFT點數for (i=0; i< FFT_LENGTH; i++)out[i] = in[i]; }void dummy_proc_be(status_t* status_in, bool* ovflo,cmpxDataOut in[FFT_LENGTH], cmpxDataOut out[FFT_LENGTH]) {int i; for (i=0; i< FFT_LENGTH; i++)out[i] = in[i];*ovflo = status_in->getOvflo() & 0x1; }void fft_top(bool direction,complex<data_in_t> in[FFT_LENGTH],complex<data_out_t> out[FFT_LENGTH],bool* ovflo) { #pragma HLS interface ap_hs port=direction #pragma HLS interface ap_fifo depth=1 port=ovflo #pragma HLS interface ap_fifo depth=FFT_LENGTH port=in,out #pragma HLS data_pack variable=in #pragma HLS data_pack variable=out #pragma HLS dataflowcomplex<data_in_t> xn[FFT_LENGTH];complex<data_out_t> xk[FFT_LENGTH];config_t fft_config;status_t fft_status;dummy_proc_fe(direction, &fft_config, in, xn);// FFT IPhls::fft<config1>(xn, xk, &fft_status, &fft_config);dummy_proc_be(&fft_status, ovflo, xk, out); }

在該代碼中,片段

config->setDir(direction);config->setSch(0xA);config->setNfft(4); //用來設置FFT點數

實現了運行時變換方向、縮放因子以及變換長度的配置,這里設置的變換長度為24=162^4=1624=16
fft_tb.cpp:

// 67d7842dbbe25473c3c32b93c0da8047785f30d78e8a024de1b57352245f9689 /******************************************************************************* Vendor: Xilinx Associated Filename: fft_tb.cpp Purpose: Xilinx FFT IP-XACT IP in Vivado HLS Revision History: September 26, 2013 - initial release******************************************************************************* #- (c) Copyright 2011-2019 Xilinx, Inc. All rights reserved. #- #- This file contains confidential and proprietary information #- of Xilinx, Inc. and is protected under U.S. and #- international copyright and other intellectual property #- laws. #- #- DISCLAIMER #- This disclaimer is not a license and does not grant any #- rights to the materials distributed herewith. Except as #- otherwise provided in a valid license issued to you by #- Xilinx, and to the maximum extent permitted by applicable #- law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND #- WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES #- AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING #- BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON- #- INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and #- (2) Xilinx shall not be liable (whether in contract or tort, #- including negligence, or under any other theory of #- liability) for any loss or damage of any kind or nature #- related to, arising under or in connection with these #- materials, including for any direct, or any indirect, #- special, incidental, or consequential loss or damage #- (including loss of data, profits, goodwill, or any type of #- loss or damage suffered as a result of any action brought #- by a third party) even if such damage or loss was #- reasonably foreseeable or Xilinx had been advised of the #- possibility of the same. #- #- CRITICAL APPLICATIONS #- Xilinx products are not designed or intended to be fail- #- safe, or for use in any application requiring fail-safe #- performance, such as life-support or safety devices or #- systems, Class III medical devices, nuclear facilities, #- applications related to the deployment of airbags, or any #- other applications that could lead to death, personal #- injury, or severe property or environmental damage #- (individually and collectively, "Critical #- Applications"). Customer assumes the sole risk and #- liability of any use of Xilinx products in Critical #- Applications, subject only to applicable laws and #- regulations governing limitations on product liability. #- #- THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS #- PART OF THIS FILE AT ALL TIMES. #- ************************************************************************This file contains confidential and proprietary information of Xilinx, Inc. and is protected under U.S. and international copyright and other intellectual property laws.DISCLAIMER This disclaimer is not a license and does not grant any rights to the materials distributed herewith. Except as otherwise provided in a valid license issued to you by Xilinx, and to the maximum extent permitted by applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE; and (2) Xilinx shall not be liable (whether in contract or tort, including negligence, or under any other theory of liability) for any loss or damage of any kind or nature related to, arising under or in connection with these materials, including for any direct, or any indirect, special, incidental, or consequential loss or damage (including loss of data, profits, goodwill, or any type of loss or damage suffered as a result of any action brought by a third party) even if such damage or loss was reasonably foreseeable or Xilinx had been advised of the possibility of the same.CRITICAL APPLICATIONS Xilinx products are not designed or intended to be fail-safe, or for use in any application requiring fail-safe performance, such as life-support or safety devices or systems, Class III medical devices, nuclear facilities, applications related to the deployment of airbags, or any other applications that could lead to death, personal injury, or severe property or environmental damage (individually and collectively, "Critical Applications"). Customer assumes the sole risk and liability of any use of Xilinx products in Critical Applications, subject only to applicable laws and regulations governing limitations on product liability. THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE AT ALL TIMES.*******************************************************************************/#include <iostream> #include <cstdlib> #include <cstring> #include <sstream> #include "fft_top.h" #include <stdio.h>#include <fstream> #include <string> #include <sstream>using namespace std;int main() {cmpxDataIn xn_input[FFT_LENGTH];cmpxDataOut xk_output[FFT_LENGTH];for(int i=0;i<FFT_LENGTH;i++){//cout<<i/FFT_LENGTH<<endl;xn_input[i].real((data_in_t)((float)i/(float)FFT_LENGTH));xn_input[i].imag((data_in_t)((float)(-i)/(float)FFT_LENGTH));}bool ovflo;int FWD_INV=1;fft_top(FWD_INV, xn_input, xk_output, &ovflo);for(int i=0;i<FFT_LENGTH;i++)cout<<"i="<<i<<": "<<xk_output[i].real()<<"+"<<xk_output[i].imag()<<"j"<<endl;cout<<ovflo<<endl;return 0;}

這里雖然數組長度為32,但是其實只有前16個數參與了16點FFT變換。可通過實驗驗證:
HLS仿真結果:

i=0: 0.234375+-0.234375j i=1: 0.0628967+0.0941467j i=2: 0.0220947+0.0533447j i=3: 0.00775146+0.0390015j i=4: 0+0.03125j i=5: -0.00518799+0.026062j i=6: -0.00915527+0.0220947j i=7: -0.0125122+0.0187378j i=8: -0.015625+0.015625j i=9: -0.0187378+0.0125122j i=10: -0.0220947+0.00915527j i=11: -0.026062+0.00518799j i=12: -0.03125+0j i=13: -0.039032+-0.00778198j i=14: -0.0533447+-0.0220947j i=15: -0.0941772+-0.0629272j i=16: -0.0454102+0.00408936j i=17: 0+0j i=18: -0.262939+0.00195313j i=19: 0+0j i=20: -0.0424805+0.00408936j i=21: 0+0j i=22: -0.0351563+0.00408936j i=23: 0+0j i=24: -0.0439453+0.00408936j i=25: 0+0j i=26: -0.787781+0.00195313j i=27: 0+0j i=28: -0.0439453+0.00408936j i=29: 0+0j i=30: -0.348389+0.00195313j i=31: 0+0j

而作為baseline的python代碼如下:

if __name__=='__main__':x=torch.from_numpy(np.array(x))y=torch.from_numpy(np.array(y))print(x)print(y)z=torch.complex(x,y)print(torch.fft.fft(z)/16)

運行結果為:

tensor([ 0.2344-0.2344j, 0.0629+0.0942j, 0.0221+0.0533j, 0.0078+0.0390j,0.0000+0.0312j, -0.0052+0.0261j, -0.0092+0.0221j, -0.0125+0.0187j,-0.0156+0.0156j, -0.0187+0.0125j, -0.0221+0.0092j, -0.0261+0.0052j,-0.0312+0.0000j, -0.0390-0.0078j, -0.0533-0.0221j, -0.0942-0.0629j],dtype=torch.complex128)

可以看到,baseline的輸出和HLS輸出的前16個數在誤差允許范圍內可以認為是相同的

總結

以上是生活随笔為你收集整理的Xilinx HLS FFT IP核运行时动态配置FFT长度的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。