forked from victoroliv2/CCL-GPU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccl_test.cu
executable file
·133 lines (105 loc) · 2.73 KB
/
ccl_test.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <stdio.h>
#include <cuda.h>
#include "pgm.h"
#include "ccl_gold.cpp"
#include "ccl_uf.cu"
#include "ccl_lequiv.cu"
#include "ccl_naive_prop.cu"
int number_cc(int* label, int w, int h) {
bool* mask = (bool*)malloc(w*h*sizeof(bool));
for (int i=0; i<w*h; i++) {
mask[i] = (label[i] == i);
}
int count = 0;
for (int i=0; i<w*h; i++) {
if (mask[i]) {count++;}
}
free(mask);
return count;
}
#define TRIES 1
float et_v[TRIES];
#define START_TIME cudaEventRecord(start,0)
#define STOP_TIME cudaEventRecord(stop,0 ); \
cudaEventSynchronize(stop); \
cudaEventElapsedTime( &et, start, stop )
int w,h;
unsigned char* img;
int *label, *label_gold;
void VERIFY() {
for (int k=0;k<w*h;k++) {
if (label[k] != label_gold[k]) {
printf("WRONG!\n");
break;
}
}
for (int k=0;k<w*h;k++) {
label[k] = -1;
}
}
float MIN_ET() {
float et = et_v[0];
for (int t=0; t<TRIES; t++) {
et = (et_v[t] < et)? et_v[t] : et;
}
return et;
}
int main(int argc, char* argv[]) {
cudaEvent_t start,stop;
cudaEventCreate( &start );
cudaEventCreate( &stop );
float et;
{
img = load_ppm(argv[1], &w, &h);
label_gold = (int*)malloc(w*h*sizeof(int));
label = (int*)malloc(w*h*sizeof(int));
for (int t=0;t<TRIES;t++) {
START_TIME;
gold::CCL(img, w, h, label_gold);
STOP_TIME;
et_v[t] = et;
}
et = MIN_ET();
printf("cc: %d\n", number_cc(label_gold, w, h));
printf("gold: %.3f\n", et);
for (int t=0;t<TRIES;t++) {
START_TIME;
uf::CCL(img, w, h, label, false);
STOP_TIME;
et_v[t] = et;
}
et = MIN_ET();
printf("uf: %.3f\n", et);
VERIFY();
for (int t=0;t<TRIES;t++) {
START_TIME;
uf::CCL(img, w, h, label, true);
STOP_TIME;
et_v[t] = et;
}
et = MIN_ET();
printf("uf_hybrid: %.3f\n", et);
VERIFY();
for (int t=0;t<TRIES;t++) {
START_TIME;
lequiv::CCL(img, w, h, label);
STOP_TIME;
et_v[t] = et;
}
et = MIN_ET();
printf("lequiv: %.3f\n", et);
VERIFY();
/*for (int t=0;t<TRIES;t++) {
START_TIME;
naive_prop::CCL(img, w, h, label);
STOP_TIME;
et_v[t] = et;
}
et = MIN_ET();
printf("%.3f %.3f\n", et, et_gold/et);
VERIFY();*/
}
free(img);
free(label);
return 0;
}