-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_hash.cu
88 lines (75 loc) · 2.91 KB
/
main_hash.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
#include <iostream>
#include <algorithm>
#include <chrono>
#include <vector>
#include <string>
#include "cpuGroupby.h"
#include "groupby_hash.cuh"
int main(int argc, const char * argv[]) {
using Time = std::chrono::high_resolution_clock;
using fsec = std::chrono::duration<float>;
int num_rows = 100000;
int num_key_cols = 2;
int num_val_cols = 3;
int num_distinct_keys = 10;
int hash_table_rows = 1003;
std::vector<std::string> args(argv, argv+argc);
if (argc == 2){
num_rows = stoi(args.at(1));
} else if(argc == 4){
num_rows = stoi(args.at(1));
num_key_cols = stoi(args.at(2));
num_val_cols = stoi(args.at(3));
} else if(argc == 5){
num_rows = stoi(args.at(1));
num_key_cols = stoi(args.at(2));
num_val_cols = stoi(args.at(3));
num_distinct_keys = stoi(args.at(4));
}else if(argc == 6){
num_rows = stoi(args.at(1));
num_key_cols = stoi(args.at(2));
num_val_cols = stoi(args.at(3));
num_distinct_keys = stoi(args.at(4));
hash_table_rows = stoi(args.at(5));
} else {
if (argc != 1) {
std::cerr << "Invalid arguments" << std::endl;
exit(1);
}
}
// Setting up the CPU groupby
cpuGroupby slowGroupby(num_key_cols, num_val_cols, num_rows);
slowGroupby.fillRand(num_distinct_keys, num_rows);
int *original_key_columns;
cudaMallocHost((void**)&original_key_columns, sizeof(int)*num_key_cols*num_rows);
int *original_value_columns;
cudaMallocHost((void**)&original_value_columns, sizeof(int)*num_val_cols*num_rows);
std::copy(slowGroupby.key_columns, slowGroupby.key_columns + num_key_cols*num_rows, original_key_columns);
std::copy(slowGroupby.value_columns, slowGroupby.value_columns + num_val_cols*num_rows, original_value_columns);
auto start = Time::now();
slowGroupby.groupby();
auto end = Time::now();
fsec cpu_duration = end - start;
// Insert GPU function calls here...
int *gpu_output_keys, *gpu_output_values;
int gpu_output_rows = 0;
gpu_output_keys = new int[slowGroupby.num_key_rows*slowGroupby.num_key_columns];
gpu_output_values = new int[slowGroupby.num_value_rows*slowGroupby.num_value_columns];
start = Time::now();
groupby_hash_GPU(hash_table_rows,original_key_columns, slowGroupby.num_key_columns,
slowGroupby.num_key_rows, original_value_columns,
slowGroupby.num_value_columns, slowGroupby.num_value_rows,
slowGroupby.ops, slowGroupby.num_ops,
gpu_output_keys, gpu_output_values, gpu_output_rows);
end = Time::now();
#ifndef NOPRINT
slowGroupby.printGPUResults(gpu_output_keys, gpu_output_values);
#endif
fsec gpu_duration = end - start;
std::cout << "CPU time: " << cpu_duration.count() << " s" << std::endl;
std::cout << "GPU time: " << gpu_duration.count() << " s" << std::endl;
slowGroupby.validGPUResult(gpu_output_keys, gpu_output_values, gpu_output_rows, false);
cudaFreeHost(original_value_columns);
cudaFreeHost(original_key_columns);
return 0;
}