-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_benchmarks.sh
executable file
·180 lines (148 loc) · 6.47 KB
/
run_benchmarks.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
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/zsh
CPU=$(sysctl -n machdep.cpu.brand_string | sed -e 's/.*\(M[0-9]\).*/\1/')
COOLDOWN_BEGINNING=60
COOLDOWN_MIDDLE=15
# https://stackoverflow.com/a/226724/523079
cat <<EOF
Requirements and recommendations for running this script:
- Run it from the root of the repository using sudo, which is required to access the CPU cycle counter.
- Run it using the caffeinate command to prevent the system going to sleep during the run: sudo caffeinate ./run_benchmarks.sh
- Try to remove as many sources of variability as possible. We recommend closing down all apps, including menubar ones, and turning off WiFi and Bluetooth. If it is a laptop, we recommend running it connected to AC power, and turning off low power mode.
Would you like to continue?
EOF
select yn in "Yes" "No"; do
case $yn in
Yes ) break;;
No ) exit;;
esac
done
# https://unix.stackexchange.com/a/389406/493812
if [ "$(id -u)" -ne 0 ]; then
echo 'This script must be run by root'
exit 1
fi
if [ -d speed_results_${CPU} ]
then
# https://stackoverflow.com/a/226724/523079
echo 'Existing results will be deleted. Are you sure?'
select yn in "Yes" "No"; do
case $yn in
Yes ) rm -rf speed_results_${CPU}; break;;
No ) exit;;
esac
done
fi
mkdir speed_results_${CPU}
rm -rf build
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
ninja
echo Waiting for the system to cool down for ${COOLDOWN_BEGINNING} seconds...
sleep ${COOLDOWN_BEGINNING}
SCHEMES=("frodokem" "saber")
PARAMETER_SETS_saber=("lightsaber" "saber" "firesaber")
declare -A PARAMETER_SETS=(
[frodokem]="640_AES,640_SHAKE,976_AES,976_SHAKE,1344_AES,1344_SHAKE"
[saber]="lightsaber,saber,firesaber"
)
declare -A IMPLS=(
[frodokem]="ref"
[saber]="BHK"
)
declare -A VARIANTS=(
[frodokem]="ref,opt,neon,opt_amx"
[saber]="neon,amx_polymul,amx_matmul"
)
declare -A SPEED_SUBROUTINE_PREFIXES=(
[frodokem]="matmul"
[saber]="matrixvectormulround"
)
for SCHEME ("$SCHEMES[@]")
do
for PARAMETER_SET ("${(@s:,:)PARAMETER_SETS[${SCHEME}]}")
do
for ALLOC in stack mmap
do
for IMPL ("${(@s:,:)IMPLS[${SCHEME}]}")
do
for VARIANT ("${(@s:,:)VARIANTS[${SCHEME}]}")
do
for BATCHING in "" 4x
do
if [ "$SCHEME" = "frodokem" ]
then
SCHEME_PARAMETER_SET=${SCHEME}_${PARAMETER_SET}
else
SCHEME_PARAMETER_SET=${PARAMETER_SET}
fi
if [ "$VARIANT" = "" ]
then
SPEED_EXEC=speed${BATCHING}_${SCHEME_PARAMETER_SET}_${ALLOC}_${IMPL}
else
SPEED_EXEC=speed${BATCHING}_${SCHEME_PARAMETER_SET}_${ALLOC}_${IMPL}_${VARIANT}
fi
if [ -f ${SPEED_EXEC} ]
then
echo "Benchmarking ${SPEED_EXEC}"
# https://stackoverflow.com/questions/77711672/performance-of-cpu-only-code-varies-with-executable-file-name
cp ${SPEED_EXEC} speed
# Run twice to warm up; e.g. macOS needs to verify the code signature and is slower on the first run
./speed > /dev/null
./speed > /dev/null
# Actual run
./speed > "../speed_results_${CPU}/${SCHEME}${BATCHING}:${PARAMETER_SET}:${ALLOC}:${IMPL}:${VARIANT}.txt"
echo Waiting for the system to cool down for ${COOLDOWN_MIDDLE} seconds...
sleep ${COOLDOWN_MIDDLE}
PREFIX=${SPEED_SUBROUTINE_PREFIXES[${SCHEME}]}
SPEED_SUBROUTINE_EXEC=speed${BATCHING}_${PREFIX}_${SCHEME_PARAMETER_SET}_${ALLOC}_${IMPL}_${VARIANT}
if [ -f ${SPEED_SUBROUTINE_EXEC} ]
then
echo "Benchmarking ${SPEED_SUBROUTINE_EXEC}"
# https://stackoverflow.com/questions/77711672/performance-of-cpu-only-code-varies-with-executable-file-name
cp ${SPEED_SUBROUTINE_EXEC} speed
# Run twice to warm up; e.g. macOS needs to verify the code signature and is slower on the first run
./speed > /dev/null
./speed > /dev/null
# Actual run
./speed > "../speed_results_${CPU}/${PREFIX}${BATCHING}:${PARAMETER_SET}:${ALLOC}:${IMPL}:${VARIANT}.txt"
echo Waiting for the system to cool down for ${COOLDOWN_MIDDLE} seconds...
sleep ${COOLDOWN_MIDDLE}
fi
fi
done
done
done
done
done
done
for PARAMETER_SET in 640 976 1344
do
for IMPL in opt neon opt_amx
do
SPEED_EXEC=sample_ct_experiment_frodokem_${PARAMETER_SET}_${IMPL}
echo "Benchmarking ${SPEED_EXEC}"
# https://stackoverflow.com/questions/77711672/performance-of-cpu-only-code-varies-with-executable-file-name
cp ${SPEED_EXEC} speed
# Run twice to warm up; e.g. macOS needs to verify the code signature and is slower on the first run
./speed > /dev/null
./speed > /dev/null
# Actual run
./speed > "../speed_results_${CPU}/sample_ct:${PARAMETER_SET}:${IMPL}.txt"
echo Waiting for the system to cool down for ${COOLDOWN_MIDDLE} seconds...
sleep ${COOLDOWN_MIDDLE}
done
SPEED_EXEC=speed_sample_frodokem_${PARAMETER_SET}
echo "Benchmarking ${SPEED_EXEC}"
# https://stackoverflow.com/questions/77711672/performance-of-cpu-only-code-varies-with-executable-file-name
cp ${SPEED_EXEC} speed
# Run twice to warm up; e.g. macOS needs to verify the code signature and is slower on the first run
./speed > /dev/null
./speed > /dev/null
# Actual run
./speed > "../speed_results_${CPU}/sample:${PARAMETER_SET}.txt"
echo Waiting for the system to cool down for ${COOLDOWN_MIDDLE} seconds...
sleep ${COOLDOWN_MIDDLE}
done
cd ..
chown -R $(logname) build/ speed_results_${CPU}/