-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·181 lines (159 loc) · 3.54 KB
/
run.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
#!/usr/bin/env bash
## Default valies
CPU_COUNT=1024
BLOCK_SIZE=1024
THREADS=1
BLD_SCRIPT="__build.sh"
RUN_SCRIPT="__run.sh"
TEST_DIR_PREFIX="test-"
LOG_PREFIX="####"
function sim_dir_valid()
{
if [ -e "$1/$BLD_SCRIPT" ] && [ -e "$1/$RUN_SCRIPT" ]
then
return 0
else
return 1
fi
}
function sim_list()
{
for dir in "$TEST_DIR_PREFIX"*
do
if sim_dir_valid "$dir"
then
echo "${dir:5}"
fi
done
}
function print_help()
{
echo "Usage: $0 [OPTION]... [SIM...]"
echo "Run simulator benchmark. Calculates MD5 hash from a block data"
echo "on an array of soft-cores PicoRV32."
echo
echo "Options:"
echo " -c [COUNT] Soft CPU count in simulation. Default: 1024"
echo " -s [SIZE] Data block size in bytes. Default: 1024 bytes"
echo " -t [COUNT] Simulation threads count. Default: 1"
echo " (so far only for Verilator)"
echo " -l List of available benchmarks"
echo " -h This help"
echo
echo "The SIM parameter is the name of the simulator from the list of"
echo "option -l. If the parameter is not specified, benchmarks for all"
echo "simulators will be performed. Be careful, some simulators take "
echo "a very long time to benchmark."
echo
}
function check_arg(){
if [[ $2 == -* ]]
then
echo "Option $1 requires an argument" >&2
exit 1
fi
}
function parse_param()
{
while getopts ":c:s:t:lh" opt
do
case $opt in
c)
check_arg "-c" "$OPTARG"
CPU_COUNT=$OPTARG
;;
s)
check_arg "-s" "$OPTARG"
BLOCK_SIZE=$OPTARG
;;
t)
check_arg "-t" "$OPTARG"
THREADS=$OPTARG
;;
l)
sim_list
exit 0
;;
h)
print_help
exit 0
;;
\?)
echo "Invalid option: -$OPTARG" >&2
print_help
exit 1
;;
:)
echo "Option -$OPTARG requires an argument" >&2
exit 1
;;
esac
done
}
function log()
{
echo -n "$LOG_PREFIX "
echo "$@"
}
function run_benchmark()
{
benchmark=$1
dir=$TEST_DIR_PREFIX$benchmark
if sim_dir_valid "$dir"
then
local t0 t1 ms
if cd "$dir"
then
# Build
log "Build $benchmark"
t0=$(date +%s%N | cut -b1-13)
if ! ./$BLD_SCRIPT "$CPU_COUNT" "$BLOCK_SIZE" "$THREADS"
then
cd ..
log "Build $benchmark FAILED"
return 1
fi
t1=$(date +%s%N | cut -b1-13)
ms=$((t1 - t0))
log "Build $benchmark time (ms): $ms"
echo
# Run
log "Run $benchmark"
t0=$(date +%s%N | cut -b1-13)
if ! ./$RUN_SCRIPT "$CPU_COUNT" "$BLOCK_SIZE" "$THREADS"
then
cd ..
log "RUN $benchmark FAILED"
return 1
fi
t1=$(date +%s%N | cut -b1-13)
ms=$((t1 - t0))
log "Run $benchmark time (ms): $ms"
cd ..
return 0
else
log "Can't change dir to $dir"
return 1
fi
else
log "No run scripts found in $dir"
return 1
fi
}
parse_param "$@"
shift $((OPTIND - 1))
if [ $# -gt 0 ]
then
benches="$*"
else
for b in $(sim_list); do benches="$benches$b "; done
fi
log "Soft-cores count: $CPU_COUNT"
log "Block size: $BLOCK_SIZE"
log "Threads count: $THREADS"
log "Benchmarks: $benches"
for bench in $benches
do
echo
run_benchmark "$bench"
done