2

fftw ライブラリ ( fftw3.afftw3.lib) を使用して Linux と Windows で 2 つの同一のプログラムを作成し、fftwf_execute(m_wfpFFTplan)ステートメントの継続時間を計算しました (16-fft)。

10000 回の実行の場合:

  • Linux の場合: 平均時間は 0.9 です
  • Windows: 平均時間は 0.12

Linux よりも Windows の方が 9 倍高速である理由について、私は混乱しています。

プロセッサー: Intel(R) Core(TM) i7 CPU 870 @ 2.93GHz

各 OS (Windows XP 32 ビットおよび Linux OpenSUSE 11.4 32 ビット) が同じマシンにインストールされています。

インターネットから fftw.lib (Windows 用) をダウンロードしましたが、その構成がわかりません。この構成でFFTWをビルドしたら:

/configure --enable-float  --enable-threads --with-combined-threads  --disable-fortran  --with-slow-timer  --enable-sse  --enable-sse2  --enable-avx   

Linux では、デフォルトの構成 (0.4 ミリ秒) よりも 4 倍高速なライブラリが得られます。

4

1 に答える 1

7

16 FFT は非常に小さいです。あなたが見つけるのは、64 よりも小さい FFT が、可能な限り最高のパフォーマンスを得るためにループのないハードコードされたアセンブラーになることです。これは、命令セット、コンパイラの最適化、さらには 64 または 32 ビット ワードの変動の影響を非常に受けやすいことを意味します。

2 の累乗で 16 -> 1048576 の FFT サイズのテストを実行するとどうなりますか? これは、Linux で特定のハードコードされた asm ルーチンがマシンに最適化されていない可能性があるためです。その特定のサイズの Windows 実装では幸運だったかもしれません。この範囲内のすべてのサイズを比較すると、Linux と Windows のパフォーマンスのより良い指標が得られます。

FFTWのキャリブレーションはお済みですか?最初に FFTW を実行すると、マシンごとの最速の実装が推測されますが、特別な命令セット、特定のサイズのキャッシュ、またはその他のプロセッサ機能がある場合、これらは実行速度に劇的な影響を与える可能性があります。その結果、キャリブレーションを実行すると、さまざまな FFT ルーチンの速度がテストされ、特定のハードウェアのサイズごとに最速のルーチンが選択されます。キャリブレーションでは、計画を繰り返し計算し、生成された FFTW "Wisdom" ファイルを保存します。保存されたキャリブレーション データ (これは時間のかかるプロセスです) を再利用できます。ソフトウェアの起動時に一度実行し、毎回ファイルを再利用することをお勧めします。キャリブレーション後、特定のサイズのパフォーマンスが 4 ~ 10 倍向上したことに気付きました。

以下は、FFTW を特定のサイズに調整するために使用したコードのスニペットです。このコードは、私が取り組んだ DSP ライブラリからそのまま貼り付けられているため、一部の関数呼び出しは私のライブラリに固有のものであることに注意してください。FFTW 固有の呼び出しが役立つことを願っています。

