-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcpu2006express.sh
executable file
·488 lines (452 loc) · 15.8 KB
/
cpu2006express.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
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
#!/bin/bash
##############################################################################
# cpu2006express.sh - This utility performs SPEC CPU2006 benchmarking using
# GCC. Capabilities include in installing prerequisites, building and
# installing SPEC CPU2006, and running reportable integer and floating-point
# runs.
#
# Required file tree:
#
# |-- config
# | |-- linux32-arm32-gcc.cfg
# | |-- linux32-intel32-gcc.cfg
# | |-- linux64-arm64-gcc.cfg
# | |-- linux64-intel64-gcc.cfg
# | `-- linux64-powerpc-gcc.cfg
# |
# |-- bin
# | |-- setup.sh
# | |-- spinner.sh
# | `-- user_input.sh
# |
# |-- cpu2006-*.tar* (You provide this file)
# |
# `-- cpu2006express.sh
#
#
# Usage: cpu2006express.sh [OPTIONS]...
#
# Option GNU long option Meaning
# -h --help Show this message
# -r --rebuild Force SPEC CPU2006 rebuild and installation
# -o --onecopy Do a single copy run
# -i --int Run integer
# -f --fp Run floating-point
# -c --complete Do a complete run (int and fp) with defaults
# -p --prereq Install prerequisites
# -q --quiet Show less detailed information
#
##############################################################################
#
# Last Updated:
# 4/15/2015
#
# Authors/Contributors:
# Ryan Spoone (github.com/ryanspoone)
# Tyler Stachecki (github.com/tj90241)
# Matthew Nicely (github.com/manicely6005)
#
##############################################################################
############################################################
# Import sources
############################################################
source "$(pwd)/bin/spinner.sh"
source "$(pwd)/bin/user_input.sh"
source "$(pwd)/bin/setup.sh"
############################################################
# Argument switch variables
############################################################
VERBOSE=true
REBUILD=false
NOPREREQ=true
INT=false
FP=false
NOCOPY=false
############################################################
# Flag parsing
############################################################
if [[ "$#" -gt 0 ]]; then
while [ "$1" ]; do
ARG="$1"
if [[ "$ARG" == "-q" || "$ARG" == "--quiet" ]]; then
VERBOSE=false
shift
elif [[ "$ARG" == "-o" || "$ARG" == "--onecopy" ]]; then
NOCOPY=true
shift
elif [[ "$ARG" == "-c" || "$ARG" == "--complete" ]]; then
INT=true
FP=true
NOPREREQ=false
shift
elif [[ "$ARG" == "-r" || "$ARG" == "--rebuild" ]]; then
REBUILD=true
shift
elif [[ "$ARG" == "-p" || "$ARG" == "--prereq" ]]; then
NOPREREQ=false
shift
elif [[ "$ARG" == "-i" || "$ARG" == "--int" ]]; then
INT=true
shift
elif [[ "$ARG" == "-f" || "$ARG" == "--fp" ]]; then
FP=true
shift
elif [[ "$ARG" == "-h" || "$ARG" == "--help" ]]; then
echo "Usage: cpu2006express.sh [OPTIONS]..."
echo
echo "Option GNU long option Meaning"
echo " -h --help Show this message"
echo " -r --rebuild Force SPEC CPU2006 rebuild and installation"
echo " -o --onecopy Do a single copy run"
echo " -i --int Run integer"
echo " -f --fp Run floating-point"
echo " -c --complete Do a complete run (int and fp) with defaults"
echo " -p --prereq Install prerequisites"
echo " -q --quiet Show less detailed information"
exit
else
echo "cpu2006express: invalid operand ‘$ARG’"
echo "Try 'cpu2006express --help' for more information."
exit
fi
done
else
echo
echo "Usage: cpu2006express.sh [OPTIONS]..."
echo "Try 'cpu2006express --help' for more information."
echo
exit
fi
############################################################
# Double check if user really meant no int and fp runs
############################################################
if [[ $INT == false && $FP == false ]]; then
echo -n "You picked no runs. Is this correct (y/n)? "
read NORUN
if [[ "$NORUN" == *"n"* ]]; then
echo -n "Would you like an integer run (y/n)?"
read INT_ANS
if [[ "$INT_ANS" == *"y"* ]]; then
INT=true
fi
echo -n "Would you like an floating-point run (y/n)?"
read FP_ANS
if [[ "$FP_ANS" == *"y"* ]]; then
FP=true
fi
fi
fi
############################################################
# Set environment stack size
############################################################
ulimit -s unlimited
############################################################
# Will display make, type, and model number
# Example: GenuineIntel
############################################################
CPU=$(grep 'vendor_id' /proc/cpuinfo | uniq | sed 's/vendor_id\s*:\s//g')
############################################################
# If CPU is still empty
# This is mainly for Intel systems
# Example: Intel Atom C2750
# Example: Intel Xeon E5-1650 0
############################################################
if [ -z "$CPU" ]; then
CPU=$(grep 'model name' /proc/cpuinfo | uniq | sed 's/model name\s*:\s//g')
fi
############################################################
# If CPU is empty
# This is mainly for ARM systems
# Example: AArch64 Processor rev 0
############################################################
if [ -z "$CPU" ]; then
CPU=$(grep 'Processor' /proc/cpuinfo | uniq | sed 's/Processor\s*:\s//g')
fi
############################################################
# If CPU is still empty
# This is mainly for PowerPC systems
# Example: POWER8 (raw), altivec supported
############################################################
if [ -z "$CPU" ]; then
CPU=$(grep 'cpu' /proc/cpuinfo | uniq | sed 's/cpu\s*:\s//g')
fi
############################################################
# Get OS and version
# Example OS: Ubuntu
# Example VER: 14.04
############################################################
if [ -f /etc/lsb-release ]; then
. /etc/lsb-release
OS=$DISTRIB_ID
VER=$DISTRIB_RELEASE
elif [ -f /etc/debian_version ]; then
OS='Debian'
VER=$(cat /etc/debian_version)
elif [ -f /etc/redhat-release ]; then
OS='Redhat'
VER=$(cat /etc/redhat-release)
else
OS=$(uname -s)
VER=$(uname -r)
fi
############################################################
# GCC version
############################################################
GCC_VER=$(gcc --version | sed -rn 's/gcc\s\(.*\)\s([0-9]*\.[0-9]*\.[0-9]*)/\1/p')
GCC_VER_NO_DOTS=${GCC_VER//\./}
export GCC_VER_SHORT=${GCC_VER_NO_DOTS:0:2}
if [ -z "$GCC_VER" ]; then
echo "Cannot determine GCC version."
fi
############################################################
# Detect os architecture, os distribution, and os version
# Displays bits, either 64 or 32
############################################################
ARCH=$(uname -m | sed 's/x86_//;s/i[3-6]86/32/')
############################################################
# If it is an ARM system
############################################################
if [[ $ARCH == *'aarch64'* || $ARCH == *'arm'*]]; then
# Get the ARM version number
ARM_V=$(echo "$ARCH" | sed 's/armv//g' | sed 's/[^0-9]*//g')
# If ARMv8 or greater, set to 62 bit
if [ "$ARM_V" -ge '8' || $ARCH == *'aarch64'* ]; then
ARCH='64'
else
ARCH='32'
fi
fi
############################################################
# Virtual cores / logical cores / threads
############################################################
LOGICAL_CORES=$(grep -c processor /proc/cpuinfo)
############################################################
# The amount of RAM needed to run all copies of SPEC
############################################################
REQUIRED_RAM=$((LOGICAL_CORES * 2))
############################################################
# Get RAM in KB
############################################################
RAM_KB=$(grep "MemTotal: " /proc/meminfo | sed "s/MemTotal: //g" | tr -d ' ' | sed "s/kB//g")
############################################################
# Convert RAM to GB
############################################################
RAM_GB=$((RAM_KB / 1000 / 1000))
############################################################
# Set number of copies the hardware can handle
############################################################
if [[ $NOCOPY == false ]]; then
if [[ $RAM_GB > $REQUIRED_RAM ]]; then
COPIES=$LOGICAL_CORES
else
COPIES=$((RAM_GB / 2))
fi
else
COPIES='1'
fi
############################################################
# The name of the target machine architecture
############################################################
if [[ $CPU == *'Power'* || $CPU == *'power'* || $CPU == *'POWER'* || $CPU == *'ppc'* ]]; then
MARCH=$(gcc -mcpu=native -Q --help=target 2> /dev/null | grep '\-mcpu=' | head -n 1 | sed "s/-mcpu=//g" | tr -d " \t\n\r")
MTUNE=$(gcc -mcpu="$MARCH" -mtune=native -Q --help=target 2> /dev/null | grep '\-mtune=' | head -n 1 | sed "s/-mtune=//g" | tr -d " \t\n\r")
else
MARCH=$(gcc -march=native -Q --help=target 2> /dev/null | grep '\-march=' | head -n 1 | sed "s/-march=//g" | tr -d " \t\n\r")
MTUNE=$(gcc -march="$MARCH" -mtune=native -Q --help=target 2> /dev/null | grep '\-mtune=' | head -n 1 | sed "s/-mtune=//g" | tr -d " \t\n\r")
fi
############################################################
# Select the proper config file
############################################################
if [[ $CPU == *'Intel'* ]]; then
if [[ $ARCH == *'32'* ]]; then
GCC_CONFIG='linux32-intel32-gcc'
else
GCC_CONFIG='linux64-intel64-gcc'
fi
elif [[ $CPU == *'ARM'* ]] || [[ $CPU == *'AArch'* ]] || [[ $CPU == *'APM X-Gene Mustang'* ]]; then
if [[ $ARCH == *'32'* ]]; then
GCC_CONFIG='linux32-arm32-gcc'
else
GCC_CONFIG='linux64-arm64-gcc'
fi
elif [[ $CPU == *'Power'* || $CPU == *'power'* || $CPU == *'POWER'* || $CPU == *'ppc'* ]]; then
export GCC_CONFIG='linux64-powerpc-gcc'
else
echo
echo 'Unable to determine which config file to use.'
echo
proc_arch
fi
############################################################
# Select the proper machine flag for the config file
############################################################
if [[ $(containsElement "${KNOWN_MTUNE[@]}" "$MTUNE") == 'y' ]]; then
export MACHINE=$MTUNE
else
if [[ $(containsElement "${KNOWN_MARCH[@]}" "$MARCH") == 'y' ]]; then
export MACHINE=$MARCH
else
echo
echo 'We cannot determine your machine architecture.'
echo
getMachine
fi
fi
############################################################
# Setting the CPU2006 run commands
############################################################
INT_COMMAND="runspec --config $GCC_CONFIG --machine $MACHINE --rate --copies $COPIES --reportable int"
FP_COMMAND="runspec --config $GCC_CONFIG --machine $MACHINE --rate --copies $COPIES --reportable fp"
############################################################
# Display system information and warnings
############################################################
echo
echo '*************************** System Information **************************'
echo
echo "CPU: $CPU"
echo "Architecture: $ARCH bit"
echo "OS: $OS $VER"
echo "GCC Version: $GCC_VER"
echo "Logical cores: $LOGICAL_CORES"
echo "Total RAM: $RAM_GB GB"
echo "Copies: $COPIES"
echo "GCC config file: $GCC_CONFIG"
echo "GCC INT command: $INT_COMMAND"
echo "GCC FP command: $FP_COMMAND"
echo
echo '******************************* Warnings ********************************'
if [[ $RAM_GB -ge $REQUIRED_RAM ]]; then
echo
echo ' None'
echo
else
echo
echo "The number of copies has been changed from $LOGICAL_CORES to $COPIES"
echo "because there isn't enough RAM to support the number of CPUs on this machine."
echo 'Please add more RAM to this machine to run the optimal amount of copies.'
echo
fi
echo '*************************************************************************'
echo
echo 'Please exit now if this information is not correct. Otherwise, resuming'
echo 'in 20 seconds...'
echo
echo '*************************************************************************'
echo
sleep 20
############################################################
################# Install Prerequisites ####################
############################################################
if [[ $NOPREREQ == false ]]; then
if [[ $VERBOSE == false ]]; then
echo
start_spinner 'Checking if prerequisites need to be installed and installing if necessary...'
$(prerequisites &) > /dev/null 2>&1
stop_spinner $?
echo
else
echo
echo 'Checking if prerequisites need to be installed and installing if necessary...'
prerequisites
echo
fi
fi
echo '*************************************************************************'
############################################################
######################## Run setup #########################
############################################################
if [[ $REBUILD == false ]]; then
if [[ $VERBOSE == false ]]; then
echo
start_spinner 'Checking if CPU2006 needs to be installed and installing if necessary...'
$(setup &) > /dev/null 2>&1
stop_spinner $?
echo
else
echo
echo 'Checking if CPU2006 needs to be installed and installing if necessary...'
setup
echo
fi
else
if [[ $VERBOSE == false ]]; then
echo
start_spinner 'Rebuilding CPU2006...'
$(rebuildSPECCPU &) > /dev/null 2>&1
stop_spinner $?
echo
else
echo
echo 'Rebuilding CPU2006...'
rebuildSPECCPU
echo
fi
fi
echo '*************************************************************************'
############################################################
########################## Run int #########################
############################################################
if [[ $INT == true ]]; then
if [[ $VERBOSE == false ]]; then
echo
start_spinner 'Running all the int benchmarks...'
$($INT_COMMAND &) > /dev/null 2>&1
stop_spinner $?
echo
else
echo
echo 'Running all the int benchmarks...'
$INT_COMMAND
echo
fi
echo '*************************************************************************'
fi
############################################################
########################## Run fp ##########################
############################################################
if [[ $FP == true ]]; then
if [[ $VERBOSE == false ]]; then
echo
start_spinner 'Running all the fp benchmarks...'
$($FP_COMMAND &) > /dev/null 2>&1
stop_spinner $?
echo
else
echo
echo 'Running all the fp benchmarks...'
$FP_COMMAND
echo
fi
echo '*************************************************************************'
fi
############################################################
# Display results directory and files within, in addition to
# the commands used.
############################################################
cd "$SPEC/result"
echo
echo 'Results directory:'
echo
pwd
echo
echo '*************************************************************************'
echo
echo 'All files in directory:'
echo
ls
echo
echo '*************************************************************************'
echo
echo 'All commands issued:'
echo
grep runspec: ./*log
echo
echo '*************************************************************************'
echo
############################################################
# Clean up exports
############################################################
unset MACHINE
unset GCC_VER_SHORT
unset KNOWN_MARCH
unset KNOWN_MTUNE