summaryrefslogtreecommitdiff
path: root/tests/scripts/benchmark_nnpkg.sh
blob: 52043f458cc05881544da540df026de57422a506 (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
#!/bin/bash

usage()
{
  echo "$0 <options>"
  echo "Options"
  echo "--nnpackage_run : specific nnpackage_run path"
  echo "--tflite_run : specific tflite_run path"
  echo "--dir : the dir path of models"
  echo "--list : the model list"
  echo "--out  : the file name of out results"
  echo "--tv   : for tv"
  exit 1
}

scripts_dir="$( cd "$( dirname "${BASH_SOURCE}" )" && pwd )"
nnfw_dir="${scripts_dir}/../.."
nnpackage_run="${nnfw_dir}/Product/out/bin/nnpackage_run"
tflite_run="${nnfw_dir}/Product/out/bin/tflite_run"
base_name="$(basename $0)"
base_name="${base_name%.*}"
outfile="${base_name}_result.txt"
dir=""
list="${scripts_dir}/list/${base_name}_model_list.txt"
tv_on="false"

for i in "$@"
do
case $i in
  --nnpackage_run=*)
    nnpackage_run="${i#*=}"
    ;;
  --tflite_run=*)
    tflite_run="${i#*=}"
    ;;
  --out=*)
    outfile="${i#*=}"
    ;;
  --dir=*)
    dir="${i#*=}"
    ;;
  --list=*)
    list="${i#*=}"
    ;;
  --tv)
    tv_on="true"
    ;;
  *)
    ;;
esac
shift
done

if ! [ -f ${nnpackage_run} ]; then
  echo "nnpackage_run file does not exists."
  usage
fi

if ! [ -f ${tflite_run} ]; then
  echo "tflite_run file does not exists."
  usage
fi

if ! [ -f ${list} ]; then
  echo "model list file does not exists."
  usage
fi

if [ -z ${dir} ]; then
  echo "dir is empty."
  usage
fi

if ! [ -d ${dir} ]; then
  echo "dir does not exists."
  usage
fi

if [ -z ${outfile} ]; then
  echo "outfile is empty."
  usage
fi

if ! [ -f ${outfile} ]; then
  touch ${outfile}
fi

# get lists
model_lists=()
for model_name in `cat $list`; do
  model_lists+=($model_name)
done

# run
for i in "${model_lists[@]}"; do
  echo "${i} result" | tee -a ${outfile}

  CMD="${nnpackage_run} -r 10 -m 1 -p 1"
  if [ "$tv_on" == "true" ]; then
    ${CMD}="${CMD} -g 1"
  fi
  CMD="${CMD} ${dir}/${i} 2>&1 >> ${outfile}"

  # cpu
  CPU_CMD="BACKENDS=cpu ${CMD}"
  echo "${CPU_CMD}"
  echo "" >> ${outfile}
  echo "onert cpu" >> ${outfile}
  eval "${CPU_CMD}"

  sleep 10 # for avoiding cpu overheated

  # acl_neon
  NEON_CMD="BACKENDS=acl_neon ${CMD}"
  echo "${NEON_CMD}"
  echo "" >> ${outfile}
  echo "onert acl_neon" >> ${outfile}
  eval "${NEON_CMD}"

  sleep 10 # for avoiding cpu overheated

  # acl_cl
  CL_CMD="BACKENDS=acl_cl ${CMD}"
  echo "${CL_CMD}"
  echo "" >> ${outfile}
  echo "onert acl_cl" >> ${outfile}
  eval "${CL_CMD}"

  echo "" >> ${outfile}

  TFLITE_CMD="LD_LIBRARY_PATH=./Product/out/lib THREAD=3 ${tflite_run} -r 10 -m 1 -p 1" 
  if [ "$tv_on" == "true" ]; then
    TFLITE_CMD="${TFLITE_CMD} -g 1"
  fi
  TFLITE_CMD="${TFLITE_CMD} ${dir}/${i}/${i}.tflite >> ${outfile}"

  echo "TfLite + CPU" >> ${outfile}
  echo "${TFLITE_CMD}"
  eval "${TFLITE_CMD}"

  echo "" >> ${outfile}

  sleep 20 # for avoiding cpu overheated
done # ${model_lists}

${scripts_dir}/merge_result_of_benchmark_nnpkg.py -i . -o . -l ${list}