-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbench_boxed.sh
More file actions
executable file
·317 lines (268 loc) · 6.83 KB
/
bench_boxed.sh
File metadata and controls
executable file
·317 lines (268 loc) · 6.83 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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
BASE_OPTIONS=(
"#define CONFIG_NO_OUTPUT 0"
"#define CONFIG_DEBUG 0"
"#define CONFIG_DEBUG_ALT_ARITH 0"
"#define CONFIG_TELEMETRY 0"
"#define CONFIG_TELEMETRY_PROMOTIONS 0"
"#define CONFIG_TELEMETRY_PERIOD 0"
"#define CONFIG_PERF_STATS 0"
"#define CONFIG_PERF_STATS_PERIOD 0"
"#define CONFIG_INSTR_TRACES 0"
"#define CONFIG_INSTR_TRACES_PERIOD 0"
"#define CONFIG_TRAP_SHORT_CIRCUITING 0"
"#define CONFIG_INSTR_SEQ_EMULATION 0"
"#define CONFIG_MAGIC_CORRECTNESS_TRAP 0"
"#define CONFIG_KERNEL_SHORT_CIRCUITING 0"
"#define CONFIG_ALT_MATH_VANILLA 0"
"#define CONFIG_ALT_MATH_BOXED_IEEE 1"
"#define CONFIG_ALT_MATH_POSIT 0"
"#define CONFIG_ALT_MATH_MPFR 0"
"#define CONFIG_ALT_MATH_RATIONAL 0"
)
if [[ -z "${FPVM_HOME}" ]]; then
echo "Please source ENV at the root of the FPVM dir"
exit -1
fi
if [[ "$#" -ne 2 ]]; then
echo "Usage: bench_boxed.sh <TEST_DIR> <TEST_NAME>"
echo "TEST_NAME should be the name of the benchmark/binary (e.g. lorenz_attractor)"
exit -1
fi
CONFIG_FILE=$FPVM_HOME/include/fpvm/config.h
TEST_DIR=$1
TEST_NAME=$2
OUTPUT_DIR=$FPVM_HOME/bench_data/boxed/$TEST_NAME
OUTPUT_BACKUP_DIR=${OUTPUT_DIR}_old
rm -rf $OUTPUT_BACKUP_DIR
mv $OUTPUT_DIR $OUTPUT_BACKUP_DIR
mkdir -p $OUTPUT_DIR
function clear_config() {
printf "%s\n" "${BASE_OPTIONS[@]}" > $CONFIG_FILE
printf '\033[0;32m'
echo "Config reset to base"
printf '\033[0m'
}
function set_option() {
if [[ $# -ne 1 ]]; then
echo "ERROR: set_option() called without config argument"
exit -1
fi
if grep -q "$1" $CONFIG_FILE; then
sed -i "/$1/s/0/1/g" $CONFIG_FILE
printf '\033[0;32m'
grep "$1" $CONFIG_FILE
printf '\033[0m'
else
echo "ERROR: Invalid config option passed to set_option()"
exit -1
fi
}
function unset_option() {
if [[ $# -ne 1 ]]; then
echo "ERROR: unset_option() called without config argument"
exit -1
fi
if grep -F -q "$1" $CONFIG_FILE; then
sed -i "/$1/s/1/0/g" $CONFIG_FILE
printf '\033[0;32m'
grep -F "$1" $CONFIG_FILE
printf '\033[0m'
else
echo "ERROR: Invalid config option passed to set_option()"
exit -1
fi
}
function init_test() {
pushd $TEST_DIR
make clean
make
popd
}
function run_test() {
pushd $TEST_DIR
make test
popd
}
function log_diffs() {
if [[ $# -ne 1 ]]; then
echo "ERROR: log_diffs() called without name argument"
exit -1
fi
echo "======" >> ${OUTPUT_DIR}/trap_diff.out
echo "======" >> ${OUTPUT_DIR}/magic_diff.out
echo $1 >> ${OUTPUT_DIR}/trap_diff.out
echo $1 >> ${OUTPUT_DIR}/magic_diff.out
diff <(grep -v "fpvm time" ${TEST_DIR}/${TEST_NAME}.out) <(grep -v "fpvm time" ${TEST_DIR}/${TEST_NAME}.patched_trap.out) >> ${OUTPUT_DIR}/trap_diff.out
diff <(grep -v "fpvm time" ${TEST_DIR}/${TEST_NAME}.out) <(grep -v "fpvm time" ${TEST_DIR}/${TEST_NAME}.patched_magic.out) >> ${OUTPUT_DIR}/magic_diff.out
}
# We'll have to do this specially I think
HW2KERN=200
KERN2USER=400
CALLWRAP=100
BASELINE=${TEST_NAME}.out
function gen_graph_data() {
pushd ${TEST_DIR}
generate_graph_inputs.pl $1 $2 $HW2KERN $KERN2USER $CALLWRAP $BASELINE $3
popd
}
# NOTE: This function expects to be called with all configs set to 0
# except for "NO_OUTPUT", the factors, and the alt math choice
function do_all_graph_data() {
if [[ $# -ne 3 ]]; then
echo "ERROR: do_all_graph_data() improper usage"
exit -1
fi
bench=$1
factors=$2
outfile=$3
# Basic Timing
gen_graph_data $bench $factors $outfile
mv ${TEST_DIR}/${bench}.${factors}.timing.txt $OUTPUT_DIR
# Amortcount (Telem)
unset_option "NO_OUTPUT"
set_option "TELEMETRY "
set_option "TELEMETRY_PROMOTIONS"
make
run_test
gen_graph_data $bench $factors $outfile
mv ${TEST_DIR}/${bench}.${factors}.amortcount.txt $OUTPUT_DIR
# Amortcost (Telem + Perf)
set_option "PERF_STATS "
make
run_test
gen_graph_data $bench $factors $outfile
mv ${TEST_DIR}/${bench}.${factors}.amortcost.txt $OUTPUT_DIR
# TraceHist/Rank (Telem + Perf + Trace)
set_option "TRACES "
make
run_test
gen_graph_data $bench $factors $outfile
mv ${TEST_DIR}/${bench}.${factors}.tracehist.txt $OUTPUT_DIR
mv ${TEST_DIR}/${bench}.${factors}.tracerank.txt $OUTPUT_DIR
}
# Just removing in case it's loaded for some reason
if [ `hostname` = "jarlsberg" ]; then
sudo rmmod fpvm_dev
sudo rm -f /dev/fpvm_dev
fi
init_test
### Test base (nothing turned on)
## Correctness
clear_config
set_option "NO_OUTPUT"
make
run_test
log_diffs "none"
## Graph Data
bench=${TEST_NAME}
factors="none"
outfile="${TEST_NAME}.patched_trap.out"
do_all_graph_data $bench $factors $outfile
### SEQ
## Correctness
clear_config
set_option "NO_OUTPUT"
set_option "INSTR_SEQ_EMULATION"
make
run_test
log_diffs "seq"
## Graph Data
bench=${TEST_NAME}
factors="seq"
outfile="${TEST_NAME}.patched_trap.out"
do_all_graph_data $bench $factors $outfile
### MAGIC
## Correctness
clear_config
set_option "NO_OUTPUT"
set_option "MAGIC"
make
run_test
log_diffs "magic"
## Graph Data
bench=${TEST_NAME}
factors="magic"
outfile="${TEST_NAME}.patched_magic.out"
do_all_graph_data $bench $factors $outfile
### SEQ + MAGIC
## Correctness
clear_config
set_option "NO_OUTPUT"
set_option "INSTR_SEQ_EMULATION"
set_option "MAGIC"
make
run_test
log_diffs "seq-magic"
## Graph Data
bench=${TEST_NAME}
factors="seq-magic"
outfile="${TEST_NAME}.patched_magic.out"
do_all_graph_data $bench $factors $outfile
# LOAD KMOD
echo "Loading kernel module for trap short-circuit"
if [ `hostname` != "jarlsberg" ]; then
exit -1
fi
pushd kernel/
sudo ./kmod_build.sh
sudo ./kmod_setup.sh
popd
### KMOD
## Correctness
clear_config
set_option "NO_OUTPUT"
set_option "TRAP_SHORT_CIRCUIT"
make
FPVM_KERNEL=y run_test
log_diffs "kmod"
## Graph Data
bench=${TEST_NAME}
factors="kmod"
outfile="${TEST_NAME}.patched_magic.out"
FPVM_KERNEL=y do_all_graph_data $bench $factors $outfile
### SEQ + KMOD
## Correctness
clear_config
set_option "NO_OUTPUT"
set_option "INSTR_SEQ_EMULATION"
set_option "TRAP_SHORT_CIRCUIT"
make
FPVM_KERNEL=y run_test
log_diffs "seq-kmod"
## Graph Data
bench=${TEST_NAME}
factors="seq-kmod"
outfile="${TEST_NAME}.patched_magic.out"
FPVM_KERNEL=y do_all_graph_data $bench $factors $outfile
### MAGIC + KMOD
## Correctness
clear_config
set_option "NO_OUTPUT"
set_option "MAGIC"
set_option "TRAP_SHORT_CIRCUIT"
make
FPVM_KERNEL=y run_test
log_diffs "magic-kmod"
## Graph Data
bench=${TEST_NAME}
factors="magic-kmod"
outfile="${TEST_NAME}.patched_magic.out"
FPVM_KERNEL=y do_all_graph_data $bench $factors $outfile
### SEQ + MAGIC + KMOD
## Correctness
clear_config
set_option "NO_OUTPUT"
set_option "INSTR_SEQ_EMULATION"
set_option "MAGIC"
set_option "TRAP_SHORT_CIRCUIT"
make
FPVM_KERNEL=y run_test
log_diffs "seq-magic-kmod"
## Graph Data
bench=${TEST_NAME}
factors="seq-magic-kmod"
outfile="${TEST_NAME}.patched_magic.out"
FPVM_KERNEL=y do_all_graph_data $bench $factors $outfile
sudo rmmod fpvm_dev
sudo rm -f /dev/fpvm_dev