-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cu
executable file
·114 lines (86 loc) · 4.29 KB
/
main.cu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef __GPU__
#define __GPU__
#include "gaussian.cuh"
#include "sobel.cuh"
#include "gamma.cuh"
#include "histogram.cuh"
#endif
#include <string>
#include <cmath>
#include <chrono>
#include <math.h>
int main()
{
/* 4,64 YAPILACAK*/
/*histogram hesabı local histogram*/
/*renkli cache yüklemeler*/
/*histogram 3 cache değişimi*/
/*gaussian denklemi*/
cv::utils::logging::setLogLevel(cv::utils::logging::LogLevel::LOG_LEVEL_SILENT); /*supressing annoying opencv infos in cmdline*/
std::string img_path = "/home/ben/Desktop/cuda-img-enhancement/images/2048.png";
cv::Mat color_img = cv::imread(img_path, cv::IMREAD_COLOR);
cv::Mat gray_img;
cv::cvtColor(color_img, gray_img, cv::COLOR_BGR2GRAY);
cv::Mat color_cpu_img = color_img.clone();
cv::Mat gray_cpu_img = gray_img.clone();
cv::Mat color_cpu_parallel_img = color_img.clone();
cv::Mat gray_cpu_parallel_img = gray_img.clone();
cv::Mat color_gpu_img = color_img.clone();
cv::Mat gray_gpu_img = gray_img.clone();
float gamma = 0.3;
float cpu_3d_elapsed = 0, cpu_1d_elapsed = 0, gpu_1d_elapsed = 0, gpu_1d_sm_elapsed = 0, gpu_3d_elapsed = 0, gpu_3d_sm_elapsed = 0;
float cpu_1d_parallel_elapsed = 0, cpu_3d_parallel_elapsed = 0;
int iter = 1;
for(int i = 0 ; i < iter ; i++){
// cpu_1d_elapsed += gaussian_filter_cpu_1D(gray_img, &gray_cpu_img);
// cpu_3d_elapsed += gaussian_filter_cpu_3D(color_img, &color_cpu_img);
// cpu_1d_parallel_elapsed += gaussian_filter_cpu_parallel_1D(gray_img, &gray_cpu_parallel_img);
// cpu_3d_parallel_elapsed += gaussian_filter_cpu_parallel_3D(color_img, &color_cpu_parallel_img);
// gpu_1d_elapsed += gaussian_filter_gpu_1D(gray_img, &gray_gpu_img, false);
// gpu_1d_sm_elapsed += gaussian_filter_gpu_1D(gray_img, &gray_gpu_img, true);
// gpu_3d_elapsed += gaussian_filter_gpu_3D(color_img, &color_gpu_img, false);
gpu_3d_sm_elapsed += gaussian_filter_gpu_3D(color_img, &color_gpu_img, true);
}
cpu_3d_elapsed /= iter;
cpu_1d_elapsed /= iter;
gpu_1d_elapsed /= iter;
gpu_1d_sm_elapsed /= iter;
gpu_3d_elapsed /= iter;
gpu_3d_sm_elapsed /= iter;
cpu_1d_parallel_elapsed /= iter;
cpu_3d_parallel_elapsed /= iter;
std::cout << "cpu_1d_elapsed: " << cpu_1d_elapsed << "\n";
std::cout << "cpu_1d_parallel_elapsed: " << cpu_1d_parallel_elapsed << "\n";
std::cout << "gpu_1d_elapsed: " << gpu_1d_elapsed << "\n";
std::cout << "gpu_1d_sm_elapsed: " << gpu_1d_sm_elapsed << "\n";
std::cout << "cpu_3d_elapsed: " << cpu_3d_elapsed << "\n";
std::cout << "cpu_3d_parallel_elapsed: " << cpu_3d_parallel_elapsed << "\n";
std::cout << "gpu_3d_elapsed: " << gpu_3d_elapsed << "\n";
std::cout << "gpu_3d_sm_elapsed: " << gpu_3d_sm_elapsed << "\n";
std::cout << "Acceleration of 1d image with multithread: " << cpu_1d_elapsed / cpu_1d_parallel_elapsed << "\n";
std::cout << "Acceleration of 1d image with GPU: " << cpu_1d_elapsed / gpu_1d_elapsed << "\n";
std::cout << "Acceleration of 1d image with GPU-SM: " << cpu_1d_elapsed / gpu_1d_sm_elapsed << "\n";
std::cout << "Acceleration of 3d image with multithread: " << cpu_3d_elapsed / cpu_3d_parallel_elapsed << "\n";
std::cout << "Acceleration of 3d image with GPU: " << cpu_3d_elapsed / gpu_3d_elapsed << "\n";
std::cout << "Acceleration of 3d image with GPU-SM: " << cpu_3d_elapsed / gpu_3d_sm_elapsed << "\n";
std::cout << "Acceleration of shared mem in 1d image: " << gpu_1d_elapsed / gpu_1d_sm_elapsed << "\n";
std::cout << "Acceleration of shared mem in 3d image: " << gpu_3d_elapsed / gpu_3d_sm_elapsed << "\n";
// cv::imshow("img", color_img);
// cv::imshow("img-gray", gray_img);
// cv::imshow("cpu-color", color_cpu_img);
// cv::imshow("cpu-gray", gray_cpu_img);
// // cv::imshow("cpu-color-multithreaded", color_cpu_parallel_img);
// // cv::imshow("cpu-gray-multithreaded", gray_cpu_parallel_img);
// cv::imshow("gpu-color", color_gpu_img);
// cv::imshow("gpu-gray", gray_gpu_img);
// cv::Mat equalizedOpenCV;
// std::vector <cv::Mat> channels;
// cv::split(gray_img,channels);
// for(int i = 0 ; i < channels.size(); i++){
// cv::equalizeHist(channels.at(i),channels.at(i));
// }
// cv::merge(channels,equalizedOpenCV);
// cv::imshow("equalizedOpenCV", equalizedOpenCV);
cv::waitKey(0);
}
/*"Include Directories" C:\opencv\build\include*/