-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathrun_all_benchmarks.sh
404 lines (346 loc) · 13.4 KB
/
run_all_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
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
################################################################################
# Environment variable detection
if [ ! "${BENCHMARK}" ]; then
echo "BENCHMARK environment variable not set - assuming \"spmv\"" 1>&2
BENCHMARK="spmv"
fi
if [ ! "${DRY_RUN}" ]; then
echo "DRY_RUN environment variable not set - assuming \"false\"" 1>&2
DRY_RUN="false"
fi
if [ ! "${EXECUTOR}" ]; then
echo "EXECUTOR environment variable not set - assuming \"cuda\"" 1>&2
EXECUTOR="cuda"
fi
if [ ! "${SEGMENTS}" ]; then
echo "SEGMENTS environment variable not set - running entire suite" 1>&2
SEGMENTS=1
SEGMENT_ID=1
elif [ ! "${SEGMENT_ID}" ]; then
echo "SEGMENT_ID environment variable not set - exiting" 1>&2
exit 1
fi
if [ ! "${PRECONDS}" ]; then
echo "PRECONDS environment variable not set - assuming \"none\"" 1>&2
PRECONDS="none"
fi
if [ ! "${FORMATS}" ]; then
echo "FORMATS environment variable not set - assuming \"csr,coo,ell,hybrid,sellp\"" 1>&2
FORMATS="csr,coo,ell,hybrid,sellp"
fi
if [ ! "${SOLVERS}" ]; then
echo "SOLVERS environment variable not set - assuming \"bicgstab,cg,cgs,fcg,gmres,idr\"" 1>&2
SOLVERS="bicgstab,cg,cgs,fcg,gmres,idr"
fi
if [ ! "${SOLVERS_PRECISION}" ]; then
echo "SOLVERS_PRECISION environment variable not set - assuming \"1e-6\"" 1>&2
SOLVERS_PRECISION=1e-6
fi
if [ ! "${SOLVERS_MAX_ITERATIONS}" ]; then
echo "SOLVERS_MAX_ITERATIONS environment variable not set - assuming \"10000\"" 1>&2
SOLVERS_MAX_ITERATIONS=10000
fi
if [ ! "${SYSTEM_NAME}" ]; then
echo "SYSTEM_MANE environment variable not set - assuming \"unknown\"" 1>&2
SYSTEM_NAME="unknown"
fi
if [ ! "${DEVICE_ID}" ]; then
echo "DEVICE_ID environment variable not set - assuming \"0\"" 1>&2
DEVICE_ID="0"
fi
if [ ! "${SOLVERS_RHS}" ]; then
echo "SOLVERS_RHS environment variable not set - assuming \"unit\"" 1>&2
SOLVERS_RHS="unit"
fi
if [ "${SOLVERS_RHS}" == "random" ]; then
SOLVERS_RHS_FLAG="--random_rhs=true"
else
SOLVERS_RHS_FLAG="--random_rhs=false"
fi
if [ ! "${GPU_TIMER}" ]; then
echo "GPU_TIMER environment variable not set - assuming \"false\"" 1>&2
GPU_TIMER="false"
fi
# Control whether to run detailed benchmarks or not.
# Default setting is detailed=false. To activate, set DETAILED=1.
if [ ! "${DETAILED}" ] || [ "${DETAILED}" -eq 0 ]; then
DETAILED_STR="--detailed=false"
else
DETAILED_STR="--detailed=true"
fi
# This allows using a matrix list file for benchmarking.
# The file should contains a suitesparse matrix on each line.
# The allowed formats to target suitesparse matrix is:
# id or group/name or name.
# Example:
# 1903
# Freescale/circuit5M
# thermal2
if [ ! "${MATRIX_LIST_FILE}" ]; then
use_matrix_list_file=0
elif [ -f "${MATRIX_LIST_FILE}" ]; then
use_matrix_list_file=1
else
echo -e "A matrix list file was set to ${MATRIX_LIST_FILE} but it cannot be found."
exit 1
fi
################################################################################
# Utilities
# Checks the creation dates of a set of files $@, replaces file $1
# with the newest file from the set, and deletes the other
# files.
keep_latest() {
RESULT="$1"
for file in $@; do
if [ "${file}" -nt "${RESULT}" ]; then
RESULT="${file}"
fi
done
if [ "${RESULT}" != "$1" ]; then
cp "${RESULT}" "$1"
fi
for file in ${@:2}; do
rm -f "${file}"
done
}
# Computes matrix statistics of the problems described in file $1, and updates
# the file with results. Backups are created after each processed problem to
# prevent data loss in case of a crash. Once the extraction is completed, the
# backups and the results are combined, and the newest file is taken as the
# final result.
compute_matrix_statistics() {
[ "${DRY_RUN}" == "true" ] && return
cp "$1" "$1.imd" # make sure we're not loosing the original input
./matrix_statistics/matrix_statistics \
--backup="$1.bkp" --double_buffer="$1.bkp2" \
<"$1.imd" 2>&1 >"$1"
keep_latest "$1" "$1.bkp" "$1.bkp2" "$1.imd"
}
# Runs the conversion benchmarks for all matrix formats by using file $1 as the
# input, and updating it with the results. Backups are created after each
# benchmark run, to prevent data loss in case of a crash. Once the benchmarking
# is completed, the backups and the results are combined, and the newest file is
# taken as the final result.
run_conversion_benchmarks() {
[ "${DRY_RUN}" == "true" ] && return
cp "$1" "$1.imd" # make sure we're not loosing the original input
./conversions/conversions --backup="$1.bkp" --double_buffer="$1.bkp2" \
--executor="${EXECUTOR}" --formats="${FORMATS}" \
--device_id="${DEVICE_ID}" --gpu_timer=${GPU_TIMER} \
<"$1.imd" 2>&1 >"$1"
keep_latest "$1" "$1.bkp" "$1.bkp2" "$1.imd"
}
# Runs the SpMV benchmarks for all SpMV formats by using file $1 as the input,
# and updating it with the results. Backups are created after each
# benchmark run, to prevent data loss in case of a crash. Once the benchmarking
# is completed, the backups and the results are combined, and the newest file is
# taken as the final result.
run_spmv_benchmarks() {
[ "${DRY_RUN}" == "true" ] && return
cp "$1" "$1.imd" # make sure we're not loosing the original input
./spmv/spmv --backup="$1.bkp" --double_buffer="$1.bkp2" \
--executor="${EXECUTOR}" --formats="${FORMATS}" \
--device_id="${DEVICE_ID}" --gpu_timer=${GPU_TIMER} \
<"$1.imd" 2>&1 >"$1"
keep_latest "$1" "$1.bkp" "$1.bkp2" "$1.imd"
}
# Runs the solver benchmarks for all supported solvers by using file $1 as the
# input, and updating it with the results. Backups are created after each
# benchmark run, to prevent data loss in case of a crash. Once the benchmarking
# is completed, the backups and the results are combined, and the newest file is
# taken as the final result.
run_solver_benchmarks() {
[ "${DRY_RUN}" == "true" ] && return
cp "$1" "$1.imd" # make sure we're not loosing the original input
./solver/solver --backup="$1.bkp" --double_buffer="$1.bkp2" \
--executor="${EXECUTOR}" --solvers="${SOLVERS}" \
--preconditioners="${PRECONDS}" \
--max_iters=${SOLVERS_MAX_ITERATIONS} --rel_res_goal=${SOLVERS_PRECISION} \
${SOLVERS_RHS_FLAG} ${DETAILED_STR} --device_id="${DEVICE_ID}" --gpu_timer=${GPU_TIMER} \
<"$1.imd" 2>&1 >"$1"
keep_latest "$1" "$1.bkp" "$1.bkp2" "$1.imd"
}
# A list of block sizes that should be run for the block-Jacobi preconditioner
BLOCK_SIZES="$(seq 1 32)"
# A lis of precision reductions to run the block-Jacobi preconditioner for
PRECISIONS="0,0 0,1 0,2 1,0 1,1 2,0 autodetect"
# Runs the preconditioner benchmarks for all supported preconditioners by using
# file $1 as the input, and updating it with the results. Backups are created
# after each benchmark run, to prevent data loss in case of a crash. Once the
# benchmarking is completed, the backups and the results are combined, and the
# newest file is taken as the final result.
run_preconditioner_benchmarks() {
[ "${DRY_RUN}" == "true" ] && return
local bsize
for bsize in ${BLOCK_SIZES}; do
for prec in ${PRECISIONS}; do
echo -e "\t\t running jacobi ($prec) for block size ${bsize}" 1>&2
cp "$1" "$1.imd" # make sure we're not loosing the original input
./preconditioner/preconditioner \
--backup="$1.bkp" --double_buffer="$1.bkp2" \
--executor="${EXECUTOR}" --preconditioners="jacobi" \
--jacobi_max_block_size="${bsize}" \
--jacobi_storage="${prec}" \
--device_id="${DEVICE_ID}" --gpu_timer=${GPU_TIMER} \
<"$1.imd" 2>&1 >"$1"
keep_latest "$1" "$1.bkp" "$1.bkp2" "$1.imd"
done
done
}
################################################################################
# SuiteSparse collection
SSGET=ssget
NUM_PROBLEMS="$(${SSGET} -n)"
# Creates an input file for $1-th problem in the SuiteSparse collection
generate_suite_sparse_input() {
INPUT=$(${SSGET} -i "$1" -e)
cat << EOT
[{
"filename": "${INPUT}",
"problem": $(${SSGET} -i "$1" -j)
}]
EOT
}
parse_matrix_list() {
local source_list_file=$1
local benchmark_list=""
local id=0
for mtx in $(cat ${source_list_file}); do
if [[ ! "$mtx" =~ ^[0-9]+$ ]]; then
if [[ "$mtx" =~ ^[a-zA-Z0-9_-]+$ ]]; then
id=$(${SSGET} -s "[ @name == $mtx ]")
elif [[ "$mtx" =~ ^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_-]+)$ ]]; then
local group="${BASH_REMATCH[1]}"
local name="${BASH_REMATCH[2]}"
id=$(${SSGET} -s "[ @name == $name ] && [ @group == $group ]")
else
>&2 echo -e "Could not recognize entry $mtx."
fi
else
id=$mtx
fi
benchmark_list="$benchmark_list $id"
done
echo "$benchmark_list"
}
if [ $use_matrix_list_file -eq 1 ]; then
MATRIX_LIST=($(parse_matrix_list $MATRIX_LIST_FILE))
NUM_PROBLEMS=${#MATRIX_LIST[@]}
fi
LOOP_START=$((1 + (${NUM_PROBLEMS}) * (${SEGMENT_ID} - 1) / ${SEGMENTS}))
LOOP_END=$((1 + (${NUM_PROBLEMS}) * (${SEGMENT_ID}) / ${SEGMENTS}))
for (( p=${LOOP_START}; p < ${LOOP_END}; ++p )); do
if [ $use_matrix_list_file -eq 1 ]; then
i=${MATRIX_LIST[$((p-1))]}
else
i=$p
fi
if [ "${BENCHMARK}" == "preconditioner" ]; then
break
fi
if [ "$(${SSGET} -i "$i" -preal)" = "0" ]; then
[ "${DRY_RUN}" != "true" ] && ${SSGET} -i "$i" -c >/dev/null
continue
fi
RESULT_DIR="results/${SYSTEM_NAME}/${EXECUTOR}/SuiteSparse"
GROUP=$(${SSGET} -i "$i" -pgroup)
NAME=$(${SSGET} -i "$i" -pname)
RESULT_FILE="${RESULT_DIR}/${GROUP}/${NAME}.json"
PREFIX="($i/${NUM_PROBLEMS}):\t"
mkdir -p "$(dirname "${RESULT_FILE}")"
generate_suite_sparse_input "$i" >"${RESULT_FILE}"
echo -e "${PREFIX}Extracting statistics for ${GROUP}/${NAME}" 1>&2
compute_matrix_statistics "${RESULT_FILE}"
echo -e "${PREFIX}Running SpMV for ${GROUP}/${NAME}" 1>&2
run_spmv_benchmarks "${RESULT_FILE}"
if [ "${BENCHMARK}" == "conversions" ]; then
echo -e "${PREFIX}Running Conversion for ${GROUP}/${NAME}" 1>&2
run_conversion_benchmarks "${RESULT_FILE}"
fi
if [ "${BENCHMARK}" != "solver" -o \
"$(${SSGET} -i "$i" -prows)" != "$(${SSGET} -i "$i" -pcols)" ]; then
[ "${DRY_RUN}" != "true" ] && ${SSGET} -i "$i" -c >/dev/null
continue
fi
echo -e "${PREFIX}Running solvers for ${GROUP}/${NAME}" 1>&2
run_solver_benchmarks "${RESULT_FILE}"
echo -e "${PREFIX}Cleaning up problem ${GROUP}/${NAME}" 1>&2
[ "${DRY_RUN}" != "true" ] && ${SSGET} -i "$i" -c >/dev/null
done
if [ "${BENCHMARK}" != "preconditioner" ]; then
exit
fi
################################################################################
# Generated collection
count_tokens() { echo "$#"; }
BLOCK_SIZES="$(seq 1 32)"
NUM_BLOCKS="$(seq 10000 2000 50000)"
NUM_PROBLEMS=$((
$(count_tokens ${BLOCK_SIZES}) * $(count_tokens ${NUM_BLOCKS}) ))
ID=0
# Creates an input file for a block diagonal matrix with block size $1 and
# number of blocks $2. The location of the matrix is given by $3.
generate_block_diagonal_input() {
cat << EOT
[{
"filename": "$3",
"problem": {
"collection": "generated",
"group": "block-diagonal",
"name": "$2-$1",
"type": "block-diagonal",
"real": true,
"binary": false,
"2d3d": false,
"posdef": false,
"psym": 1,
"nsym": 0,
"kind": "artificially generated problem",
"num_blocks": $2,
"block_size": $1
}
}]
EOT
}
# Generates the problem data using the input file $1
generate_problem() {
[ "${DRY_RUN}" == "true" ] && return
cp "$1" "$1.tmp"
./matrix_generator/matrix_generator <"$1.tmp" 2>&1 >"$1"
keep_latest "$1" "$1.tmp"
}
LOOP_START=$((1 + (${NUM_PROBLEMS}) * (${SEGMENT_ID} - 1) / ${SEGMENTS}))
LOOP_END=$((1 + (${NUM_PROBLEMS}) * (${SEGMENT_ID}) / ${SEGMENTS}))
for bsize in ${BLOCK_SIZES}; do
for nblocks in ${NUM_BLOCKS}; do
ID=$((${ID} + 1))
if [ "${ID}" -ge "${LOOP_END}" ]; then
break
fi
if [ "${ID}" -lt "${LOOP_START}" ]; then
continue
fi
RESULT_DIR="results/${SYSTEM_NAME}/${EXECUTOR}/Generated"
GROUP="block-diagonal"
NAME="${nblocks}-${bsize}"
RESULT_FILE="${RESULT_DIR}/${GROUP}/${NAME}.json"
PREFIX="(${ID}/${NUM_PROBLEMS}):\t"
mkdir -p "$(dirname "${RESULT_FILE}")"
mkdir -p "/tmp/${GROUP}"
generate_block_diagonal_input \
"${bsize}" "${nblocks}" "/tmp/${GROUP}/${NAME}.mtx" \
>"${RESULT_FILE}"
echo -e "${PREFIX}Generating problem ${GROUP}/${NAME}" 1>&2
generate_problem "${RESULT_FILE}"
echo -e "${PREFIX}Extracting statistics for ${GROUP}/${NAME}" 1>&2
compute_matrix_statistics "${RESULT_FILE}"
echo -e "${PREFIX}Running preconditioners for ${GROUP}/${NAME}" 1>&2
BLOCK_SIZES="${bsize}"
run_preconditioner_benchmarks "${RESULT_FILE}"
echo -e "${PREFIX}Cleaning up problem ${GROUP}/${NAME}" 1>&2
[ "${DRY_RUN}" != "true" ] && rm -r "/tmp/${GROUP}/${NAME}.mtx"
done
if [ "${ID}" -ge "${LOOP_END}" ]; then
break
fi
done