-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
110 lines (76 loc) · 1.92 KB
/
main.cpp
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
#include <thrust/device_vector.h>
#include "cuda.h"
#include <time.h>
#include <cstdlib>
#include <vector>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
/*
srand(time(0));
const int HISTO_SIZE = 20;
//const int HISTO_SIZE = 90000000;
const int MAX = 20;
vector<int> numbers(HISTO_SIZE);
for (int i = 0; i < HISTO_SIZE; i++)
{
numbers[i] = rand() % MAX + 1;
}
#ifdef IS_LOGGING
cout << "These are the numbers to form a histogram from:" << endl;
for (int i = 0; i < HISTO_SIZE; i++)
{
cout << numbers[i] << " ";
}
cout << endl;
#endif
*/
thrust::host_vector<int> resultVector1 = doHistogramGPU();
std::vector<int> resultVector2 = doHistogramCPU();
cout << "Histogram from GPU:" << endl;
for (int i = 0; i < resultVector1.size(); i++)
{
cout << resultVector1[i] << " ";
}
cout << endl;
cout << "Histogram from CPU:" << endl;
for (int i = 0; i < resultVector2.size(); i++)
{
cout << resultVector2[i] << " ";
}
cout << endl;
const int WIDTH = 6;
cout << "Histogram in tabular form (printed from bins from GPU result):" << endl;
cout << endl;
cout << "Bin explanations:" << endl;
cout << "Bin 1: Values 0-63" << endl;
cout << "Bin 2: Values 64-127" << endl;
cout << "Bin 3: Values 128-191" << endl;
cout << "Bin 4: Values 192-255" << endl;
cout << endl;
for (int i = 0; i < 4; i++) //i = blue
{
cout << "B = " << i + 1 << "..." << endl;
cout << setw(WIDTH) << "R=>";
for (int k = 0; k < 4; k++)
{
cout << setw(WIDTH) << k + 1;
}
cout << endl;
cout << setw(WIDTH) << "G" << endl;
cout << setw(WIDTH) << "|" << endl;
cout << setw(WIDTH) << "V" << endl << endl;
for (int j = 0; j < 4; j++) //j = green
{
cout << setw(WIDTH) << j + 1;
for (int k = 0; k < 4; k++) //k = red
{
cout << setw(WIDTH) << resultVector1[i * 16 + j * 4 + k];
}
cout << endl << endl;
}
cout << endl << endl;
}
return 0;
}