猿代码 — 科研/AI模型/高性能计算
0

GPU cv::cuda::threshold性能好像不大行啊

摘要: #include iostream#include "opencv2/opencv.hpp"int main (int argc, char* argv){cv::Mat h_img1 = cv::imread("images/cameraman.tif", 0);cv::cuda::GpuMat d_result1,d_result2,d_result3,d_result4,d_result5, ...
#include <iostream>
#include "opencv2/opencv.hpp"

int main (int argc, char* argv[])
{
 cv::Mat h_img1 = cv::imread("images/cameraman.tif", 0);
cv::cuda::GpuMat d_result1,d_result2,d_result3,d_result4,d_result5, d_img1;
//Measure initial time ticks
int64 work_begin = cv::getTickCount();
d_img1.upload(h_img1);
cv::cuda::threshold(d_img1, d_result1, 128.0, 255.0, cv::THRESH_BINARY);
cv::cuda::threshold(d_img1, d_result2, 128.0, 255.0, cv::THRESH_BINARY_INV);
cv::cuda::threshold(d_img1, d_result3, 128.0, 255.0, cv::THRESH_TRUNC);
cv::cuda::threshold(d_img1, d_result4, 128.0, 255.0, cv::THRESH_TOZERO);
cv::cuda::threshold(d_img1, d_result5, 128.0, 255.0, cv::THRESH_TOZERO_INV);

cv::Mat h_result1,h_result2,h_result3,h_result4,h_result5;
d_result1.download(h_result1);
d_result2.download(h_result2);
d_result3.download(h_result3);
d_result4.download(h_result4);
d_result5.download(h_result5);
//Measure difference in time ticks
int64 delta = cv::getTickCount() - work_begin;
double freq = cv::getTickFrequency();
//Measure frames per second
double work_fps = freq / delta;
std::cout <<"Performance of Thresholding on GPU: " <<std::endl;
std::cout <<"Time: " << (1/work_fps) <<std::endl;
std::cout <<"FPS: " <<work_fps <<std::endl;
 return 0;
}



(cv) [XXX@th-es-ln0 b5.Chapter5]$ yhrun -p TH_GPU ./14.gpu2.exe
Performance of Thresholding on GPU:
Time: 0.0615325
FPS: 16.2516
(cv) [XXX@th-es-ln0 b5.Chapter5]$ yhrun -p TH_GPU ./13.cpu.exe
Performance of Thresholding on CPU:
Time: 0.0180505
FPS: 55.4002

说点什么...

已有0条评论

最新评论...

本文作者
2023-11-20 00:07
  • 0
    粉丝
  • 98
    阅读
  • 0
    回复
资讯幻灯片
热门评论
热门专题
排行榜
Copyright   ©2015-2023   猿代码-超算人才智造局 高性能计算|并行计算|人工智能      ( 京ICP备2021026424号-2 )