-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathultimative_bencher.sh
167 lines (148 loc) · 4.96 KB
/
ultimative_bencher.sh
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
#!/bin/bash
### Adjust the following
benchmarks=("IS" "FT" "EP" "CG" "MG")
classes=("B" "C")
cores=("8" "4" "2" "1")
threads=("8" "4" "2" "1")
selection=("0" "All" "1" "Normal" "2" "Half")
###
# We all love colors
RED='\033[0;31m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
NC='\033[0m' # No Color
### Here begins program
function normal_bench() {
export WAIT_FOR_PIPE=2
for f in ./bin/*.x; do
bname=./results/$currentDate/${f##*/}
for i in {1..5}; do
for core in ${cores[@]}; do
for thr in ${threads[@]}; do
perf stat --field-separator , -e duration_time,energy-pkg,energy-cores env LD_PRELOAD=./is_it_openmp.so $f 2>>$bname#$core,$thr.txt | tee -a $bname.log &
while [ ! -p set_cores.pipe -a ! -p set_threads.pipe ]; do
sleep 0.05
done
echo $core > set_cores.pipe
echo $thr > set_threads.pipe
while [ -p set_cores.pipe -a -p set_threads.pipe ]; do
sleep 1
done
done
done
done
done
unset WAIT_FOR_PIPE
}
function half_bench() {
export WAIT_FOR_PIPE=2
default_c="8"
default_t="8"
for f in ./bin/*.x; do
bname=./results/$currentDate/${f##*/}_half
# measure exec time of 8/8
/usr/bin/time -f %e env LD_PRELOAD=./is_it_openmp.so $f 2> /tmp/exec_time &
while [ ! -p set_cores.pipe -a ! -p set_threads.pipe ]; do
sleep 0.05
done
echo $default_c > set_cores.pipe
echo $default_t > set_threads.pipe
while [ -p set_cores.pipe -a -p set_threads.pipe ]; do
sleep 1
done
# calculate half
duration=$(</tmp/exec_time)
sleep_duration=$(bc -l <<<"scale=1; $duration/2")
for thr in ${threads[@]}; do
# switch threads after half of time
if [[ $thr -eq $default_c ]]; then
continue
fi
for i in {1..5}; do
perf stat --field-separator , -e duration_time,energy-pkg,energy-cores env LD_PRELOAD=./is_it_openmp.so $f 2>>$bname#$default_c,$default_t#$thr,$thr.txt | tee -a $bname.log &
while [ ! -p set_cores.pipe -a ! -p set_threads.pipe ]; do
sleep 0.05
done
echo $default_c > set_cores.pipe
echo $default_t > set_threads.pipe
sleep $sleep_duration
echo $thr > set_cores.pipe
echo $thr > set_threads.pipe
while [ -p set_cores.pipe -a -p set_threads.pipe ]; do
sleep 1
done
perf stat --field-separator , -e duration_time,energy-pkg,energy-cores env LD_PRELOAD=./is_it_openmp.so $f 2>>$bname#$default_c,$default_t#$thr,$default_t.txt | tee -a $bname.log &
while [ ! -p set_cores.pipe -a ! -p set_threads.pipe ]; do
sleep 0.05
done
echo $default_c > set_cores.pipe
echo $default_t > set_threads.pipe
sleep $sleep_duration
echo $thr > set_cores.pipe
echo $default_t > set_threads.pipe
while [ -p set_cores.pipe -a -p set_threads.pipe ]; do
sleep 1
done
done
done
done
unset WAIT_FOR_PIPE
}
function compile() {
mkdir bin
for bench in ${benchmarks[@]}; do
for class in ${classes[@]}; do
make $bench CLASS=$class
done
done
}
# experimental check
expected_files=$((${#benchmarks[@]}*${#classes[@]}))
counted_files=`ls -1q bin | wc -l`
me=`basename "$0"`
# compile if needed
if [[ ! -d "bin" ]]; then
echo -e "${BLUE}Info:${NC} bin not found. Compiling..."
compile
else
if [[ $expected_files -ne $counted_files ]]; then
echo -e "${YELLOW}Warning:${NC} You specified $expected_files benchmarks in $me, but I found only $counted_files."
read -p "Shall I compile that for you? [Y/n] " yn
if [[ $yn =~ ^[Nn]$ ]]; then
echo "Okay. Bye Bye."
exit 2
else
compile
fi
else
echo -e "${BLUE}Info:${NC} bin already exists. Skipping compile step."
fi
fi
if [[ ! -d "results" ]]; then
mkdir results
fi
if [[ -p set_cores.pipe ]]; then
rm set_cores.pipe
fi
if [[ -p set_threads.pipe ]]; then
rm set_threads.pipe
fi
currentDate=`date +"%Y-%m-%d-%H-%M-%S"`
mkdir ./results/$currentDate
perfParanoia=$(</proc/sys/kernel/perf_event_paranoid)
if [[ perfParanoia -ne "-1" ]]; then
echo -e "${RED}Perf is too paranoid.${NC}"
exit 1
fi
selection=$(dialog --title "Benchmark Selection" --menu "Select a Benchmark to run" 24 40 5 "${selection[@]}" 3>&2 2>&1 1>&3)
case ${selection} in
0)
normal_bench
half_bench;;
1)
normal_bench;;
2)
half_bench;;
*)
echo "Okay. Bye Bye."
esac