Я написал небольшую программу, с помощью которой вы можете получить границы цифрового изображения (известный детектор Canny). Необходимо измерить точное время (в миллисекундах) выполнения алгоритма на устройстве (GPU) (включая этапы передачи данных). Я прилагаю рабочий код программы в C:
#include <iostream>
#include <sys/time.h>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <cuda_runtime.h>
#include <opencv2/core/cuda.hpp>
using namespace cv;
using namespace std;
__device__ __host__
void FirstRun (void)
{
cudaSetDevice(0);
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
}
int main( int argc, char** argv )
{
clock_t time;
if (argc != 2)
{
cout << "Wrong number of arguments!" << endl;
return -1;
}
const char* filename = argv[1];
Mat img = imread(filename, IMREAD_GRAYSCALE);
if( !img.data )
{
cout << " --(!) Error reading images \n" << endl;
return -2;
}
double low_tresh = 100.0;
double high_tresh = 150.0;
int apperture_size = 3;
bool useL2gradient = false;
int imageWidth = img.cols;
int imageHeight = img.rows;
cout << "Width of image: " << imageWidth << endl;
cout << "Height of image: " << imageHeight << endl;
cout << endl;
FirstRun();
// Canny algorithm
cuda::GpuMat d_img(img);
cuda::GpuMat d_edges;
time = clock();
Ptr<cuda::CannyEdgeDetector> canny = cuda::createCannyEdgeDetector(low_tresh, high_tresh, apperture_size, useL2gradient);
canny->detect(d_img, d_edges);
time = clock() - time;
cout << "CannyCUDA time (ms): " << (float)time / CLOCKS_PER_SEC * 1000 << endl;
return 0;
}
Я получаю два разных времени работы (изображение 7741 x 8862)
![enter image description here](https://i.stack.imgur.com/lefOR.png)
![enter image description here](https://i.stack.imgur.com/2N9Nu.png)
Конфигурация системы:
1) Процессор: Intel Core i7 9600K (3,6 ГГц), 32 ГБ ОЗУ;
2) Графический процессор: Nvidia Geforce RTX 2080 Ti;
3) OpenCV вер. 4,0
Сколько сейчас времени и правильно ли я его измеряю, спасибо!