【问题标题】:How to measure fft and ifft time from the cuda::convolution function?如何从 cuda::convolution 函数测量 fft 和 ifft 时间?
【发布时间】:2019-12-24 09:34:37
【问题描述】:

我正在使用 cuda::convolution::convolve 来计算高斯卷积,我想测量 fft 和 ifft 的时间。但我不知道如何衡量。

我在GitHub 上找到了源代码。我不知道如何从中测量时间。

 cufftSafeCall( cufftExecR2C(planR2C, templ_block.ptr<cufftReal>(), templ_spect.ptr<cufftComplex>()) );

        // Process all blocks of the result matrix
        for (int y = 0; y < result.rows; y += block_size.height)
        {
            for (int x = 0; x < result.cols; x += block_size.width)
            {
                Size image_roi_size(std::min(x + dft_size.width, image.cols) - x,
                                    std::min(y + dft_size.height, image.rows) - y);
                GpuMat image_roi(image_roi_size, CV_32F, (void*)(image.ptr<float>(y) + x),
                                 image.step);
                cuda::copyMakeBorder(image_roi, image_block, 0, image_block.rows - image_roi.rows,
                                    0, image_block.cols - image_roi.cols, 0, Scalar(), _stream);

                cufftSafeCall(cufftExecR2C(planR2C, image_block.ptr<cufftReal>(),
                                           image_spect.ptr<cufftComplex>()));
                cuda::mulAndScaleSpectrums(image_spect, templ_spect, result_spect, 0,
                                          1.f / dft_size.area(), ccorr, _stream);
                cufftSafeCall(cufftExecC2R(planC2R, result_spect.ptr<cufftComplex>(),
                                           result_data.ptr<cufftReal>()));

                Size result_roi_size(std::min(x + block_size.width, result.cols) - x,
                                     std::min(y + block_size.height, result.rows) - y);
                GpuMat result_roi(result_roi_size, result.type(),
                                  (void*)(result.ptr<float>(y) + x), result.step);
                GpuMat result_block(result_roi_size, result_data.type(),
                                    result_data.ptr(), result_data.step);

                result_block.copyTo(result_roi, _stream);
            }
        }

        cufftSafeCall( cufftDestroy(planR2C) );
        cufftSafeCall( cufftDestroy(planC2R) );

        syncOutput(result, _result, _stream);
    }
}

【问题讨论】:

  • 我假设与您对其他 CUDA 应用程序计时的方式相同。

标签: opencv cuda cufft


【解决方案1】:

我曾经不得不像这样测量并这样做:

#include <chrono>

auto begin = std::chrono::high_resolution_clock::now();

cufftSafeCall(cufftExecR2C(planR2C, image_block.ptr<cufftReal>(),
                                           image_spect.ptr<cufftComplex>()));
//or the call you want to measure

auto elapsed = chrono::high_resolution_clock::now() - begin;

然后您可以使用以下方法将其转换为微秒: time = chrono::duration_cast&lt;chrono::microseconds&gt;(elapsed).count();

如果调用在 for 循环中并且您想要所有调用的时间,您可以声明一个数组来保存每轮的 time

【讨论】:

    猜你喜欢
    • 2014-09-21
    • 1970-01-01
    • 2018-03-15
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    相关资源
    最近更新 更多