3 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
19 DRIVER_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23 echo "Optimize circle model."
24 echo "Usage: one-optimize"
25 echo " --all Enable all optimization algorithms"
26 echo " --fuse_bcq Enable FuseBCQ Pass"
27 echo " --fuse_instnorm Enable FuseInstanceNormalization Pass"
28 echo " --resolve_customop_add"
29 echo " Enable ResolveCustomOpAddPass Pass"
30 echo " --resolve_customop_batchmatmul"
31 echo " Enable ResolveCustomOpBatchMatMulPass Pass"
32 echo " --resolve_customop_matmul"
33 echo " Enable ResolveCustomOpMatMulPass Pass"
34 echo " --input_path <path/to/input/circle>"
35 echo " --output_path <path/to/output/circle>"
41 OPTIMIZE_fuse_instnorm=0
42 OPTIMIZE_resolve_customop_add=0
43 OPTIMIZE_resolve_customop_batchmatmul=0
44 OPTIMIZE_resolve_customop_matmul=0
46 # Parse command-line arguments
48 while [ "$#" -ne 0 ]; do
64 OPTIMIZE_fuse_instnorm=1
67 '--resolve_customop_add')
68 OPTIMIZE_resolve_customop_add=1
71 '--resolve_customop_batchmatmul')
72 OPTIMIZE_resolve_customop_batchmatmul=1
75 '--resolve_customop_matmul')
76 OPTIMIZE_resolve_customop_matmul=1
81 export INPUT_PATH="$2"
85 export OUTPUT_PATH="$2"
89 echo "Unknown parameter: ${CUR}"
95 if [ -z ${INPUT_PATH} ] || [ ! -e ${INPUT_PATH} ]; then
96 echo "Error: input model not found"
104 if [ $OPTIMIZE_all == 1 ]; then
105 OPTIMIZE_OPTIONS+="--all "
107 if [ $OPTIMIZE_fuse_bcq == 1 ]; then
108 OPTIMIZE_OPTIONS+="--fuse_bcq "
110 if [ $OPTIMIZE_fuse_instnorm == 1 ]; then
111 OPTIMIZE_OPTIONS+="--fuse_instnorm "
113 if [ $OPTIMIZE_resolve_customop_add == 1 ]; then
114 OPTIMIZE_OPTIONS+="--resolve_customop_add "
116 if [ $OPTIMIZE_resolve_customop_batchmatmul == 1 ]; then
117 OPTIMIZE_OPTIONS+="--resolve_customop_batchmatmul "
119 if [ $OPTIMIZE_resolve_customop_matmul == 1 ]; then
120 OPTIMIZE_OPTIONS+="--resolve_customop_matmul "
123 # remove previous log
124 rm -rf "${OUTPUT_PATH}.log"
126 # NOTE do not wrap ${OPTIMIZE_OPTIONS} with ""
128 echo "${DRIVER_PATH}/circle2circle" ${OPTIMIZE_OPTIONS} \
129 "${INPUT_PATH}" "${OUTPUT_PATH}" > "${OUTPUT_PATH}.log"
131 "${DRIVER_PATH}/circle2circle" ${OPTIMIZE_OPTIONS} \
132 "${INPUT_PATH}" "${OUTPUT_PATH}" >> "${OUTPUT_PATH}.log" 2>&1