// Calibration FFTW
void DSP::forceCalibration(void)
{
// Try to import FFTw Wisdom for fast plan creation
FILE *fftw_wisdom = fopen("DSPDLL.ftw", "r");

// If wisdom does not exist, ask user to calibrate
if (fftw_wisdom == 0)
{
    int iStatus2 = AfxMessageBox("FFTw not calibrated on this machine."\
        "Would you like to perform a one-time calibration?\n\n"\
        "Note:\tMay take 40 minutes (on P4 3GHz), but speeds all subsequent FFT-based filtering & convolution by up to 100%.\n"\
        "\tResults are saved to disk (DSPDLL.ftw) and need only be performed once per machine.\n\n"\
        "\tMAKE SURE YOU REALLY WANT TO DO THIS, THERE IS NO WAY TO CANCEL CALIBRATION PART-WAY!", 
        MB_YESNO | MB_ICONSTOP, 0);

    if (iStatus2 == IDYES)
    {
        // Perform calibration for all powers of 2 from 8 to 4194304
        // (most heavily used FFTs - for signal processing)
        AfxMessageBox("About to perform calibration.\n"\
            "Close all programs, turn off your screensaver and do not move the mouse in this time!\n"\
            "Note:\tThis program will appear to be unresponsive until the calibration ends.\n\n"
            "\tA MESSAGEBOX WILL BE SHOWN ONCE THE CALIBRATION IS COMPLETE.\n");
        startTimer();

        // Create a whole load of FFTw Plans (wisdom accumulates automatically)
        for (int i = 8; i <= 4194304; i *= 2)
        {
            // Create new buffers and fill
            DSP::cFFTin = new fftw_complex[i];
            DSP::cFFTout = new fftw_complex[i];
            DSP::fconv_FULL_Real_FFT_rdat = new double[i];
            DSP::fconv_FULL_Real_FFT_cdat = new fftw_complex[(i/2)+1];
            for(int j = 0; j < i; j++)
            {
                DSP::fconv_FULL_Real_FFT_rdat[j] = j;
                DSP::cFFTin[j][0] = j;
                DSP::cFFTin[j][1] = j;
                DSP::cFFTout[j][0] = 0.0;
                DSP::cFFTout[j][1] = 0.0;
            }

            // Create a plan for complex FFT.
            // Use the measure flag to get the best possible FFT for this size
            // FFTw "remembers" which FFTs were the fastest during this test. 
            // at the end of the test, the results are saved to disk and re-used
            // upon every initialisation of the DSP Library
            DSP::pCF = fftw_plan_dft_1d
                (i, DSP::cFFTin, DSP::cFFTout, FFTW_FORWARD, FFTW_MEASURE);

            // Destroy the plan
            fftw_destroy_plan(DSP::pCF);

            // Create a plan for real forward FFT
            DSP::pCF = fftw_plan_dft_r2c_1d
                (i, fconv_FULL_Real_FFT_rdat, fconv_FULL_Real_FFT_cdat, FFTW_MEASURE);

            // Destroy the plan
            fftw_destroy_plan(DSP::pCF);

            // Create a plan for real inverse FFT
            DSP::pCF = fftw_plan_dft_c2r_1d
                (i, fconv_FULL_Real_FFT_cdat, fconv_FULL_Real_FFT_rdat, FFTW_MEASURE);

            // Destroy the plan
            fftw_destroy_plan(DSP::pCF);

            // Destroy the buffers. Repeat for each size
            delete [] DSP::cFFTin;
            delete [] DSP::cFFTout;
            delete [] DSP::fconv_FULL_Real_FFT_rdat;
            delete [] DSP::fconv_FULL_Real_FFT_cdat;
        }

        double time = stopTimer();

        char * strOutput;
        strOutput = (char*) malloc (100);
        sprintf(strOutput, "DSP.DLL Calibration complete in %d minutes, %d seconds\n"\
            "Please keep a copy of the DSPDLL.ftw file in the root directory of your application\n"\
            "to avoid re-calibration in the future\n", (int)time/(int)60, (int)time%(int)60);
        AfxMessageBox(strOutput);

        isCalibrated = 1;

        // Save accumulated wisdom
        char * strWisdom = fftw_export_wisdom_to_string();  
        FILE *fftw_wisdomsave = fopen("DSPDLL.ftw", "w");
        fprintf(fftw_wisdomsave, "%s", strWisdom);

        fclose(fftw_wisdomsave);
        DSP::pCF = NULL;
        DSP::cFFTin = NULL;
        DSP::cFFTout = NULL;
        fconv_FULL_Real_FFT_cdat = NULL;
        fconv_FULL_Real_FFT_rdat = NULL;
        free(strOutput);
    }
}
else 
{
    // obtain file size.
    fseek (fftw_wisdom , 0 , SEEK_END);
    long lSize = ftell (fftw_wisdom);
    rewind (fftw_wisdom);

    // allocate memory to contain the whole file.
    char * strWisdom = (char*) malloc (lSize);

    // copy the file into the buffer.
    fread (strWisdom,1,lSize,fftw_wisdom);

    // import the buffer to fftw wisdom
    fftw_import_wisdom_from_string(strWisdom);

    fclose(fftw_wisdom);
    free(strWisdom);

    isCalibrated = 1;

    return;
}
}

秘密のソースは、FFTW_MEASURE フラグを使用して計画を作成することです。これは、特定のタイプの FFT (実数、複素数、1D、2D) とサイズに対して最速のものを見つけるために、何百ものルーチンを具体的に測定します。

DSP::pCF = fftw_plan_dft_1d (i, DSP::cFFTin, DSP::cFFTout, 
   FFTW_FORWARD, FFTW_MEASURE);

最後に、すべてのベンチマーク テストは、最適化をオンにしてデバッガーから分離したリリース モードでコンパイルされたコードから呼び出される、execute の外部にある 1 つの FFT プラン ステージでも実行する必要があります。ベンチマークは、数千回 (または数百万回) の反復を行うループで実行し、平均実行時間をかけて結果を計算する必要があります。ご存じのとおり、計画段階にはかなりの時間がかかり、実行は 1 つの計画で複数回実行されるように設計されています。

于 2011-12-31T08:51:06.270 に答える