-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_rpma.cu
137 lines (114 loc) · 3.33 KB
/
test_rpma.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
134
135
136
137
#include "rpma.cuh"
#include "util.cuh"
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <time.h>
#include <sys/time.h>
using namespace std;
int main(int argc, const char * argv[]) {
if (argc < 3) {
cout << "too few arguments" << endl;
return 0;
}
if (argc > 4) {
cout << "too many arguments" << endl;
}
int mode = 0;
if (argc == 4)
mode = (string(argv[3]) == "show");// 0 for cmp 1 for show
SIZE_TYPE SIZE = atoi(argv[1]);
SIZE_TYPE group_num = atoi(argv[2]);
DEV_VEC_KEY keys;
DEV_VEC_VALUE values;
KEY_TYPE *h_keys = new KEY_TYPE[SIZE];
VALUE_TYPE *h_values = new VALUE_TYPE[SIZE];
ifstream in_key, in_value;
in_key.open("keys.dat");
in_value.open("values.dat");
for (int i = 0; i < SIZE; ++i) {
in_key >> h_keys[i];
in_value >> h_values[i];
}
in_key.close();
in_value.close();
cout << "initiating rpma..." << endl;
RPMA rpma;
init_rpma(rpma);
cout << "repeatly updating rpma..." << endl;
SIZE_TYPE std_group_size = (SIZE + group_num - 1) / group_num;
cErr(cudaDeviceSynchronize());
cErr(cudaDeviceSetLimit(cudaLimitMallocHeapSize, 1024 * 1024 * 1024));
cErr(cudaDeviceSynchronize());
DEV_VEC_SIZE stat(32);
cErr(cudaMemset(RAW_PTR(stat), 0, sizeof(SIZE_TYPE)*32));
cErr(cudaDeviceSynchronize());
TimeKeeper tk;
for (int i = 0; i < group_num; ++i) {
int bg = i * std_group_size;
int ed = min((i + 1) * std_group_size, SIZE);
int group_size = ed - bg;
if (group_size <= 0) break;
keys.resize(group_size);
values.resize(group_size);
cErr(cudaDeviceSynchronize());
cErr(cudaMemcpy(RAW_PTR(keys), h_keys + bg, sizeof(KEY_TYPE) * group_size, cudaMemcpyHostToDevice));
cErr(cudaMemcpy(RAW_PTR(values), h_values + bg, sizeof(VALUE_TYPE) * group_size, cudaMemcpyHostToDevice));
cErr(cudaDeviceSynchronize());
// printf("update %d \n", i);
update_rpma(rpma, keys, values, stat);
if (mode) {
show_rpma(rpma);
}
}
unsigned long long sumstat = 0;
for (int i = 0; i < 32; ++i)
sumstat += ((stat[i])<<i);
cout << sumstat;
cErr(cudaDeviceSynchronize());
tk.checkTime("update complete");
cout << "generating gold keys and values..." << endl;
thrust::sort_by_key(h_keys, h_keys + SIZE, h_values);
cErr(cudaDeviceSynchronize());
cout << "extracting data from rpma..." << endl;
KEY_PTR o_keys;
VALUE_PTR o_values;
get_data_rpma(rpma, o_keys, o_values);
if (mode) {
/*
cout << "keys:" << endl;
for (int i = 0; i < SIZE; ++i) {
cout << i << "\t" << h_keys[i] << "\t" << o_keys[i] << endl;
}
cout << "values:" << endl;
for (int i = 0; i < SIZE; ++i) {
cout << i << "\t" << h_values[i] << "\t" << o_values[i] << endl;
}*/
//show_rpma(rpma);
}
else {
//show_rpma(rpma);
bool succ = true;
for (int i = 0; i < SIZE; ++i) {
if (h_keys[i] != o_keys[i] || h_values[i] != o_values[i]) {
succ = false;
SIZE_TYPE idx = GET_IDX(i, rpma.tree_height);
SIZE_TYPE lane = GET_LANE(i, idx, rpma.tree_height);
cout << "error in linear idx " << i << ", idx " << idx << ", lane " << lane << ", expect(" << h_keys[i] << ", " << h_values[i] << "), but got(" << o_keys[i] << ", " << o_values[i] << ")" << endl;
}
}
if (succ) {
cout << "test succeed" << endl;
}
else {
cout << "test fail" << endl;
}
}
for (int i = 0; i < 32; ++i)
cout << stat[i] << endl;
delete[] o_keys;
delete[] o_values;
destroy_rpma(rpma);
}