-
Notifications
You must be signed in to change notification settings - Fork 7
/
runtest.sh
576 lines (492 loc) · 17.4 KB
/
runtest.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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
#!/bin/bash
# runtest.sh
# Author: Agner Fog
# Date created: 2019-06-02
# Last modified: 2022-07-26
#
# This script will compile and run a testbench for the C++ Vector Class Library
# Using a list of test cases.
#
# (c) Copyright 2019-2022 by Agner Fog.
# GNU General Public License 3.0 or later www.gnu.org/licenses
#
###############################################################################
#
# Instructions:
# ./runtest.sh listfile.lst
#
# Format for the list file:
# -------------------------
# General lines define a function or operator to test, and various parameters,
# separated by commas:
# 1. Test case (integer or range) indicating which function or operator to test
# 2. Vector type for parameters
# 3. Vector type for return value
# 4. Instruction set (2=SSE2, 3=SSE3, 4=SSSE3, 5=SSE4.1, 6=SSE4.2, 7=AVX,
# 8=AVX2+FMA, 9=AVX512F, 10=AVX512BW/DQ/VL, 11=AVX512VBMI2, 12=AVX512_FP16
# 5. Function name (only for permute etc.)
# 6. List of indexes for permute, blend and gather functions. Separated by '+'
# (will be converted to template parameters separated by ',')
#
# Ranges can be specified for the following parameters:
# 1. Test case: a range specified as values separated by spaces
# 2. Vector type: Multiple vector types separted by spaces
# 3. The type for return value cannot specify a range.
# Make it blank to get the same as the vector type for input parameters
# 4. Instruction set: a range specified as values separated by spaces
#
# Special lines:
# A line beginning with a dollar sign ($) specifies a parameter:
# $compiler= (1=Gnu, 2=Clang,
# 3=Intel compiler for Linux "classic", 4=Intel compiler for Linux, clang based
# 10=Microsoft compiler for Windows, 11=Intel compiler for Windows "classic")
# $mode= (32 for 32-bit mode, 64 for 64-bit mode)
# $testbench= (name and path of .cpp testbench file)
# $outfile= (name of output file)
# $include= (directory of .h include files. May be relative path)
# $emulator= (path and name of Intel emulator, to be called if instruction set not supported by current CPU)
# $compilermax= (maximum instruction set supported by the compiler. skip test cases with higher instruction set)
# $seed= (an integer for initializing random number generator)
#
# Comments begin with '#'
#
# The file must end with a blank line
###################################################################################################
# Extra compiler options may be inserted here:
extraoptions=""
# Extra source files or library files may be inserted here:
extrasource=""
# This fixes some bugs in gcc with testcase 5, Vec16c, instruction set 10:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65782
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89325
# Not needed in latest releases:
# gccextraoptions="-fno-asynchronous-unwind-tables -Wno-attributes"
# Default name for compiled file
exefilename="x"
# Uncomment this line if wrong operating system is detected:
# OSTYPE="cygwin"
# Detect operating system
if [[ $OSTYPE == "cygwin" || $OSTYPE == "msys" ]] ; then
os=1 # Windows/Cygwin/Msys-Mingw
gccextraoptions="-fno-asynchronous-unwind-tables -Wno-attributes" # workaround for cygwin problems
exefilename="xx.exe" # avoid same name as ELF exe file because they can be messed up
echo -e "Operating system is Windows\n\n"
elif [[ $OSTYPE == "linux-gnu" ]] ; then
os=2 # Linux, including Linux on Windows (WSL, Mingw-W64)
clangextraoptions="-lm"
echo -e "Operating system is Linux\n\n"
else
os=0 # other operating systems may be added here
echo -e "Operating system is Unknown\n\n"
fi
# Read file
filename=$1
if [ ! -e $filename ] ; then
echo Error: file $filename not found
exit 99
fi
# default name of output file is same as input file with extension (.lst) changed to .txt
outfile="${filename/\.[a-z]*/.txt}"
# statistics
starttime=`date +%s`
counttests=0
# Function to compile code with the specified options and run it
compileAndRun() {
exitcode=0
# vector type for return
rtype=${rtype// }
if [ -z "$rtype" ] ; then
rtype=$vtype
fi
# function name
if [[ ! -z "$funcname" ]] ; then
funcname=${funcname// /}
parf="-Dfuncname=$funcname"
else
parf=""
fi
# compiler parameters
parameters="-Dtestcase=$testcase $parf -Dvtype=$vtype -Drtype=$rtype -DINSTRSET=$instrset -Dseed=$seed"
# indexes for template functions
if [[ -z "$indexes" ]] ; then
parix=""
inx2=""
else
# remove spaces, replace '+' by ','
inx2=${indexes// /}
inx2=${inx2//\+/,} # this is not working if IFS=","
parix="-Dindexes=$inx2"
fi
# instruction set options
if [[ $instrset -lt 3 ]] ; then
isetoption=-msse2
elif [[ $instrset -eq 3 ]] ; then
isetoption=-msse3
elif [[ $instrset -eq 4 ]] ; then
isetoption=-mssse3
elif [[ $instrset -eq 5 ]] ; then
isetoption=-msse4.1
elif [[ $instrset -eq 6 ]] ; then
isetoption=-msse4.2
elif [[ $instrset -eq 7 ]] ; then
isetoption=-mavx
elif [[ $instrset -eq 8 ]] ; then
isetoption="-mfma -mavx2 -mf16c "
elif [[ $instrset -eq 9 ]] ; then
isetoption="-mfma -mavx512f -mf16c "
elif [[ $instrset -eq 10 ]] ; then
isetoption="-mfma -mavx512bw -mavx512dq -mavx512vl -mf16c "
elif [[ $instrset -eq 11 ]] ; then
isetoption="-mfma -mavx512bw -mavx512dq -mavx512vl -mf16c -mavx512vbmi -mavx512vbmi2 "
elif [[ $instrset -eq 12 ]] ; then
isetoption="-mfma -mavx512bw -mavx512dq -mavx512vl -mf16c -mavx512vbmi -mavx512vbmi2 -mavx512fp16 "
fi
# call compiler
if [ $compiler -eq 0 ] ; then
echo "Error: Compiler not specified" >> $outfile
exitcode=1
return 1
elif [ $compiler -eq 1 ] ; then
# Gnu compiler
echo "g++ $parameters $isetoption $options -I$include $gccextraoptions $parix $extraoptions $testbench $extrasource"
eval g++ $parameters $isetoption $options -I$include $gccextraoptions $parix $extraoptions $testbench $extrasource
elif [ $compiler -eq 2 ] ; then
# Clang compiler
echo "clang++ $parameters $options $isetoption -I$include $parix $extraoptions $clangextraoptions $testbench $extrasource "
eval clang++ $parameters $options $isetoption -I$include $parix $extraoptions $clangextraoptions $testbench $extrasource
elif [ $compiler -eq 3 ] ; then
# Intel compiler for Linux, legacy
echo "$parameters $options $isetoption -I$include $parix $extraoptions $testbench $extrasource"
eval icc $parameters $options $isetoption -I$include $parix $extraoptions $testbench $extrasource
elif [ $compiler -eq 4 ] ; then
# Intel compiler for Linux, clang based
echo "icpx $parameters $options $isetoption -I$include $testbench $parix $extraoptions $testbench $extrasource"
eval icpx $parameters $options $isetoption -I$include $testbench $parix $extraoptions $testbench $extrasource
elif [ $compiler -eq 10 ] ; then
# MS compiler
# instruction set options
if [[ $instrset -le 7 ]] ; then
isetoption=/arch:AVX
elif [[ $instrset -eq 8 ]] ; then
isetoption=/arch:AVX2
elif [[ $instrset -eq 9 ]] ; then
isetoption=/arch:AVX512
elif [[ $instrset -eq 10 ]] ; then
isetoption=/arch:AVX512
fi
parameters="/D testcase=$testcase /D vtype=$vtype /D rtype=$rtype /D INSTRSET=$instrset /D funcname=$funcname"
echo cl.exe "$options $parameters /I$include $testbench $isetoption /D indexes=$inx2 $extraoptions $testbench $extrasource"
eval cl.exe "$options $parameters /I$include $testbench $isetoption /D indexes=$inx2 $extraoptions $testbench $extrasource"
elif [ $compiler -eq 11 ] ; then
# Intel compiler for Windows
# instruction set options
if [[ $instrset -lt 3 ]] ; then
isetoption=/QxSSE2
elif [[ $instrset -eq 3 ]] ; then
isetoption=/QxSSE3
elif [[ $instrset -eq 4 ]] ; then
isetoption=/QxSSSE3
elif [[ $instrset -eq 5 ]] ; then
isetoption=/QxSSE4.1
elif [[ $instrset -eq 6 ]] ; then
isetoption=/QxSSE4.2
elif [[ $instrset -eq 7 ]] ; then
isetoption=/QxAVX
elif [[ $instrset -eq 8 ]] ; then
isetoption="/QxCORE-AVX2"
elif [[ $instrset -eq 9 ]] ; then
isetoption="/QxCOMMON-AVX512"
elif [[ $instrset -eq 10 ]] ; then
isetoption="/QxCORE-AVX512"
fi
parameters="/D testcase=$testcase /D vtype=$vtype /D rtype=$rtype /D INSTRSET=$instrset /D funcname=$funcname"
echo "icl $parameters $options -I$include $isetoption $parix $extraoptions $testbench $extrasource"
eval icl.exe $parameters $options -I$include $isetoption $parix $extraoptions $testbench $extrasource
else
echo "Error: Unknown compiler" >> $outfile
exitcode=1
return 1
fi
# test if compilation successful
if [ $? -ne 0 ] ; then
echo "*** Compiling failed\n" >> $outfile
exit 2 # exit
fi
# check if instruction set is supported
if [[ $instrset -gt $maxiset ]] ; then
if [ -e "$emulator" ] ; then
# emulate and run compiled program
$emulator -future -- ./$exefilename
else
echo "*** emulator $emulator not found\n"
echo "*** emulator $emulator not found\n" >> $outfile
exit 2 # exit
fi
else
# run compiled program
./$exefilename
fi
returncode=$?
if [[ $returncode -ne 0 ]] ; then
echo "*** Test failed\n" >> $outfile
exit 1 # exit
fi
}
# Function to set the compiler
setCompiler() {
compiler=$1 # set compiler variable
if [ $compiler -eq 1 ] ; then
# Gnu compiler
options="-m$mode -std=c++17 -O3 -fno-trapping-math -o$exefilename"
# -ffinite-math-only will spoil checks for nan and infinite
elif [ $compiler -eq 2 ] ; then
# Clang compiler
options="-m$mode -std=c++17 -O3 -fno-trapping-math -o$exefilename"
elif [ $compiler -eq 3 ] ; then
# Intel compiler for Linux, legacy ("classic")
options="-m$mode -std=c++17 -O3 -fno-trapping-math -fp-model precise -o$exefilename"
elif [ $compiler -eq 4 ] ; then
# Intel compiler for Linux, clang based
options="-m$mode -std=c++17 -O3 -fno-trapping-math -fp-model precise -o$exefilename"
elif [ $compiler -eq 10 ] ; then
# MS compiler for Windows VS2019
os=1
exefilename=xx.exe
options="/O2 /std:c++17 /Fe$exefilename /arch:AVX2"
elif [ $compiler -eq 11 ] ; then
# Intel compiler for Windows
os=1
options="/O3 /std:c++17 /Fe$exefilename /fp:precise"
exefilename=xx.exe
fi
}
getInstructionSet() {
# Find highest instruction set supported by current CPU
# compile get_instruction_set.cpp
if [ $compiler -eq 1 ] ; then
# Gnu compiler
eval g++ -msse2 -std=c++17 -I$include get_instruction_set.cpp -oiset$exefilename
g++ --version
g++ --version >> $outfile
elif [ $compiler -eq 2 ] ; then
# Clang compiler
eval clang -msse2 -std=c++17 -I$include get_instruction_set.cpp -oiset$exefilename
clang --version
clang --version >> $outfile
elif [ $compiler -eq 3 ] ; then
# Intel compiler for Linux, legacy
eval icc -std=c++17 -I$include get_instruction_set.cpp -oiset$exefilename
icc --version
icc --version >> $outfile
elif [ $compiler -eq 4 ] ; then
# Intel compiler for Linux, clang based
eval icpx -std=c++17 -I$include get_instruction_set.cpp -oiset$exefilename
icpx --version
icpx --version >> $outfile
elif [ $compiler -eq 10 ] ; then
# MS compiler for Windows
eval cl.exe -I$include /std:c++17 get_instruction_set.cpp /Fe:iset$exefilename
cl.exe
cl.exe >> $outfile
elif [ $compiler -eq 11 ] ; then
# Intel compiler for Windows
eval icl.exe -I$include /std:c++17 get_instruction_set.cpp /Fe:iset$exefilename
icl --version
icl --version >> $outfile
else
echo "Error: Unknown compiler"
exitcode=1
return 1
fi
if [ $? -ne 0 ] ; then
echo "Failed compiling get_instruction_set.cpp\n"
exit 2 # exit
fi
# run the compiled get_instruction_set.cpp to get the max instruction set
eval maxiset=`./iset$exefilename`
maxiset=`echo "$maxiset" | tr -d '\r\n'` # remove trailing line feed
if [ $? -ne 0 ] ; then
echo "Failed executing get_instruction_set.cpp\n"
exit 2 # exit
fi
echo -e "max instruction set: $maxiset\n"
}
startOutputFile() {
# Start writing output file
echo -e "Test of VCL on $testbench with $outfile \n" > "$outfile"
date +%Y-%m-%d:%H:%M:%S >> $outfile
echo -e "\n\n" >> $outfile
}
# Save system path
syspath=$PATH
# Initialize variables to default values
mode=64
testbench=testbench1.cpp
include=../src2
outfile=/dev/null
seed=0
compiler=0
maxiset=
setCompiler 1
############################################
# Loop through the lines of the input file:
############################################
oldIFS=$IFS
IFS=$'\n'
# The filename comes at the end of this loop
# (If you put it here with a pipe, the variables in the loop will be lost)
while read -r line0
do
# remove quotation marks and windows carriage return
line=`echo "$line0" | tr -d '\r"'`
# remove comments beginning with #
line=${line%%#*}
# skip blank lines
if [[ -z "${line//[ ,]}" ]] ; then continue ; fi
# detect special lines
if [ "${line:0:1}" = "$" ] ; then
# line begins with "$".
# remove commas
line1=${line//,/}
# Split by "="
IFS="="
spliteq=(${line1:1})
varname="${spliteq[0]}"
value="${spliteq[1]}"
varname=${varname// }
value=${value// }
#echo -e "varname:$varname value:$value \n"
if [[ $varname == "outfile" ]] ; then
# set name of new output file
if [[ $outfile != $value ]] ; then
outfile=$value
startOutputFile
fi
elif [[ $varname == "mode" ]] ; then
# set mode
mode=$value
if [ $mode -ne 32 -a $mode -ne 64 ] ; then
echo "Error: Wrong mode: $mode" >> $outfile
exit 1
fi
setCompiler "$compiler"
elif [[ $varname == "testbench" ]] ; then
# set testbench file
testbench=$value
elif [[ $varname == "include" ]] ; then
# set include directory
include=$value
elif [[ $varname == "compiler" ]] ; then
# set compiler
setCompiler $value
elif [[ $varname == "emulator" ]] ; then
# set emulator
emulator=$value
elif [[ $varname == "compilermax" ]] ; then
# set compilermax
compilermax=$value
elif [[ $varname == "seed" ]] ; then
# set compiler
seed=$value
else
echo "Error: Unknown parameter $varname" >> $outfile
fi
# reset field separator for read loop
IFS=$'\n'
continue
fi
# Check if outfile is started
if [ -z "$outfile" ] ; then
outfile="/dev/null"
# startOutputFile
fi
# Check if max instruction set has been detected
if [ -z "$maxiset" ] ; then
getInstructionSet
fi
# General comma-separated line
# Split by comma
IFS=","
splitline=($line)
# reset field separator for read loop
IFS=$'\n'
# get fields:
# 1. test case, integer or range, indicating which function or operator to test
# 2. vector type for parameters
# 3. vector type for return value
# 4. instruction set (2=SSE2, 3=SSE3, 4=SSSE3, 5=SSE4.1, 6=SSE4.2,
# 7=AVX, 8=AVX2+FMA, 9=AVX512F, 10=AVX512BW/DQ/VL
# 5. function name
# 6. indexes, separated by '+'
testcases=${splitline[0]}
vtypes=${splitline[1]}
rtypes=${splitline[2]}
instrsets=${splitline[3]}
funcname=${splitline[4]}
indexes=${splitline[5]}
# default values
if [ -z "$testcases" ] ; then
testcases=1
fi
if [ -z "$vtypes" ] ; then
vtypes=Vec8i
fi
if [ -z "$rtypes" ] ; then
rtypes="" # Will be set to vtype
fi
if [ -z "$instrsets" ] ; then
echo Error: Instruction set not specified, or a comma is missing
exit 98
fi
# make array of test cases
eval tcases=( $testcases )
numtcases=${#tcases[@]}
# make array of vector types
eval vcases=( $vtypes )
numvcases=${#vcases[@]}
# make array of instruction sets
eval icases=( $instrsets )
numicases=${#icases[@]}
# loops for parameter ranges
for testcase in "${tcases[@]}" ; do
if [ $numtcases -gt 1 ] ; then
echo -e "* Testcase $testcase\n" >> $outfile
fi
for vtype in "${vcases[@]}" ; do
if [ $numvcases -gt 1 ] ; then
echo -e "** Vector type $vtype\n" >> $outfile
fi
for instrset in "${icases[@]}" ; do
if [ $numicases -gt 1 ] ; then
echo -e "*** Instruction set $instrset\n" >> $outfile
fi
# parameters that can't have ranges
rtype="$rtypes"
# write to file
echo -e " test case $testcase $funcname, vector $vtype, instruction set $instrset, $testbench\n" >> $outfile
# compilermax
if [[ ! -z $compilermax ]] ; then
if [[ $instrset -gt $compilermax ]] ; then
echo -e "- skipped\n" >> $outfile
continue
fi
fi
# compile testbench and run it
compileAndRun
# count successes
counttests=$((counttests + 1))
done
done
done
IFS=$'\n'
done < $filename # end line loop
# reset field separator
IFS=$oldIFS
# statistics
endtime=`date +%s`
elapsedtime=$(($endtime - $starttime))
minutes=$(($elapsedtime/60))
seconds=$(($elapsedtime-($minutes*60)))
# output summary
echo -e "$counttests tests executed successfully in $minutes minutes $seconds seconds \n"
echo -e "$counttests tests executed successfully in $minutes minutes $seconds seconds \n" >> $outfile