【发布时间】:2018-09-15 05:54:18
【问题描述】:
我正在使用 CUDA 测试 OpenCV GPU 加速,但 GPU 比 CPU 慢。它只是关于中值滤波器还是我在我的代码中做错了什么?为什么 GPU 上的纯处理时间高于 CPU?
输出:
Device 0: "GeForce GT 330M" 1023Mb, sm_12 (not Fermi),
48 cores, Driver/Runtime ver.6.50/6.50
Size of the Image: 512 x 512
GPU Time Includes up&download Times: 8531/100 = 85ms
GPU Time Includes only 'apply': 8307/100 = 83ms
CPU Time: 1855/100 = 18ms
代码:
void CPUvsGPU()
{
QElapsedTimer timer;
Mat cSrc;
Mat cGray;
cuda::GpuMat gGray;
cuda::printShortCudaDeviceInfo(cuda::getDevice());
cSrc = imread("baboon.jpg");
cout << "Size of the Image: " << cSrc.size << endl;
cvtColor(cSrc, cGray, COLOR_BGR2GRAY);
gGray.upload(cGray);
Mat cOut(cGray.size(), CV_8U);
cuda::GpuMat gOut(gGray.size(), CV_8U);
Ptr <cuda::Filter> mf;
mf = cuda::createMedianFilter(CV_8UC1,9);
mf->apply(gGray, gOut);//don't measure first operation's time on GPU
timer.start();
for (int i = 0; i<100 ; i++)
{
gGray.upload(cGray);
mf->apply(gGray, gOut);
gOut.download(cOut);
}
cout << "GPU Time Includes up&download Times: " << timer.elapsed() << "/100 = " << timer.elapsed()/100 <<"ms" << endl;
timer.start();
for (int i = 0; i<100 ; i++)
mf->apply(gGray, gOut);
cout << "GPU Time Includes only 'apply': " << timer.elapsed() << "/100 = " << timer.elapsed()/100 <<"ms" << endl;
timer.start();
for (int i = 0; i<100 ; i++)
medianBlur(cGray,cOut,9);
cout << "CPU Time: " << timer.elapsed() << "/100 = " << timer.elapsed()/100 <<"ms" << endl;
}
【问题讨论】:
-
您正在使用有史以来最小、最慢的 CUDA GPU 之一运行。也许更好的问题是为什么你会期望 GPU 更快?
-
@talonmies 现在一切都清楚了 :) 快速 CUDA GPU 的主要标准是什么? CUDA 内核数、帧缓冲区、时钟速度还是其他?
-
是的 cuda 核心是一个因素,但它与时钟速度和内存速度有关,所以是的,48 个 cuda 核心并没有那么多(我有 1050 ti 和 768 个 cuda 核心,它不是最好的市场)
-
中值过滤器在 gpu 上也不应该那么好。
标签: c++ opencv gpu hardware-acceleration