OpenCV 3.4 C++ Cuda 加速比 CPU 花费更多时间
OpenCV 3.4 C++ Cuda acceleration takes more time than CPU
我正在使用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;
}
尝试查看此链接,您的 GPU 列在旧版 GPU 中。
还要尝试查看比我机器上的CPU版本慢的OpenCV算法的GPU版本?以及为什么Opencv GPU代码比CPU慢?,以便在进行比较时要考虑的其他问题。对于所有功能,您获得的加速并不相同。有些得到了小的增强,有些则速度非常惊人。
相关文章:
- 分别测量每个线程上花费的 CPU 时间(C++)
- 对于等待以 std::future wait() 返回的函数的 CPU 使用率或检查标志在循环中休眠一段时间哪个更好?
- 一段时间后 CPU 使用率高
- C/C++memcpu基准测试:测量CPU和墙时间
- 超过CPU时间限制:当MPI_Sent一个非常大的int*时
- 如何测量一组特定线程的 CPU 时间?
- OpenCV 3.4 C++ Cuda 加速比 CPU 花费更多时间
- 如何以C++而不是 CPU 时间测量挂钟时间
- 将返回 CPU 时间提升为 0
- C++中的双感叹号(!!)会花费更多的CPU时间吗
- 为什么内存访问时间远远超过CPU缓存大小时会增加
- 在我的CUDA运行时间计划中,CPU和GPU可以异步计算,但不能合作地计算
- 即使使用睡眠,线程也不会放弃CPU时间
- 以C++为单位测量程序的 CPU 时间和挂钟时间
- 在 Windows 上以C++计算 CPU 时间
- 一段时间后,C++应用程序占用100%的cpu周期
- 时间短函数与 CPU 时间使用 RTEMS 操作系统
- PDH 无法通过 PdhAddCounter() 访问总 CPU 时间
- 二叉搜索真的是在 0 时钟 CPU 时间内执行的吗?
- 我应该检查什么:cpu时间还是墙时间