整合FFTW C函数调用内部系统的Verilog code [英] Integrating fftw C function calls inside system verilog code
问题描述
我已经安装了FFTW C库succefully我的Linux系统上。下面是一些关于FFTW更多信息C => http://www.fftw.org/ 我有一个示例C code能成功FFTW调用C函数。下面是一个C C code和命令来运行C code:
code:
I have installed fftw C library succefully on my linux system. Here is more info about fftw c => http://www.fftw.org/ I have a sample C code which can call fftw C functions successfully. Below is a C ccode and command to run the C code: Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <fftw3.h>
int main(void)
{
double FFT_in[] = {0.1, 0.6, 0.1, 0.4, 0.5, 0, 0.8, 0.7, 0.8, 0.6, 0.1,0};
double *IFFT_out;
int i,size = 12;
fftw_complex *middle;
fftw_plan fft;
fftw_plan ifft;
middle = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*size);
IFFT_out = (double *) malloc(size*sizeof(double));
fft = fftw_plan_dft_r2c_1d(size, FFT_in, middle, FFTW_ESTIMATE); //Setup fftw plan for fft (real 1D data)
ifft = fftw_plan_dft_c2r_1d(size, middle, IFFT_out, FFTW_ESTIMATE); //Setup fftw plan for ifft
fftw_execute(fft);
fftw_execute(ifft);
printf("Input: \tFFT_coefficient[i][0] \tFFT_coefficient[i][1] \tRecovered Output:\n");
for(i=0;i<size;i++)
printf("%f\t%f\t\t\t%f\t\t\t%f\n",(FFT_in[i]),middle[i][0],middle[i][1],IFFT_out[i]/size);
fftw_destroy_plan(fft);
fftw_destroy_plan(ifft);
fftw_free(middle);
free(IFFT_out);
return 0;
}
我可以通过下面的gcc命令成功地运行该code:
GCC -g -Wall -I /家庭的/ usr / FFTW /本地/包括-L /家庭的/ usr / FFTW / local / lib目录fftw_test.c -lfftw3 -lm -o fftw_test
I can run this code succesfully with below gcc command: gcc -g -Wall -I/home/usr/fftw/local/include -L/home/usr/fftw/local/lib fftw_test.c -lfftw3 -lm -o fftw_test
现在我想打电话给使用DPI方法体系的Verilog这里面的功能。在我告诉我的问题,下面是一个示例DPI-C / SystemVerilog的测试用例,我可以成功运行:
C:code
Now I want to call this function inside system verilog using DPI method. Before I show my issue, below is a sample DPI-C/systemverilog testcase which I could run successfully: C:code
#include <stdio.h>
#include <stdlib.h>
#include "svdpi.h"
int add(x,y)
{
int z;
z=x+y;
printf("This is from C:%d+%d=%d\n",x,y,z);
return z;
}
使用DPI以上调用C函数从系统的Verilog:
Calling above C function from system verilog using DPI:
module top;
import "DPI-C" function int add(int a, int b);
int a,b,j;
initial begin
$display("Entering in SystemVerilog Initial Block\n");
#20
a=20;b=10;
j = add(a,b);
$display("This is from System Verilog:Value of J=%d",j);
$display("Exiting from SystemVerilog Initial Block");
#5 $finish;
end
endmodule
终于我可以伊伦命令成功运行此
伊伦-f run.f哪里run.f包含以下命令:
and finally I could run this successfully with irun command irun -f run.f where run.f contains following commands:
# Compile the SystemVerilog files
basicadd.sv
-access +rwc
# Generate a header file called _sv_export.h
-dpiheader _sv_export.h
# Delay compilation of testexport.c until after elaboration
-cpost add.c -end
# Redirect output of ncsc_run to a log file called ncsc_run.log
-log_ncsc_run ncsc_run.log
现在我真正的问题是
当我尝试FFTW下与系统的Verilog链接,我不能够运行它。下面是我的C code,这类似于第一个C code口贴pretty:
C code:
Now my real issue is When I try to link fftw C with system verilog, I am not able to run it. Below is my C code, which is pretty similar to very first C code I posted: C code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <fftw3.h>
#include "svdpi.h"
void fftw_test_DPI(double FFT_in[],int size)
{
double *IFFT_out;
int i;
fftw_complex *middle;
fftw_plan fft;
fftw_plan ifft;
middle = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*size);
IFFT_out = (double *) malloc(size*sizeof(double));
fft = fftw_plan_dft_r2c_1d(size, FFT_in, middle, FFTW_ESTIMATE); //Setup fftw plan for fft (real 1D data)
ifft = fftw_plan_dft_c2r_1d(size, middle, IFFT_out, FFTW_ESTIMATE); //Setup fftw plan for ifft
fftw_execute(fft);
fftw_execute(ifft);
printf("Input: \tFFT_coefficient[i][0] \tFFT_coefficient[i][1] \tRecovered Output:\n");
for(i=0;i<size;i++)
printf("%f\t%f\t\t\t%f\t\t\t%f\n",FFT_in[i],middle[i][0],middle[i][1],IFFT_out[i]/size);
fftw_destroy_plan(fft);
fftw_destroy_plan(ifft);
fftw_free(middle);
free(IFFT_out);
//return IFFT_out;
}
下面是我的系统的Verilog,在那里我致电上述C函数:
Here is my system verilog, where I call above C function:
module top;
import "DPI-C" function void fftw_test_DPI(real FFT_in[0:11], int size);
real j [0:11];
integer i,size;
real FFT_in [0:11];
initial begin
size = 12;
FFT_in[0] = 0.1;
FFT_in[1] = 0.6;
FFT_in[2] = 0.1;
FFT_in[3] = 0.4;
FFT_in[4] = 0.5;
FFT_in[5] = 0.0;
FFT_in[6] = 0.8;
FFT_in[7] = 0.7;
FFT_in[8] = 0.8;
FFT_in[9] = 0.6;
FFT_in[10] = 0.1;
FFT_in[11] = 0.0;
$display("Entering in SystemVerilog Initial Block\n");
#20
fftw_test_DPI(FFT_in,size);
$display("Printing recovered output from system verilog\n");
//for(i=0;i<size;i++)
//$display("%f\t\n",(j[i])/size);
$display("Exiting from SystemVerilog Initial Block");
#5 $finish;
end
endmodule
最后我尝试了运行多种方式,我会提到的几种方法我试过:
第一个方法:
And finally I tried it running several ways, I will mentioned couple of ways I tried: 1st method:
irun -f run_fftw.f where run_fftw.f contains:
# Compile the SystemVerilog files
fftw_test.sv
-access +rwc
# Generate a header file called _sv_export.h
-dpiheader _sv_export.h
# Delay compilation of fftw_test.c until after elaboration
-cpost fftw_test_DPI.c -end
-I/home/usr/fftw/local/include -L/home/usr/fftw/local/lib fftw_test_DPI.c -lfftw3 -lm
# Redirect output of ncsc_run to a log file called ncsc_run.log
-log_ncsc_run ncsc_run.log
但这会导致下面的错误:
建设图书馆run.so
LD:/home/usr/fftw/local/lib/libfftw3.a(mapflags.o):创建共享目标时,对`.RODATA搬迁R_X86_64_32不能使用;与-fPIC编译
/home/usr/fftw/local/lib/libfftw3.a:看不懂的符号:坏值
collect2:劳工处返回1退出状态
令: * 的[/home/usr/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so]错误1
ncsc_run:* E,TBBLDF:未能建立试题库
/回家的/ usr / DPI /./ INCA_libs / irun.lnx8664.12.20.nc / librun.so
but this results in below error: building library run.so ld: /home/usr/fftw/local/lib/libfftw3.a(mapflags.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC /home/usr/fftw/local/lib/libfftw3.a: could not read symbols: Bad value collect2: ld returned 1 exit status make: * [/home/usr/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so] Error 1 ncsc_run: *E,TBBLDF: Failed to build test library /home/usr/DPI/./INCA_libs/irun.lnx8664.12.20.nc/librun.so
第二个方法:
1.gcc -fPIC -O2 -c -g -I /家庭/ ss69 / FFTW /本地/包括-I。 -L /家庭的/ usr / FFTW / local / lib目录-L。 -o fftw_test_DPI.o fftw_test_DPI.c -lfftw3 -lm
2nd method: 1.gcc -fPIC -O2 -c -g -I/home/ss69/fftw/local/include -I. -L/home/usr/fftw/local/lib -L. -o fftw_test_DPI.o fftw_test_DPI.c -lfftw3 -lm
2.gcc -shared -o libdpi.so fftw_test_DPI.o
2.gcc -shared -o libdpi.so fftw_test_DPI.o
3.irun -64bit -sv_lib libdpi.so fftw_test.sv
3.irun -64bit -sv_lib libdpi.so fftw_test.sv
这将导致以下错误:
装载快照worklib.top:sv ....................完成
ncsim>运行
进入SystemVerilog的初始块
This results in below error: Loading snapshot worklib.top:sv .................... Done ncsim> run Entering in SystemVerilog Initial Block
ncsim:符号查找错误:./libdpi.so:未定义的符号:fftw_malloc
ncsim: symbol lookup error: ./libdpi.so: undefined symbol: fftw_malloc
我知道我的职位是一种难以效仿的,但我会极力AP preciate任何帮助。
I know my post is kind of difficult to follow, but I would highly appreciate any help.
推荐答案
您可能需要导出
或 SETENV LD_LIBRARY_PATH $ {LD_LIBRARY_PATH}:/家在/ usr / FFTW / local / lib目录:
。除非你的 libdpi.so
与静态FFTW库链接,否则,你的code将需要加载FFTW库的动态版本(libfftw.so?),因为您正在使用 FFTW _ *
的API。
You might need to export
or setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:/home/usr/fftw/local/lib:.
. Unless your libdpi.so
is linked with static FFTW library, otherwise, your code will need to load the dynamic version of the FFTW library (libfftw.so?) because you are using fftw_*
APIs.
这篇关于整合FFTW C函数调用内部系统的Verilog code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!