This repository has been archived by the owner on May 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_benchmarks_parallelbash_pc.sh
executable file
·183 lines (162 loc) · 7.53 KB
/
run_benchmarks_parallelbash_pc.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
#!/usr/bin/env bash
# Copyright (c) 2018-2021, Texas Instruments
# All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##################################################################
# to run background jobs
set -m
#set -e
##################################################################
# target_device - use one of: TDA4VM AM62A AM68A AM69A
# (Note: until r8.5 only TDA4VM was supported)
TARGET_SOC=TDA4VM
# leave this as pc - no change needed
# pc: for model compilation and inference on PC, evm: for model inference on EVM
# after compilation, run_package_artifacts_evm.sh can be used to format and package the compiled artifacts for evm
TARGET_MACHINE=pc
# for parallel execution on pc only (cpu or gpu).
# number of parallel processes to run.
NUM_PARALLEL_PROCESSES=16
# for parallel execution on CUDA/GPU. if you don't have CUDA/gpu, these don't matter
# important note: to use CUDA/GPU, CUDA compiled TIDL (tidl_tools) is required.
NUM_PARALLEL_DEVICES=4
##################################################################
# for arg in "$@"
while(( "$#" ));
do
case "$1" in
"TDA4VM"|"AM68A"|"AM69A"|"AM62A"|"AM67A"|"AM62")
TARGET_SOC=$1
shift
;;
"--parallel_processes")
NUM_PARALLEL_PROCESSES=$2
shift 2
;;
"--parallel_devices")
NUM_PARALLEL_DEVICES=$2
shift 2
;;
"-h"|"--help")
cat << EOF
Usage: $0 [OPTIONS] [TARGET_SOC]
This script sets up the environment and runs benchmarking on x86 PC in parallel processes for a specified target device by calling the following:
./scripts/benchmark_custom.py
./scripts/generate_report.py
Options:
--parallel_processes=* Number of parallel processes to run. Defaults to 16.
(E.g., 8 means eight models will run in parallel,
1 means one model will run in a separate processs,
and null means one process will run in the same process as the main).
--devices=* Number of parallel devices (CUDA/GPU) to run on. If you don't have CUDA/gpu, this does not apply. Defaults to 4.
If you have GPUs these wil be used for CUDA_VISIBLE_DEVICES. E.g., specifying 4 will use the gpus: 0,1,2,3.
You can also specify a list with actual GPU ids instead of an integer: [0,1,2,3].
NOTE: to use CUDA/GPU, CUDA compiled TIDL (tidl_tools) is required.
-h, --help Display this help message and exit.
TARGET_SOC:
Specify the target device. Use one of: TDA4VM, AM62A, AM68A, AM69A. Defaults to TDA4VM.
Note: Until r8.5, only TDA4VM was supported.
Example:
$0 # defaults to TDA4VM
$0 AM62A # select device
$0 -p=10 # choose number of parallel processes
$0 --devices=2 # choose number of parallel devices
EOF
exit 0
;;
*) # Catch-all
shift
;;
esac
done
echo "TARGET_SOC: ${TARGET_SOC}"
echo "TARGET_MACHINE: ${TARGET_MACHINE}"
echo "NUM_PARALLEL_PROCESSES: ${NUM_PARALLEL_PROCESSES}"
echo "NUM_PARALLEL_DEVICES: ${NUM_PARALLEL_DEVICES}"
##################################################################
# set environment variables
# also point to the right type of artifacts (pc or evm)
source run_set_env.sh ${TARGET_SOC} ${TARGET_MACHINE}
# specify one of the following settings - options can be changed inside the yaml
#SETTINGS=settings_infer_on_evm.yaml
SETTINGS=settings_import_on_pc.yaml
##################################################################
echo "-------------------------------------------------------------------"
function f_num_running_jobs() {
n_jobs=$(jobs -r | wc -l)
echo $n_jobs
}
function f_list_running_jobs() {
proc_id_jobs=$(pgrep -P $$ -d " ")
echo $proc_id_jobs
}
function run_model() {
echo $@
python3 ./scripts/benchmark_modelzoo.py $@ --run_inference 0 && \
python3 ./scripts/benchmark_modelzoo.py $@ --run_import 0
}
echo "-------------------------------------------------------------------"
proc_id=$$
# run all the shortlisted models with these settings
MODELARTIFACTS_DIR="./work_dirs/modelartifacts"
MODELS_LIST="${MODELARTIFACTS_DIR}/benchmarks_models_list.txt"
mkdir -p ${MODELARTIFACTS_DIR}
python3 ./scripts/generate_models_list.py ${SETTINGS} --target_device ${TARGET_SOC} --models_list_file $MODELS_LIST --dataset_loading False ${@:2}
num_lines=$(wc -l < ${MODELS_LIST})
echo $num_lines
parallel_device=0
for model_id in $(cat ${MODELS_LIST}); do
while [ $(f_num_running_jobs) -ge $NUM_PARALLEL_PROCESSES ]; do
timestamp=$(date +'%Y%m%d-%H%M%S')
num_running_jobs=$(f_num_running_jobs)
echo -ne "\r\e[0K proc_id:$proc_id timestamp:$timestamp num_running_jobs:$num_running_jobs"
sleep 10
done
timestamp=$(date +'%Y%m%d-%H%M%S')
num_running_jobs=$(f_num_running_jobs)
parallel_device=$((parallel_device+1))
parallel_device=$((parallel_device%NUM_PARALLEL_DEVICES))
echo " "
echo " ==============================================================="
echo " proc_id:$proc_id timestamp:$timestamp num_running_jobs:$num_running_jobs running model_id:$model_id on parallel_device:$parallel_device"
# --parallel_processes 0 is used becuase we don't want to create another process inside.
# --parallel_devices null is used becuase CUDA_VISIBLE_DEVICES is set here itself - no need to be set inside again
CUDA_VISIBLE_DEVICES="$parallel_device" run_model "${SETTINGS}" --target_device "${TARGET_SOC}" --model_selection "${model_id}" --parallel_processes 0 --parallel_devices null ${@:2} &
sleep 1
echo " ==============================================================="
done
echo "-------------------------------------------------------------------"
while [ $(f_num_running_jobs) -ge 1 ]; do
timestamp=$(date +'%Y%m%d-%H%M%S')
num_running_jobs=$(f_num_running_jobs)
echo -ne "\r\e[0K proc_id:$proc_id timestamp:$timestamp num_running_jobs:$num_running_jobs"
sleep 10
done
echo "-------------------------------------------------------------------"
# generate the final report with results for all the artifacts generated
python3 ./scripts/generate_report.py ${SETTINGS}
echo "-------------------------------------------------------------------"