blob: 3bff910f56a5d4982b87a6c74a582761e9534eb2 (
plain)
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
|
#!/bin/bash
#
# Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
# NOTE: Supposed that this script would be executed with an artifact path.
# The artifact path has tests/(test suite) and Product/
# Reference this PR(https://github.sec.samsung.net/STAR/nnfw/pull/375).
function Usage()
{
echo "Usage: ./$0 --artifactpath=. # run all tests"
echo "Usage: ./$0 --artifactpath=/home/dragon/nnfw --frameworktest --verification --benchmark # run fw test & verfication and benchmark"
echo ""
echo "--artifactpath - (should be passed) path that has tests/ and Product/"
echo ""
echo "Following three options are needed when you want to tests of specific types. If you don't pass any one, unittest and verification will be run"
echo "--unittest - (default=on) run unit test"
echo "--frameworktest - (default=off)run framework test"
echo "--verification - (default=on) run verification"
echo ""
echo "Following option is only needed when you want to test benchmark."
echo "--benchmark - (default=off) run benchmark"
echo "--benchmark_acl - (default=off) run benchmark-acl"
echo ""
echo "etc."
echo "--framework_driverbin - (default=../../Product/out/bin/tflite_run) runner for runnning framework tests"
echo "--verification_driverbin - (default=../../Product/out/bin/nnapi_test) runner for runnning verification tests"
echo "--benchmark_driverbin - (default=../../Product/out/bin/tflite_benchmark) runner for runnning benchmark"
echo "--runtestsh - (default=\$ARTIFACT_PATH/tests/framework/run_test.sh) run_test.sh with path where it is for framework test and verification"
echo "--unittestdir - (default=\$ARTIFACT_PATH/Product/out/unittest) directory that has unittest binaries for unit test"
echo ""
echo "--ldlibrarypath - (default=\$ARTIFACT_PATH/Product/out/lib) path that you want to include libraries"
echo "--usennapi - (default=on) declare USE_NNAPI=1"
echo "--nousennapi - (default=off) declare nothing about USE_NNAPI"
echo "--acl_envon - (default=off) declare envs for ACL"
echo ""
}
ARTIFACT_PATH=""
FRAMEWORK_DRIVER_BIN=""
VERIFICATION_DRIVER_BIN=""
BENCHMARK_DRIVER_BIN=""
RUN_TEST_SH=""
UNIT_TEST_DIR=""
LD_LIBRARY_PATH_IN_SHELL=""
USE_NNAPI="USE_NNAPI=1"
ALLTEST_ON="true"
UNITTEST_ON="false"
FRAMEWORKTEST_ON="false"
VERIFICATION_ON="false"
BENCHMARK_ON="false"
BENCHMARK_ACL_ON="false"
MODEL_LIST="inceptionv3/inception_nonslim inceptionv3/inception_slim"
ACL_ENV_ON="false"
for i in "$@"
do
case $i in
-h|--help|help)
Usage
exit 1
;;
--artifactpath=*)
ARTIFACT_PATH=${i#*=}
;;
--framework_driverbin=*)
FRAMEWORK_DRIVER_BIN=${i#*=}
;;
--verification_driverbin=*)
VERIFICATION_DRIVER_BIN=${i#*=}
;;
--benchmark_driverbin=*)
BENCHMARK_DRIVER_BIN=${i#*=}
;;
--runtestsh=*)
RUN_TEST_SH=${i#*=}
;;
--unittestdir=*)
UNIT_TEST_DIR=${i#*=}
;;
--ldlibrarypath=*)
LD_LIBRARY_PATH_IN_SHELL=${i#*=}
;;
--usennapi)
USE_NNAPI="USE_NNAPI=1"
;;
--nousennapi)
USE_NNAPI=""
;;
--unittest)
ALLTEST_ON="false"
UNITTEST_ON="true"
;;
--frameworktest)
ALLTEST_ON="false"
FRAMEWORKTEST_ON="true"
;;
--verification)
ALLTEST_ON="false"
VERIFICATION_ON="true"
;;
--benchmark)
ALLTEST_ON="false"
BENCHMARK_ON="true"
;;
--benchmark_acl)
ALLTEST_ON="false"
BENCHMARK_ACL_ON="true"
;;
--acl_envon)
ACL_ENV_ON="true"
;;
*)
# Be careful that others params are handled as $ARTIFACT_PATH
ARTIFACT_PATH="$i"
;;
esac
shift
done
if [ ! -e "$ARTIFACT_PATH" ]; then
echo "Pass on with proper ARTIFACT_PATH"
exit 1
fi
ARTIFACT_PATH="$(readlink -f $ARTIFACT_PATH)"
if [ -z "$RUN_TEST_SH" ]; then
RUN_TEST_SH=$ARTIFACT_PATH/tests/framework/run_test.sh
fi
if [ ! -e "$RUN_TEST_SH" ]; then
echo "Cannot find $RUN_TEST_SH"
exit 1
fi
if [ -z "$UNIT_TEST_DIR" ]; then
UNIT_TEST_DIR=$ARTIFACT_PATH/Product/out/unittest
fi
if [ -z "$LD_LIBRARY_PATH_IN_SHELL" ]; then
LD_LIBRARY_PATH="$ARTIFACT_PATH/Product/out/lib:$LD_LIBRARY_PATH"
else
LD_LIBRARY_PATH="$LD_LIBRARY_PATH_IN_SHELL:$LD_LIBRARY_PATH"
fi
# Set env
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
if [ -n "$USE_NNAPI" ]; then
export "$USE_NNAPI"
fi
function switch_nnfw_kernel_env()
{
local switch=$1 # "ON" or "OFF"
local mode=$2 # "acl" or "neon" or ""
local NNFW_KERNEL_ENV_FILE=$ARTIFACT_PATH/tools/test_driver/nnfw_kernel_env_list.txt
for ENV in $(cat $NNFW_KERNEL_ENV_FILE); do
if [[ "$switch" == "ON" ]]; then
export "$ENV=$mode"
else
unset "$ENV"
fi
done
}
if [ "$ACL_ENV_ON" == "true" ]; then
switch_nnfw_kernel_env "ON" "acl"
fi
# Run unittest in each part such as Runtime, ACL
if [ "$ALLTEST_ON" == "true" ] || [ "$UNITTEST_ON" == "true" ]; then
if [ ! -e "$ARTIFACT_PATH/report" ]; then
mkdir -p $ARTIFACT_PATH/report
fi
echo ""
echo "============================================"
echo "Unittest start"
echo "============================================"
num_unittest=0
for TEST_BIN in `ls $UNIT_TEST_DIR`; do
num_unittest=$((num_unittest+1))
echo "============================================"
echo "Starting set $num_unittest: $TEST_BIN..."
echo "============================================"
$UNIT_TEST_DIR/$TEST_BIN --gtest_output=xml:$ARTIFACT_PATH/report/$TEST_BIN.xml
echo "============================================"
echo "Finishing set $num_unittest: $TEST_BIN..."
echo "============================================"
done
echo "============================================"
echo "Completed total $num_unittest set of unittest"
echo "Unittest end"
echo "============================================"
fi
# Run tflite_run with various tflite models
if [ "$FRAMEWORKTEST_ON" == "true" ]; then
if [ -z "$FRAMEWORK_DRIVER_BIN" ]; then
FRAMEWORK_DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_run
fi
if [ ! -e "$ARTIFACT_PATH/report" ]; then
mkdir -p $ARTIFACT_PATH/report
fi
echo ""
echo "============================================"
echo "Framework Test with tflite_run..."
$RUN_TEST_SH --driverbin=$FRAMEWORK_DRIVER_BIN \
--reportdir=$ARTIFACT_PATH/report \
--tapname=framework_test.tap \
> $ARTIFACT_PATH/report/framework_test.log 2>&1
echo "============================================"
cat $ARTIFACT_PATH/report/framework_test.tap
echo "============================================"
echo ""
fi
# Run nnapi_test with various tflite models
if [ "$ALLTEST_ON" == "true" ] || [ "$VERIFICATION_ON" == "true" ]; then
if [ -z "$VERIFICATION_DRIVER_BIN" ]; then
VERIFICATION_DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/nnapi_test
fi
if [ ! -e "$ARTIFACT_PATH/report" ]; then
mkdir -p $ARTIFACT_PATH/report
fi
echo ""
echo "============================================"
echo "Verification with nnapi_test..."
$RUN_TEST_SH --driverbin=$VERIFICATION_DRIVER_BIN \
--reportdir=$ARTIFACT_PATH/report \
--tapname=verification.tap \
> $ARTIFACT_PATH/report/verification.log 2>&1
echo "============================================"
cat $ARTIFACT_PATH/report/verification.tap
echo "============================================"
echo ""
fi
# Benchmark test
function get_result_of_benchmark_test()
{
local RUN_TEST_SH=$1
local DRIVER_BIN=$2
local MODEL=$3
local LOG_FILE=$4
$RUN_TEST_SH --driverbin=$DRIVER_BIN $MODEL > $LOG_FILE 2>&1
local RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'`
echo "$RESULT"
}
function print_result_of_benchmark_test()
{
local NAME=$1
local RESULT=$2
local RESULT_FILE=$3
echo "$NAME $RESULT" > $RESULT_FILE
}
function run_benchmark_test()
{
local DRIVER_BIN=
local LOG_FILE=
local RESULT_FILE=
local RESULT=
local REPORT_MODEL_DIR=
if [ -z "$BENCHMARK_DRIVER_BIN" ]; then
DRIVER_BIN=$ARTIFACT_PATH/Product/out/bin/tflite_benchmark
else
DRIVER_BIN=$BENCHMARK_DRIVER_BIN
fi
export COUNT=5
echo "============================================"
local i=0
for MODEL in $MODEL_LIST; do
echo "Benchmark test with tflite_benchmark & `echo $MODEL`"
echo $MODEL >> $MODELS_FILE
REPORT_MODEL_DIR=$ARTIFACT_PATH/report/benchmark/$MODEL
mkdir -p $REPORT_MODEL_DIR
# TFLite+CPU
LOG_FILE=$REPORT_MODEL_DIR/tflite_cpu.txt
RESULT_FILE=$REPORT_MODEL_DIR/tflite_cpu.result
echo -n "TFLite + CPU................... "
unset USE_NNAPI
RESULT=$(get_result_of_benchmark_test $RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
echo "$RESULT ms"
print_result_of_benchmark_test "TFLite_CPU" $RESULT $RESULT_FILE
# TFLite+NNAPI(CPU fallback)
LOG_FILE=$REPORT_MODEL_DIR/tflite_nnapi_cpu.txt
RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnapi_cpu.result
echo -n "TFLite + NNAPI(CPU)............ "
export USE_NNAPI=1
RESULT=$(get_result_of_benchmark_test $RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
echo "$RESULT ms"
print_result_of_benchmark_test "TFLite_NNAPI_CPU" $RESULT $RESULT_FILE
# TFLite+NNAPI(ACL)
LOG_FILE=$REPORT_MODEL_DIR/tflite_nnapi_acl.txt
RESULT_FILE=$REPORT_MODEL_DIR/tflite_nnapi_acl.result
echo -n "TFLite + NNAPI(ACL)............ "
switch_nnfw_kernel_env "ON" "acl"
RESULT=$(get_result_of_benchmark_test $RUN_TEST_SH $DRIVER_BIN $MODEL $LOG_FILE)
echo "$RESULT ms"
print_result_of_benchmark_test "TFLite_NNAPI_ACL" $RESULT $RESULT_FILE
unset USE_NNAPI
switch_nnfw_kernel_env "OFF"
if [[ $i -ne $(echo $MODEL_LIST | wc -w)-1 ]]; then
echo ""
fi
i=$((i+1))
done
echo "============================================"
unset COUNT
}
function run_benchmark_acl()
{
local REPORT_DIR=$ARTIFACT_PATH/report/benchmark
local DRIVER_DIR=$ARTIFACT_PATH/Product/out/bin
local LOG_FILE=""
local RESULT_FILE=""
local RESULT=""
export COUNT=5
echo "============================================"
local i=0
for BENCHMARK_ACL_BIN in $(ls $DRIVER_DIR/benchmark_*); do
BENCHMARK_ACL_BIN_BASENAME=$(basename $BENCHMARK_ACL_BIN)
mkdir -p $REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME
echo "Benchmark/acl test by $BENCHMARK_ACL_BIN_BASENAME"
echo $BENCHMARK_ACL_BIN_BASENAME >> $MODELS_FILE
# ACL(NEON)
LOG_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_neon.txt
RESULT_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_neon.result
echo -n "ACL(NEON)...... "
$BENCHMARK_ACL_BIN 0 > $LOG_FILE 2>&1
RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'`
echo "$RESULT ms"
echo "ACL(NEON)" $RESULT > $RESULT_FILE
# ACL(OpenCL)
LOG_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_opencl.txt
RESULT_FILE=$REPORT_DIR/$BENCHMARK_ACL_BIN_BASENAME/acl_opencl.result
echo -n "ACL(OpenCL).... "
$BENCHMARK_ACL_BIN 1 > $LOG_FILE 2>&1
RESULT=`grep -E '^Mean:' $LOG_FILE | sed -e 's/ms//g' | awk '{print $2}'`
echo "$RESULT ms"
echo "ACL(OpenCL)" $RESULT > $RESULT_FILE
if [[ $i -ne $(ls $DRIVER_DIR/benchmark_* | wc -w)-1 ]]; then
echo ""
fi
i=$((i+1))
done
echo "============================================"
unset COUNT
}
if [ "$BENCHMARK_ON" == "true" ] || [ "$BENCHMARK_ACL_ON" == "true" ]; then
if [ ! -e "$ARTIFACT_PATH/report" ]; then
mkdir -p $ARTIFACT_PATH/report
fi
REPORT_MODEL_DIR=$ARTIFACT_PATH/report/benchmark
mkdir -p $REPORT_MODEL_DIR
MODELS_FILE=$ARTIFACT_PATH/report/benchmark/benchmark_models.txt
rm -f $MODELS_FILE
fi
# Run tflite_benchmark with Iv3_non_slim & Iv3_slim
if [ "$BENCHMARK_ON" == "true" ]; then
echo ""
run_benchmark_test
echo ""
fi
# Run benchmark/acl/benchmark_googlenet,mobilenet and inception_v3
if [ "$BENCHMARK_ACL_ON" == "true" ]; then
echo ""
run_benchmark_acl
echo ""
fi
# make json file
if [ "$BENCHMARK_ON" == "true" ] || [ "$BENCHMARK_ACL_ON" == "true" ]; then
# functions to fill json with benchmark results
source $ARTIFACT_PATH/tools/test_driver/print_to_json.sh
print_to_json
fi
|