-
Notifications
You must be signed in to change notification settings - Fork 0
/
probe_benchmark.cu
227 lines (187 loc) · 10.7 KB
/
probe_benchmark.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
#include "benchmark/configuration.hpp"
#include "benchmark/data_generator.cu"
#include "hash/hash.cu"
#include "join/join_provider.cuh"
#include "json.hpp"
using json = nlohmann::json;
struct ProbeBenchmarkResult {
BenchmarkConfig benchmark_config;
ProbeBenchmarkConfig probe_config;
JoinBenchmarkConfig join_config;
index_t probe_elements;
double tuples_p_second = 0;
static std::string to_string_header() {
std::ostringstream string_stream;
string_stream << BenchmarkConfig::to_string_header() << "," << JoinBenchmarkConfig::to_string_header() << "," << ProbeBenchmarkConfig::to_string_header() << ","
<< "probe_elements,"
<< "tuples_p_second";
return string_stream.str();
}
std::string to_string() {
std::ostringstream string_stream;
string_stream << benchmark_config.to_string() << "," << join_config.to_string() << "," << probe_config.to_string() << "," << probe_elements << "," << tuples_p_second;
return string_stream.str();
}
};
void store_probe_summary(json &parent_json, ProbeSummary probe_summary) {
json probe_summary_json;
probe_summary_json["k_build_probe_tuples_p_second"] = probe_summary.k_build_probe_tuples_p_second;
probe_summary_json["k_build_probe_gb_p_second"] = probe_summary.k_build_probe_gb_p_second;
probe_summary_json["k_extract_tuples_p_second"] = probe_summary.k_extract_tuples_p_second;
probe_summary_json["k_extract_gb_p_second"] = probe_summary.k_extract_gb_p_second;
probe_summary_json["r_elements"] = probe_summary.r_elements;
probe_summary_json["s_elements"] = probe_summary.s_elements;
probe_summary_json["rs_elements"] = probe_summary.rs_elements;
probe_summary_json["probe_mode"] = probe_summary.probe_mode;
parent_json.push_back(probe_summary_json);
}
int main(int argc, char **argv) {
std::srand(0);
BenchmarkSetup benchmark_setup;
if (!load_benchmark_setup(std::string(argv[1]), std::string(argv[2]), &benchmark_setup)) {
std::cout << "Failed to load config" << std::endl;
return -1;
}
std::fstream run_csv_stream;
run_csv_stream.open((benchmark_setup.output_file_path + "/run.csv"), std::ios::app);
run_csv_stream << ProbeBenchmarkResult::to_string_header() << std::endl;
cudaDeviceProp device_properties;
cudaGetDeviceProperties(&device_properties, 0);
std::cout << device_properties.asyncEngineCount << "," << device_properties.concurrentKernels << "," << device_properties.multiProcessorCount << std::endl;
// fix to 1 for probe config preallocated data
int stream_count = 1; // benchmark_setup.max_streams;
cudaStream_t *streams = new cudaStream_t[stream_count];
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
cudaStreamCreate(&streams[stream_index]);
}
std::vector<BenchmarkConfig> benchmark_configs = get_benchmark_configs(benchmark_setup);
std::vector<ProbeBenchmarkConfig> probe_configs = get_probe_benchmark_configs(benchmark_setup);
std::vector<JoinBenchmarkConfig> join_configs = get_join_configs(benchmark_setup);
ProbeBenchmarkResult best_result;
HashConfig hash_config;
hash_config.algorithm = "fnv";
hash_config.profile_enabled = false;
cudaEvent_t profiling_start, profiling_end;
cudaEventCreate(&profiling_start);
cudaEventCreate(&profiling_end);
json probe_json;
int config_index = 0;
for (auto benchmark_config : benchmark_configs) {
for (auto join_benchmark_config : join_configs) {
int column_count = join_benchmark_config.rs_columns;
index_t s_table_size = benchmark_config.elements;
index_t r_table_size = benchmark_config.elements / join_benchmark_config.rs_scale;
db_table *r_tables = new db_table[stream_count];
db_table *s_tables = new db_table[stream_count];
db_table *rs_tables = new db_table[stream_count];
db_hash_table *r_hash_tables = new db_hash_table[stream_count];
db_hash_table *s_hash_tables = new db_hash_table[stream_count];
size_t table_bytes = (r_table_size + s_table_size) * ((column_count + 1) * sizeof(column_t) + sizeof(hash_t));
size_t rs_bytes = (r_table_size * s_table_size + 1) * sizeof(index_s_t);
if (out_of_memory(table_bytes + rs_bytes)) {
std::cout << "Tables to large" << std::endl;
continue;
}
column_t max_column_value = benchmark_config.max_value;
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
generate_tables(r_table_size, s_table_size, column_count, r_tables[stream_index], s_tables[stream_index], max_column_value, benchmark_config.skew, benchmark_config.distribution);
hash_config.stream = streams[stream_index];
r_hash_tables[stream_index] = db_hash_table(r_tables[stream_index].size, r_tables[stream_index].gpu);
s_hash_tables[stream_index] = db_hash_table(s_tables[stream_index].size, s_tables[stream_index].gpu);
hash_func(r_tables[stream_index].size, 0, sizeof(column_t) / sizeof(chunk_t) * r_tables[stream_index].column_count, (chunk_t *)r_tables[stream_index].column_values, r_hash_tables[stream_index].hashes, hash_config);
hash_func(s_tables[stream_index].size, 0, sizeof(column_t) / sizeof(chunk_t) * s_tables[stream_index].column_count, (chunk_t *)s_tables[stream_index].column_values, s_hash_tables[stream_index].hashes, hash_config);
}
for (auto probe_benchmark_config : probe_configs) {
// config.print();
// print_mem();
config_index++;
printf("%d/%lu\n", config_index, probe_configs.size() * benchmark_configs.size() * join_configs.size());
ProbeConfig probe_config;
probe_config.build_n_per_thread = probe_benchmark_config.build_n_per_thread;
probe_config.build_table_load = probe_benchmark_config.build_table_load;
probe_config.build_threads = probe_benchmark_config.build_threads;
probe_config.extract_threads = probe_benchmark_config.extract_threads;
probe_config.extract_n_per_thread = probe_benchmark_config.extract_n_per_thread;
probe_config.probe_mode = probe_benchmark_config.probe_mode;
if (benchmark_config.profile) {
probe_config.enable_profiling(profiling_start, profiling_end);
}
if (probe_config.probe_mode == ProbeConfig::MODE_PARTITION_S && probe_config.get_max_table_elements() < r_table_size) {
std::cout << "Skipping config due table size" << std::endl;
continue;
}
double tuples_p_second_avg = 0.0;
JoinStatus latest_join_status;
for (int run_index = 0; run_index < benchmark_config.runs; run_index++) {
auto probe_start = std::chrono::high_resolution_clock::now();
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
probe_config.stream = streams[stream_index];
latest_join_status = build_and_probe_gpu(r_tables[stream_index], r_hash_tables[stream_index], s_tables[stream_index], s_hash_tables[stream_index], rs_tables[stream_index], 0, probe_config);
if (latest_join_status.has_failed()) {
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
rs_tables[stream_index].free();
}
std::cout << latest_join_status.message << std::endl;
continue;
}
store_probe_summary(probe_json, probe_config.profiling_summary);
}
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
gpuErrchk(cudaStreamSynchronize(streams[stream_index]));
// gpuErrchk(cudaGetLastError());
}
auto probe_end = std::chrono::high_resolution_clock::now();
double probe_duration = std::chrono::duration_cast<std::chrono::microseconds>(probe_end - probe_start).count() / pow(10, 6);
tuples_p_second_avg += stream_count * (s_tables[0].size + r_tables[0].size) / probe_duration;
// std::cout << " > " << tuples_p_second_avg << std::endl;
// rs_tables[0].print();
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
rs_tables[stream_index].free();
}
if (latest_join_status.has_failed()) {
break;
}
}
probe_config.free();
if (latest_join_status.is_successful()) {
// max value might be clamped by zipf distribution
benchmark_config.max_column_value = max_column_value;
best_result.benchmark_config = benchmark_config;
best_result.probe_config = probe_benchmark_config;
best_result.join_config = join_benchmark_config;
tuples_p_second_avg /= benchmark_config.runs;
best_result.tuples_p_second = tuples_p_second_avg;
best_result.probe_elements = r_table_size;
run_csv_stream << best_result.to_string() << std::endl;
}
}
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
r_tables[stream_index].free();
s_tables[stream_index].free();
rs_tables[stream_index].free();
r_hash_tables[stream_index].free();
s_hash_tables[stream_index].free();
}
delete[] r_tables;
delete[] s_tables;
delete[] rs_tables;
delete[] r_hash_tables;
delete[] s_hash_tables;
}
}
for (int stream_index = 0; stream_index < stream_count; stream_index++) {
cudaStreamDestroy(streams[stream_index]);
}
cudaEventDestroy(profiling_start);
cudaEventDestroy(profiling_end);
if (benchmark_setup.profile) {
std::fstream run_json_stream;
run_json_stream.open((benchmark_setup.output_file_path + "/run.json"), std::ios::app);
run_json_stream << probe_json.dump(1);
run_json_stream.close();
}
// r_table.print();
// s_table.print();
// rs_table.print();
return 0;
}