英特尔oneAPI黑客松比赛心得交流

本文记录笔者参加英特尔oneAPI黑客松比赛的环境调试、代码编写、结果分析及参赛心得。

环境配置:使用Visual Studio2022 + oneMKL

在oneMKL安装过程中,选择VS2022作为IDE;

安装完毕后,在VS2022中,在属性管理器中Debug|x64中添加MKL项,Use oneMKL改为Parallel,VC++目录项中,设置

可执行文件目录:

C:\Program Files (x86)\Intel\oneAPI\mkl\2023.2.0\bin\intel64;$(ExecutablePath)

包含目录:

C:\Program Files (x86)\Intel\oneAPI\mkl\2023.2.0\include;$(IncludePath)

库目录:

C:\ProgramFiles(x86)\Intel\oneAPI\mkl\2023.2.0\lib\intel64;C:\Program Files (x86)\Intel\oneAPI\compiler\2023.2.0\windows\compiler\lib\intel64_win;$(LibraryPath)

链接器输入的附加依赖项:

mkl_intel_ilp64.lib;mkl_intel_thread.lib;mkl_core.lib;libiomp5md.lib;%(AdditionalDependencies)

至此,环境配置完成

代码逻辑:

在main函数中先生成2048*2048大小的随机数,分别调用fftw3以及oneMKL实现单精度浮点数的FFT,通过比较虚实部的方式对比结果,以上过程重复实现1000次,从而计算所用的平均时间。

int main()
{
    auto start = chrono::high_resolution_clock::now();
    auto end = chrono::high_resolution_clock::now();
    chrono::duration<double> duration = end - start;
    double time1 = 0, time2 = 0;
    int right = 0;
    for (int TIME = 0; TIME < tot_times; ++TIME) {
        generate();
        start = chrono::high_resolution_clock::now();
        fft_by_fftw3();
        end = chrono::high_resolution_clock::now();
        duration = end - start;
        time1 += duration.count();

        start = chrono::high_resolution_clock::now();
        fft_by_mkl();
        end = chrono::high_resolution_clock::now();
        duration = end - start;
        time2 += duration.count();

        bool equal = true;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N / 2 + 1; ++j) {
                if (abs(fftwOutput[i * (N / 2 + 1)][j * 2] - mklOutput[i * N + j].real()) > 0.001)
                    equal = false;
                if (abs(fftwOutput[i * (N / 2 + 1)][j * 2 + 1] - mklOutput[i * N + j].imag()) > 0.001)
                    equal = false;
            }
        }
        if (equal)
            right++;
    }
    fftw_free(fftwOutput);
    cout << "Accuracy:" << right << " / 1000" << endl;
    cout << "FFTW3_avg_time: " << time1 / tot_times << endl;
    cout << "MKL_avg_time: " << time2 / tot_times << endl;
    return 0;
}

运行方法及结果对比:

       代码中分别使用fftw3和oneMKL实现2048*2048单精度FFT,并反复运行一千次,计算平均时长;在正确性方面,分别比较二者结果数组的实部和虚部,相差小于0.001视为相等,经过测试后正确率为1000/1000,平均每次FFT运行时长:FFTW3:0.0159s,oneMKL:0.0073s,可以发现,oneMKL在FFT运算上的平均时长明显小于FFTW3,性能上有将近一倍的提升。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值