Skip to content

Commit f04c25d

Browse files
added regression.py
1 parent b14508b commit f04c25d

4 files changed

Lines changed: 189 additions & 33 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int main(){
106106
B.precede(D); // B runs before D // | +---+ |
107107
C.precede(D); // C runs before D // +---->| C |-----+
108108
// +---+
109-
executor.run(taskflow).get();
109+
executor.run(taskflow);
110110

111111
return 0;
112112
}

benchmark/graph_traversal/levelgraph.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ class LevelGraph {
9494
_length_num = length;
9595

9696
std::mt19937 g(0); // fixed the seed for graph generator
97-
98-
//std::srand(std::time(nullptr));
99-
std::srand(1);
97+
std::srand(0);
10098

10199
for(size_t l=0; l<level; ++l){
102100

benchmark/mnist/main.cpp

Lines changed: 52 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,44 @@ std::chrono::milliseconds measure_time_tbb(
3939
return std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1);
4040
}
4141

42+
// Procedure
43+
void mnist(
44+
const std::string& model,
45+
const unsigned min_epochs,
46+
const unsigned max_epochs,
47+
const unsigned num_threads,
48+
const unsigned num_rounds
49+
) {
50+
51+
std::cout << std::setw(12) << "epochs"
52+
<< std::setw(12) << "runtime"
53+
<< std::endl;
54+
55+
for(unsigned epochs=min_epochs; epochs <= max_epochs; epochs += 10) {
56+
57+
double runtime {0.0};
58+
59+
for(unsigned i=0; i<num_rounds; i++) {
60+
61+
if(model == "tf") {
62+
runtime += measure_time_taskflow(epochs, num_threads).count();
63+
}
64+
else if(model == "tbb") {
65+
runtime += measure_time_tbb(epochs, num_threads).count();
66+
}
67+
else if(model == "omp") {
68+
runtime += measure_time_omp(epochs, num_threads).count();
69+
}
70+
else assert(false);
71+
72+
std::cout << std::setw(12) << epochs
73+
<< std::setw(12) << runtime / num_rounds / 1e3
74+
<< std::endl;
75+
}
76+
}
77+
78+
}
79+
4280
// Function: main
4381
int main(int argc, char *argv[]){
4482

@@ -47,8 +85,11 @@ int main(int argc, char *argv[]){
4785
unsigned num_threads {1};
4886
app.add_option("-t,--num_threads", num_threads, "number of threads (default=1)");
4987

50-
unsigned num_epochs {10};
51-
app.add_option("-e,--num_epochs", num_epochs, "number of epochs (default=10)");
88+
unsigned max_epochs {100};
89+
app.add_option("-E,--max_epochs", max_epochs, "max number of epochs (default=100)");
90+
91+
unsigned min_epochs {10};
92+
app.add_option("-e,--min_epochs", min_epochs, "min number of epochs (default=10)");
5293

5394
unsigned num_rounds {1};
5495
app.add_option("-r,--num_rounds", num_rounds, "number of rounds (default=1)");
@@ -63,34 +104,16 @@ int main(int argc, char *argv[]){
63104
});
64105

65106
CLI11_PARSE(app, argc, argv);
66-
67-
double runtime {0.0};
68-
69-
for(unsigned i=0; i<num_rounds; i++) {
107+
108+
std::cout << "model=" << model << ' '
109+
<< "num_threads=" << num_threads << ' '
110+
<< "num_rounds=" << num_rounds << ' '
111+
<< "min_epochs=" << min_epochs << ' '
112+
<< "max_epochs=" << max_epochs << ' '
113+
<< std::endl;
114+
115+
mnist(model, min_epochs, max_epochs, num_threads, num_rounds);
70116

71-
std::cout << 'r' << i << ' '
72-
<< "model=" << model << ' '
73-
<< "num_threads=" << num_threads << ' '
74-
<< "num_rounds=" << num_rounds << ' '
75-
<< "num_epochs=" << num_epochs << ' '
76-
<< std::flush;
77-
78-
if(model == "tf") {
79-
runtime += measure_time_taskflow(num_epochs, num_threads).count();
80-
}
81-
else if(model == "tbb") {
82-
runtime += measure_time_tbb(num_epochs, num_threads).count();
83-
}
84-
else if(model == "omp") {
85-
runtime += measure_time_omp(num_epochs, num_threads).count();
86-
}
87-
else assert(false);
88-
89-
std::cout << "avg_cpu(s)=" << runtime / (i+1) / 1e3 << std::endl;
90-
}
91-
92-
93-
94117
return EXIT_SUCCESS;
95118
}
96119

benchmark/regression.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env python
2+
import os
3+
import subprocess
4+
import sys
5+
import math
6+
import argparse
7+
import matplotlib.pyplot as plot
8+
import statistics as stat
9+
10+
tmp_file="/tmp/tmp.txt"
11+
12+
def analyze(Y):
13+
print(
14+
" -> [min, max, avg] = [%f, %f, %f]" %
15+
(min(Y), max(Y), stat.mean(Y))
16+
)
17+
18+
###########################################################
19+
# regression: run
20+
###########################################################
21+
def run(target, method, thread, round):
22+
23+
exe = target + '/' + target
24+
print(exe, '-m', method, '-t', thread, '-r', round)
25+
26+
with open(tmp_file, "w") as ofs:
27+
subprocess.call(
28+
[exe, '-m', method, '-t', str(thread), '-r', str(round)],
29+
stdout=ofs
30+
)
31+
32+
X = []
33+
Y = []
34+
35+
with open(tmp_file, "r") as ifs:
36+
ifs.readline()
37+
ifs.readline()
38+
for line in ifs:
39+
token = line.split()
40+
assert len(token) == 2, "output line must have exactly two numbers"
41+
X.append(int(token[0]))
42+
Y.append(float(token[1]))
43+
44+
analyze(Y)
45+
46+
return X, Y
47+
48+
###########################################################
49+
# main function
50+
###########################################################
51+
def main():
52+
53+
parser = argparse.ArgumentParser(description='regression')
54+
55+
parser.add_argument(
56+
'-b', '--benchmarks',
57+
nargs='+',
58+
help='valid benchmarks: wavefront, graph_traversal',
59+
choices=['wavefront',
60+
'graph_traversal',
61+
'binary_tree',
62+
'linear_chain',
63+
'matrix_multiplication',
64+
'mnist'],
65+
required=True
66+
)
67+
68+
parser.add_argument(
69+
'-m','--methods',
70+
nargs='+',
71+
help='valid methods: omp, tbb, tf',
72+
default=['tf', 'tbb', 'omp'],
73+
choices=['tf', 'tbb', 'omp']
74+
)
75+
76+
parser.add_argument(
77+
'-t', '--threads',
78+
type=int,
79+
nargs='+',
80+
help='list of the number of threads',
81+
required=True
82+
)
83+
84+
parser.add_argument(
85+
'-r', '--num_rounds',
86+
type=int,
87+
help='number of rounds to average',
88+
default=1
89+
)
90+
91+
# parse the arguments
92+
args = parser.parse_args()
93+
94+
print('benchmarks: ', args.benchmarks)
95+
print('threads:', args.threads)
96+
print('methods:', args.methods)
97+
print('num_rounds:', args.num_rounds)
98+
99+
rows = len(args.benchmarks)
100+
cols = len(args.threads)
101+
102+
fig, axes = plot.subplots(rows, cols)
103+
plot_index = 1
104+
105+
for benchmark in args.benchmarks:
106+
for thread in args.threads:
107+
ax = plot.subplot(rows, cols, plot_index)
108+
for method in args.methods:
109+
ax = plot.title(benchmark + ' (' + str(thread) + ' threads)')
110+
X, Y = run(
111+
benchmark, method, thread, args.num_rounds
112+
)
113+
#ax.text(
114+
# .5, .9,
115+
# benchmark + ' (' + str(thread) + ' threads)',
116+
# horizontalalignment='center',
117+
# transform=ax.transAxes
118+
#)
119+
plot.plot(X, Y, label=method)
120+
plot.legend()
121+
print(X)
122+
print(Y)
123+
plot_index = plot_index + 1
124+
125+
plot.tight_layout()
126+
plot.savefig('result.png')
127+
plot.show()
128+
plot.close(fig)
129+
130+
# run the main entry
131+
if __name__ == "__main__":
132+
main()
133+
134+
135+

0 commit comments

Comments
 (0)