forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
104 lines (84 loc) · 3.09 KB
/
main.cpp
File metadata and controls
104 lines (84 loc) · 3.09 KB
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
#include <thread>
#include <iomanip>
#include <CLI11.hpp>
#include "dnn.hpp"
// Function: measure_time_taskflow
std::chrono::milliseconds measure_time_taskflow(
unsigned num_iterations,
unsigned num_threads
) {
auto t1 = std::chrono::high_resolution_clock::now();
run_taskflow(num_iterations, num_threads);
auto t2 = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
}
// Function: measure_time_omp
std::chrono::milliseconds measure_time_omp(
unsigned num_iterations,
unsigned num_threads
) {
auto t1 = std::chrono::high_resolution_clock::now();
run_omp(num_iterations, num_threads);
auto t2 = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
}
// Function: measure_time_tbb
std::chrono::milliseconds measure_time_tbb(
unsigned num_iterations,
unsigned num_threads
) {
auto t1 = std::chrono::high_resolution_clock::now();
run_tbb(num_iterations, num_threads);
auto t2 = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
}
// Function: main
int main(int argc, char *argv[]){
CLI::App app{"Hyperparameter Search"};
unsigned num_threads {1};
app.add_option("-t,--num_threads", num_threads, "number of threads (default=1)");
unsigned num_epochs {10};
app.add_option("-e,--num_epochs", num_epochs, "number of epochs (default=10)");
unsigned num_rounds {1};
app.add_option("-r,--num_rounds", num_rounds, "number of rounds (default=1)");
std::string model = "tf";
app.add_option("-m,--model", model, "model name tbb|omp|tf (default=tf)")
->check([] (const std::string& m) {
if(m != "tbb" && m != "omp" && m != "tf") {
return "model name should be \"tbb\", \"omp\", or \"tf\"";
}
return "";
});
CLI11_PARSE(app, argc, argv);
{
std::string path = std::experimental::filesystem::current_path();
path = path.substr(0, path.rfind("cpp-taskflow") + 12);
path += "/benchmark/parallel_dnn/";
IMAGES = read_mnist_image(path + "./train-images.data");
LABELS = read_mnist_label(path + "./train-labels.data");
TEST_IMAGES = read_mnist_image(path + "./t10k-images-idx3-ubyte");
TEST_LABELS = read_mnist_label(path + "./t10k-labels-idx1-ubyte");
}
::srand(0);
double runtime {0.0};
for(unsigned i=0; i<num_rounds; i++) {
std::cout << 'r' << i << ' '
<< "model=" << model << ' '
<< "num_threads=" << num_threads << ' '
<< "num_rounds=" << num_rounds << ' '
<< "num_epochs=" << num_epochs << ' '
<< std::flush;
if(model == "tf") {
runtime += measure_time_taskflow(num_epochs, num_threads).count();
}
else if(model == "tbb") {
runtime += measure_time_tbb(num_epochs, num_threads).count();
}
else if(model == "omp") {
runtime += measure_time_omp(num_epochs, num_threads).count();
}
else assert(false);
std::cout << "avg_cpu(s)=" << runtime / (i+1) / 1e3 << std::endl;
}
return EXIT_SUCCESS;
}