英特尔 oneAPI 黑客松使用oneMKL对FFT的优化情况

代码实现

主函数:

int N=2048;
        float *in=(float *)malloc(sizeof(float)*N*N);
        fftwf_complex *outfftw3=(fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex)*N*(N/2+1));
        MKL_Complex8 *outmkl=(MKL_Complex8 *)malloc(sizeof(MKL_Complex8)*N*(N/2+1));
        Rand(in,N);
    onemkl(in,outmkl,N);
    fftw3(in,outfftw3,N);
    match(outfftw3,outmkl,N);

各个定义的函数:

void Rand(float *in,int N)
{
    VSLStreamStatePtr stream;
       vslNewStream(&stream,VSL_BRNG_MT19937,1);
        vsRngUniform(VSL_RNG_METHOD_UNIFORM_STD,stream,N*N,in,0.0f,1.0f);
}

void onemkl(float *in,MKL_Complex8 *out,int N)
{
    int time;
    MKL_LONG sizeN[2]={N,N};
    MKL_LONG rs[3]={0,N,1};
        MKL_LONG cs[3]={0,N/2+1,1};
    DFTI_DESCRIPTOR_HANDLE handle=NULL;
    DftiCreateDescriptor(&handle,DFTI_SINGLE,DFTI_REAL,2,sizeN);
    DftiSetValue(handle,DFTI_PLACEMENT,DFTI_NOT_INPLACE);
        DftiSetValue(handle,DFTI_CONJUGATE_EVEN_STORAGE,DFTI_COMPLEX_COMPLEX);
        DftiSetValue(handle,DFTI_INPUT_STRIDES,rs);
        DftiSetValue(handle,DFTI_OUTPUT_STRIDES,cs);
    DftiCommitDescriptor(handle);
    clock_t start,end;
    start=clock();
    DftiComputeForward(handle,in,out);
    end=clock();
    printf("1    oneMKL use %f\n",(double)(end-start)/CLOCKS_PER_SEC);
    start=clock();
    for(time=0;time<1000;time++) DftiComputeForward(handle,in,out);
    end=clock();
    printf("1000 oneMKL Average use %f\n",(double)(end-start)/CLOCKS_PER_SEC/1000);
}

void fftw3(float *in,fftwf_complex *out,int N)
{
    int time;
    fftw_plan flag;
    clock_t start,end;
    flag=fftwf_plan_dft_r2c_2d(N,N,in,out,FFTW_MEASURE);
    start=clock();
    fftwf_execute(flag);
    end=clock();
    printf("1    FFTW3  use %f\n",(double)(end-start)/CLOCKS_PER_SEC);
    start=clock();
    for(time=0;time<1000;time++) fftwf_execute(flag);
    end=clock();
    printf("1000 FFTW3  Average use %f\n",(double)(end-start)/CLOCKS_PER_SEC/1000);
}

void match(fftwf_complex *array_f,MKL_Complex8 *array_m,int N)
{
    float diff=0.000001;
    float R=0;
    float I=0;
    int a=0;
    
    for(int i=0;i<(N/2+1)*N;i++)
        {
            R=fabs(array_m[i].real-array_f[i][0]);
            I=fabs(array_m[i].imag-array_f[i][1]);
            if(R>diff || I>diff) a=1;
       }
    if(a==0) printf("oneMKL with FFTW3 is Match\n");
    else printf("oneMKL with FFTW3 is not Match\n");
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值