forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·295 lines (255 loc) · 8.57 KB
/
setup.sh
File metadata and controls
executable file
·295 lines (255 loc) · 8.57 KB
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
#!/usr/bin/env bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# Copyright 2023-2025 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
set -u
########################
### Hardcoded constants
########################
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
et_dir=$(realpath $script_dir/../..)
ARCH="$(uname -m)"
OS="$(uname -s)"
root_dir="${script_dir}/ethos-u-scratch" # TODO: rename
eula_acceptance=0
enable_baremetal_toolchain=1
target_toolchain=""
enable_fvps=1
enable_vela=1
enable_model_converter=0 # model-converter tool for VGF output
enable_vgf_lib=0 # vgf reader - runtime backend dependency
enable_emulation_layer=0 # Vulkan layer driver - emulates Vulkan ML extensions
enable_vulkan_sdk=0 # Download and export Vulkan SDK required by emulation layer
mlsdk_manifest_url="https://github.com/arm/ai-ml-sdk-manifest.git"
# Figure out if setup.sh was called or sourced and save it into "is_script_sourced"
(return 0 2>/dev/null) && is_script_sourced=1 || is_script_sourced=0
# Global scope these so they can be set later
toolchain_url=""
toolchain_dir=""
toolchain_md5_checksum=""
# List of supported options and their descriptions
OPTION_LIST=(
"--i-agree-to-the-contained-eula (required) Agree to the EULA"
"--root-dir Path to scratch directory"
"--enable-baremetal-toolchain Enable baremetal toolchain setup"
"--enable-fvps Enable FVP setup"
"--enable-vela Enable VELA setup"
"--enable-model-converter Enable MLSDK model converter setup"
"--enable-vgf-lib Enable MLSDK vgf library setup"
"--enable-emulation-layer Enable MLSDK Vulkan emulation layer"
"--disable-ethos-u-deps Do not setup what is needed for Ethos-U"
"--enable-mlsdk-deps Setup what is needed for MLSDK"
"--mlsdk-manifest-url URL to the MLSDK manifest for vulkan."
"--help Display help"
)
########
### Functions
########
function print_usage() {
echo "Usage: $(basename "$0") [OPTIONS]"
echo
echo "Available options:"
for entry in "${OPTION_LIST[@]}"; do
opt="${entry%% *}"
desc="${entry#* }"
printf " %-40s %s\n" "$opt" "$desc"
done
echo
echo "Supplied args: $*"
}
function check_options() {
while [[ "${#}" -gt 0 ]]; do
case "$1" in
--i-agree-to-the-contained-eula)
eula_acceptance=1
shift
;;
--root-dir)
# Only change default root dir if the script is being executed and not sourced.
if [[ $is_script_sourced -eq 0 ]]; then
root_dir=${2:-"${root_dir}"}
fi
if [[ $# -ge 2 ]]; then
shift 2
else
print_usage "$@"
exit 1
fi
;;
--enable-baremetal-toolchain)
enable_baremetal_toolchain=1
shift
;;
--target-toolchain)
# Only change default root dir if the script is being executed and not sourced.
if [[ $is_script_sourced -eq 0 ]]; then
target_toolchain=${2:-"${target_toolchain}"}
fi
if [[ $# -ge 2 ]]; then
shift 2
else
print_usage "$@"
exit 1
fi
;;
--enable-fvps)
enable_fvps=1
shift
;;
--enable-vela)
enable_vela=1
shift
;;
--enable-model-converter)
enable_model_converter=1
shift
;;
--enable-vgf-lib)
enable_vgf_lib=1
shift
;;
--enable-emulation-layer)
enable_emulation_layer=1
shift
;;
--enable-vulkan-sdk)
enable_vulkan_sdk=1
shift
;;
--disable-ethos-u-deps)
enable_baremetal_toolchain=0
enable_fvps=0
enable_vela=0
shift
;;
--enable-mlsdk-deps)
enable_model_converter=1
enable_vgf_lib=1
enable_emulation_layer=1
enable_vulkan_sdk=1
shift
;;
--mlsdk-manifest-url)
# Ensure that there is a url provided.
if [[ -n "$2" && "${2:0:1}" != "-" ]]; then
mlsdk_manifest_url="$2"
shift 2
else
echo "Error: --mlsdk-manifest-url requires a URL argument."
print_usage "$@"
exit 1
fi
;;
--setup-test-dependency)
echo "Installing test dependency..."
source $et_dir/backends/arm/scripts/install_models_for_test.sh
exit 0
;;
--help)
print_usage "$@"
exit 0
;;
*)
print_usage "$@"
exit 1
;;
esac
done
}
function setup_root_dir() {
mkdir -p ${root_dir}
root_dir=$(realpath ${root_dir})
setup_path_script="${root_dir}/setup_path"
}
function setup_ethos_u_tools() {
CMAKE_POLICY_VERSION_MINIMUM=3.5 BUILD_PYBIND=1 pip install --no-dependencies -r $et_dir/backends/arm/requirements-arm-ethos-u.txt
}
function create_setup_path(){
cd "${root_dir}"
clear_setup_path
if [[ "${enable_fvps}" -eq 1 ]]; then
setup_path_fvp
fi
if [[ "${enable_baremetal_toolchain}" -eq 1 ]]; then
setup_path_toolchain
fi
if [[ "${enable_vulkan_sdk}" -eq 1 ]]; then
setup_path_vulkan
fi
if [[ "${enable_model_converter}" -eq 1 ]]; then
setup_path_model_converter
fi
if [[ "${enable_vgf_lib}" -eq 1 ]]; then
setup_path_vgf_lib
fi
if [[ "${enable_emulation_layer}" -eq 1 ]]; then
setup_path_emulation_layer
fi
echo "[main] Update path by running 'source ${setup_path_script}.sh'"
echo "[main] Or for fish shell use 'source ${setup_path_script}.fish'"
}
########
### main
########
# script is not sourced! Lets run "main"
if [[ $is_script_sourced -eq 0 ]]; then
set -e
check_options "$@"
# Import utils
source $et_dir/backends/arm/scripts/utils.sh
source $et_dir/backends/arm/scripts/fvp_utils.sh
source $et_dir/backends/arm/scripts/toolchain_utils.sh
source $et_dir/backends/arm/scripts/vulkan_utils.sh
echo "[main]: Checking platform and os"
check_platform_support
check_os_support
cd "${script_dir}"
# Setup the root dir
setup_root_dir
cd "${root_dir}"
echo "[main] Using root dir ${root_dir} and options:"
echo "enable-fvps=${enable_fvps}"
echo "target-toolchain=${target_toolchain}"
echo "enable-baremetal-toolchain=${enable_baremetal_toolchain}"
echo "enable-model-converter=${enable_model_converter}"
echo "enable-vgf-lib=${enable_vgf_lib}"
echo "enable-emulation-layer=${enable_emulation_layer}"
echo "enable-vulkan-sdk=${enable_vulkan_sdk}"
echo "enable-vela=${enable_vela}"
echo "mlsdk-manifest-url=${mlsdk_manifest_url}"
# Setup toolchain
if [[ "${enable_baremetal_toolchain}" -eq 1 ]]; then
# Select appropriate toolchain
select_toolchain
setup_toolchain
fi
# Setup FVP
if [[ "${enable_fvps}" -eq 1 ]]; then
check_fvp_eula
setup_fvp
install_fvp
fi
# Setup Vulkan SDK
if [[ "${enable_vulkan_sdk}" -eq 1 ]]; then
setup_vulkan_sdk
fi
if [[ "${enable_model_converter}" -eq 1 || \
"${enable_vgf_lib}" -eq 1 || \
"${enable_emulation_layer}" -eq 1 ]]; then
source $et_dir/backends/arm/scripts/mlsdk_utils.sh -u "${mlsdk_manifest_url}"
setup_model_converter ${root_dir} ${mlsdk_manifest_dir} ${enable_model_converter} ${enable_vgf_lib} ${enable_emulation_layer}
fi
# Create the setup_path.sh used to create the PATH variable for shell
create_setup_path
# Setup the tosa_reference_model and dependencies
CMAKE_POLICY_VERSION_MINIMUM=3.5 BUILD_PYBIND=1 pip install --no-dependencies -r $et_dir/backends/arm/requirements-arm-tosa.txt
if [[ "${enable_vela}" -eq 1 ]]; then
setup_ethos_u_tools
fi
echo "[main] success!"
exit 0
fi