-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.cu
318 lines (273 loc) · 10.7 KB
/
bench.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include "xxhash.hcu"
#include "utils.hcu"
#include "cuckoo_serial.hcu"
#include "cuckoo_cuda_native.hcu"
#include <string>
#include "CSVWriter.h"
using namespace csv;
void test_cuckoo_serial();
void test_cuckoo_cuda();
void bench_task1_cuckoo();
void bench_task2_cuckoo();
void bench_task3_cuckoo();
void bench_task4_cuckoo();
int main()
{
// ha? naïve
srand(19260817);
// test_xxhash();
// test_cuckoo_serial();
// test_cuckoo_cuda();
bench_task1_cuckoo();
bench_task2_cuckoo();
bench_task3_cuckoo();
bench_task4_cuckoo();
return 0;
}
void bench_task1_cuckoo()
{
// create csv writer
CsvWriter serial_writer("task1_serial.csv");
CsvWriter cuda_writer("task1_cuda.csv");
Record header;
header.put("func_num");
header.put("scale");
header.put("mean");
header.put("stddev");
serial_writer.setHeader(header);
cuda_writer.setHeader(header);
printf("task 1\n");
uint32_t hash_table_size = 1 << 25;
for (int num_funcs = 2; num_funcs <= 4; ++num_funcs)
{
for (int scale = 10; scale <= 24; ++scale)
{
int n = 1 << scale;
uint32_t *input_keys = new uint32_t[n];
generate_unique_random(input_keys, n);
double duration_serial[5];
double duration_cuda[5];
for (int rep = 0; rep < 5; rep++)
{
CuckooSerialHashTable ht_serial(hash_table_size, 4 * clog2(n), num_funcs);
CuckooCudaHashTable ht_cuda(hash_table_size, 4 * clog2(n), num_funcs);
int level_serial;
int level_cuda;
duration_serial[rep] = time_func([&]
{ level_serial = ht_serial.insert(input_keys, n); });
duration_cuda[rep] = time_func([&]
{ level_cuda = ht_cuda.insert(input_keys, n); });
printf("hash-func-num %-10d scale %-10d repeat-times %-10d serial time: %-10lf rehash %-10d cuda time: %-10lf rehash %-10d\n", num_funcs, scale, rep, duration_serial[rep], level_serial, duration_cuda[rep], level_cuda);
}
double mean_serial = average(duration_serial, 5);
double stddev_serial = standardDev(duration_serial, 5);
double mean_cuda = average(duration_cuda, 5);
double stddev_cuda = standardDev(duration_cuda, 5);
Record record;
record.put(num_funcs);
record.put(scale);
record.put(mean_serial);
record.put(stddev_serial);
serial_writer.insertRecord(record);
Record record_cuda;
record_cuda.put(num_funcs);
record_cuda.put(scale);
record_cuda.put(mean_cuda);
record_cuda.put(stddev_cuda);
cuda_writer.insertRecord(record_cuda);
delete[] input_keys;
}
}
serial_writer.write();
cuda_writer.write();
}
void bench_task2_cuckoo()
{
CsvWriter serial_writer("task2_serial.csv");
CsvWriter cuda_writer("task2_cuda.csv");
Record header;
header.put("func_num");
header.put("percent");
header.put("mean");
header.put("stddev");
serial_writer.setHeader(header);
cuda_writer.setHeader(header);
printf("task 2\n");
uint32_t hash_table_size = 1 << 25;
uint32_t n = 1 << 24;
for (int num_funcs = 3; num_funcs <= 4; ++num_funcs)
{
uint32_t *insert_values = new uint32_t[n];
uint32_t *lookup_values = new uint32_t[n];
bool *results = new bool[n];
for (int percent = 0; percent <= 10; ++percent)
{
int bound = ceil((1 - 0.1 * percent) * n);
double duration_serial[5];
double duration_cuda[5];
for (int rep = 0; rep < 5; ++rep)
{
generate_unique_random(insert_values, n);
for (int i = 0; i < bound; ++i)
lookup_values[i] = insert_values[rand() % n];
for (int i = bound; i < n; ++i)
lookup_values[i] = rand() % (int)(1.5 * n) + 1;
CuckooSerialHashTable ht_serial(hash_table_size, 4 * clog2(n), num_funcs);
CuckooCudaHashTable ht_cuda(hash_table_size, 4 * clog2(n), num_funcs);
ht_serial.insert(insert_values, n);
ht_cuda.insert(insert_values, n);
duration_serial[rep] = time_func([&]
{ ht_serial.lookup(lookup_values, results, n); });
duration_cuda[rep] = time_func([&]
{ ht_cuda.lookup(lookup_values, results, n); });
printf("hash-func-num %-10d percent %-5d repeat-times %-10d serial time: %-10lf cuda time: %-10lf\n", num_funcs, percent * 10, rep, duration_serial[rep], duration_cuda[rep]);
}
double mean_serial = average(duration_serial, 5);
double stddev_serial = standardDev(duration_serial, 5);
double mean_cuda = average(duration_cuda, 5);
double stddev_cuda = standardDev(duration_cuda, 5);
Record record;
record.put(num_funcs);
record.put(percent);
record.put(mean_serial);
record.put(stddev_serial);
serial_writer.insertRecord(record);
Record record_cuda;
record_cuda.put(num_funcs);
record_cuda.put(percent);
record_cuda.put(mean_cuda);
record_cuda.put(stddev_cuda);
cuda_writer.insertRecord(record_cuda);
}
delete[] insert_values;
delete[] lookup_values;
delete[] results;
}
serial_writer.write();
cuda_writer.write();
}
void bench_task3_cuckoo()
{
CsvWriter serial_writer("task3_serial.csv");
CsvWriter cuda_writer("task3_cuda.csv");
Record header;
header.put("func_num");
header.put("ratios");
header.put("mean");
header.put("stddev");
serial_writer.setHeader(header);
cuda_writer.setHeader(header);
printf("task 3\n");
uint32_t n = 1 << 24;
uint32_t *insert_values = new uint32_t[n];
generate_unique_random(insert_values, n);
for (int num_funcs = 3; num_funcs <= 4; ++num_funcs)
{
float ratios[] = {1.9, 1.8, 1.7, 1.6, 1.5, 1.4, 1.3, 1.2, 1.1, 1.05, 1.02, 1.01};
for (int ri = 0; ri < 12; ++ri)
{
double duration_serial[5];
double duration_cuda[5];
int size = ceil(ratios[ri] * n);
for (int rep = 0; rep < 5; ++rep)
{
CuckooSerialHashTable ht_serial(size, 4 * clog2(n), num_funcs);
CuckooCudaHashTable ht_cuda(size, 4 * clog2(n), num_funcs);
int level_serial;
int level_cuda;
duration_serial[rep] = time_func([&]
{ level_serial = ht_serial.insert(insert_values, n); });
duration_cuda[rep] = time_func([&]
{ level_cuda = ht_cuda.insert(insert_values, n); });
printf("hash-func-num %-10d ratios %-10lf repeat-times %-10d serial time: %-10lf rehash %-10d cuda time: %-10lf rehash %-10d\n", num_funcs, ratios[ri], rep, duration_serial[rep], level_serial, duration_cuda[rep], level_cuda);
}
double mean_serial = average(duration_serial, 5);
double stddev_serial = standardDev(duration_serial, 5);
double mean_cuda = average(duration_cuda, 5);
double stddev_cuda = standardDev(duration_cuda, 5);
Record record;
record.put(num_funcs);
record.put(ratios[ri]);
record.put(mean_serial);
record.put(stddev_serial);
serial_writer.insertRecord(record);
Record record_cuda;
record_cuda.put(num_funcs);
record_cuda.put(ratios[ri]);
record_cuda.put(mean_cuda);
record_cuda.put(stddev_cuda);
cuda_writer.insertRecord(record_cuda);
}
}
serial_writer.write();
cuda_writer.write();
delete[] insert_values;
}
void bench_task4_cuckoo()
{
CsvWriter serial_writer("task4_serial.csv");
CsvWriter cuda_writer("task4_cuda.csv");
Record header;
header.put("func_num");
header.put("bound_mul");
header.put("mean");
header.put("stddev");
serial_writer.setHeader(header);
cuda_writer.setHeader(header);
printf("task 4\n");
int n = 0x1 << 24, size = ceil(1.4 * n);
uint32_t *insert_values = new uint32_t[n];
generate_unique_random(insert_values, n);
for (int num_funcs = 3; num_funcs <= 4; ++num_funcs)
{
for (int bound_mul = 1; bound_mul <= 10; ++bound_mul)
{
double duration_serial[5];
double duration_cuda[5];
for (int rep = 0; rep < 5; rep++)
{
CuckooSerialHashTable ht_serial(size, bound_mul * clog2(n), num_funcs);
CuckooCudaHashTable ht_cuda(size, bound_mul * clog2(n), num_funcs);
int level_serial;
int level_cuda;
duration_serial[rep] = time_func([&]
{ level_serial = ht_serial.insert(insert_values, n); });
duration_cuda[rep] = time_func([&]
{ level_cuda = ht_cuda.insert(insert_values, n); });
printf("hash-func-num %-10d bound-mul %-10d repeat-times %-10d serial time: %-10lf rehash %-10d cuda time: %-10lf rehash %-10d\n", num_funcs, bound_mul, rep, duration_serial[rep], level_serial, duration_cuda[rep], level_cuda);
}
double mean_serial = average(duration_serial, 5);
double stddev_serial = standardDev(duration_serial, 5);
double mean_cuda = average(duration_cuda, 5);
double stddev_cuda = standardDev(duration_cuda, 5);
Record record;
record.put(num_funcs);
record.put(bound_mul);
record.put(mean_serial);
record.put(stddev_serial);
serial_writer.insertRecord(record);
Record record_cuda;
record_cuda.put(num_funcs);
record_cuda.put(bound_mul);
record_cuda.put(mean_cuda);
record_cuda.put(stddev_cuda);
cuda_writer.insertRecord(record_cuda);
}
}
serial_writer.write();
cuda_writer.write();
delete[] insert_values;
}
void test_cuckoo_serial()
{
CuckooSerialHashTable x(1000, 12, 5);
test_hashtable("CuckooSerialHashTable", x);
}
void test_cuckoo_cuda()
{
CuckooCudaHashTable x(1000, 12, 5);
test_hashtable("CuckooCudaHashTable", x);
}