Skip to content

Commit 2bd96df

Browse files
YufengShi-dudumansnilsrobellArmRyan
authored
Arm backend: Add model-converter and other mlsdk package download option (#12397)
- Disable mlsdk setup by default because the manifest repo is not yet public. - To enable mlsdk dependencies, an mlsdk_manifest_url needs to be supplied. This setup is currently intended for internal development only. Signed-off-by: Yufeng Shi <[email protected]> Co-authored-by: Måns Nilsson <[email protected]> Co-authored-by: Rob Elliott <[email protected]> Co-authored-by: Ryan O'Shea <[email protected]>
1 parent 78063df commit 2bd96df

File tree

2 files changed

+249
-21
lines changed

2 files changed

+249
-21
lines changed

backends/arm/scripts/mlsdk_utils.sh

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
set -euo pipefail
8+
9+
# TODO
10+
mlsdk_manifest_url=""
11+
12+
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
13+
14+
source ${script_dir}/utils.sh
15+
16+
usage() { echo "Usage: $0 [-u <mlsdk-manifest-url>]" 1>&2; exit 1; }
17+
18+
while getopts ":u:" opt; do
19+
case "${opt}" in
20+
u)
21+
mlsdk_manifest_url=${OPTARG}
22+
;;
23+
*)
24+
usage
25+
;;
26+
esac
27+
done
28+
29+
function download_ai_mlsdk_manifest() {
30+
local _dada_dir="$1"
31+
32+
if [[ -z "${_dada_dir}" ]]; then
33+
echo "Error: _dada_dir parameter missing?"
34+
return 1
35+
fi
36+
37+
if [[ -z "${mlsdk_manifest_url}" ]]; then
38+
echo "Error: mlsdk_manifest_url parameter missing?"
39+
return 1
40+
fi
41+
42+
if [[ ! -d "${_dada_dir}" ]]; then
43+
mkdir -p "$_dada_dir"
44+
pushd "$_dada_dir" || exit 1
45+
46+
curl https://storage.googleapis.com/git-repo-downloads/repo > repo
47+
chmod u+x repo
48+
./repo init --no-repo-verify --depth=1 --manifest-url ${mlsdk_manifest_url} -g model-converter,emulation-layer,vgf-library
49+
./repo sync
50+
51+
popd
52+
fi
53+
}
54+
55+
function setup_model_converter() {
56+
local work_dir="$1"
57+
local manifest_dir="$2"
58+
local enable_vgf_lib="$3"
59+
local enable_emulation_layer="$4"
60+
61+
if [[ -z "$work_dir" ]]; then
62+
echo "Error: work_dir parameter is required."
63+
return 1
64+
fi
65+
66+
if [[ -z "$manifest_dir" ]]; then
67+
echo "Error: manifest_dir parameter is required."
68+
return 1
69+
fi
70+
71+
mkdir -p "$work_dir"
72+
pushd "$work_dir" || exit 1
73+
74+
download_ai_mlsdk_manifest ${manifest_dir}
75+
76+
pushd "$manifest_dir"
77+
78+
# model-converter
79+
# TODO: Remove macOS patch after mlsdk fully supports macOS
80+
if [[ "$(uname)" == "Darwin" ]]; then
81+
sed -i '' '/^ *print(f"Unsupported host platform/ i\
82+
if system == "Darwin":\
83+
# Use default Apple toolchain (Clang) on macOS\
84+
return True\
85+
\
86+
' sw/model-converter/scripts/build.py
87+
fi
88+
python sw/model-converter/scripts/build.py -j$(nproc)
89+
90+
# libvgf
91+
if [[ "${enable_vgf_lib}" -eq 1 ]]; then
92+
# TODO: Remove macOS patch after mlsdk fully supports macOS
93+
if [[ "$(uname)" == "Darwin" ]]; then
94+
sed -i '' '/^ *print(f"ERROR: Unsupported host platform/ i\
95+
if system == "Darwin":\
96+
# Use default Apple toolchain (Clang) on macOS\
97+
return True\
98+
\
99+
' sw/vgf-lib/scripts/build.py
100+
fi
101+
python sw/vgf-lib/scripts/build.py -j$(nproc)
102+
fi
103+
104+
# emu layer
105+
if [[ "${enable_emulation_layer}" -eq 1 ]]; then
106+
pushd sw/emulation-layer
107+
cmake -B build \
108+
-DGLSLANG_PATH=../../dependencies/glslang \
109+
-DSPIRV_CROSS_PATH=../../dependencies/SPIRV-Cross \
110+
-DSPIRV_HEADERS_PATH=../../dependencies/SPIRV-Headers \
111+
-DSPIRV_TOOLS_PATH=../../dependencies/SPIRV-Tools \
112+
-DVULKAN_HEADERS_PATH=../../dependencies/Vulkan-Headers
113+
cmake --build build
114+
popd
115+
fi
116+
117+
popd
118+
}
119+
120+
#setup_model_converter() $1
121+
# `"$manifest_dir"'

examples/arm/setup.sh

Lines changed: 128 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
1616
et_dir=$(realpath $script_dir/../..)
1717
ARCH="$(uname -m)"
1818
OS="$(uname -s)"
19-
root_dir="${script_dir}/ethos-u-scratch"
19+
root_dir="${script_dir}/ethos-u-scratch" # TODO: rename
2020
eula_acceptance=0
21-
skip_toolchain_setup=0
21+
enable_baremetal_toolchain=1
2222
target_toolchain=""
23-
skip_fvp_setup=0
24-
skip_vela_setup=0
23+
enable_fvps=1
24+
enable_vela=1
25+
enable_model_converter=0 # model-converter tool for VGF output
26+
enable_vgf_lib=0 # vgf reader - runtime backend dependency
27+
enable_emulation_layer=0 # Vulkan layer driver - emulates Vulkan ML extensions
28+
mlsdk_manifest_url=""
2529

2630

2731
# Figure out if setup.sh was called or sourced and save it into "is_script_sourced"
@@ -54,16 +58,44 @@ else
5458
echo "[main] Error: only x86-64 & aarch64/arm64 architecture is supported for now!"; exit 1;
5559
fi
5660

57-
# vela
61+
# Vela
5862
vela_repo_url="https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela"
5963
vela_rev="8cac2b9a7204b57125a8718049519b091a98846c"
6064

65+
# MLSDK dependencies
66+
mlsdk_manifest_dir="ml-sdk-for-vulkan-manifest"
67+
68+
# List of supported options and their descriptions
69+
OPTION_LIST=(
70+
"--i-agree-to-the-contained-eula (required) Agree to the EULA"
71+
"--root-dir Path to scratch directory"
72+
"--enable-baremetal-toolchain Enable baremetal toolchain setup"
73+
"--enable-fvps Enable FVP setup"
74+
"--enable-vela Enable VELA setup"
75+
"--enable-model-converter Enable MLSDK model converter setup"
76+
"--enable-vgf-lib Enable MLSDK vgf library setup"
77+
"--enable-emulation-layer Enable MLSDK Vulkan emulation layer"
78+
"--disable-ethos-u-deps Do not setup what is needed for Ethos-U"
79+
"--enable-mlsdk-deps Setup what is needed for MLSDK"
80+
"--mlsdk-manifest-url URL to the MLSDK manifest for vulkan."
81+
"--help Display help"
82+
)
83+
84+
6185
########
6286
### Functions
6387
########
6488

6589
function print_usage() {
66-
echo "Usage: $(basename $0) <--i-agree-to-the-contained-eula> [--root-dir path-to-a-scratch-dir] [--target-toolchain toolchain name] [--skip-fvp-setup] [--skip-toolchain-setup] [--skip-vela-setup]"
90+
echo "Usage: $(basename "$0") [OPTIONS]"
91+
echo
92+
echo "Available options:"
93+
for entry in "${OPTION_LIST[@]}"; do
94+
opt="${entry%% *}"
95+
desc="${entry#* }"
96+
printf " %-40s %s\n" "$opt" "$desc"
97+
done
98+
echo
6799
echo "Supplied args: $*"
68100
}
69101

@@ -87,8 +119,8 @@ function check_options() {
87119
exit 1
88120
fi
89121
;;
90-
--skip-toolchain-setup)
91-
skip_toolchain_setup=1
122+
--enable-baremetal-toolchain)
123+
enable_baremetal_toolchain=1
92124
shift
93125
;;
94126
--target-toolchain)
@@ -104,14 +136,49 @@ function check_options() {
104136
exit 1
105137
fi
106138
;;
107-
--skip-fvp-setup)
108-
skip_fvp_setup=1
139+
--enable-fvps)
140+
enable_fvps=1
141+
shift
142+
;;
143+
--enable-vela)
144+
enable_vela=1
145+
shift
146+
;;
147+
--enable-model-converter)
148+
enable_model_converter=1
149+
shift
150+
;;
151+
--enable-vgf-lib)
152+
enable_vgf_lib=1
109153
shift
110154
;;
111-
--skip-vela-setup)
112-
skip_vela_setup=1
155+
--enable-emulation-layer)
156+
enable_emulation_layer=1
113157
shift
114158
;;
159+
--disable-ethos-u-deps)
160+
enable_baremetal_toolchain=0
161+
enable_fvps=0
162+
enable_vela=0
163+
shift
164+
;;
165+
--enable-mlsdk-deps)
166+
enable_model_converter=1
167+
enable_vgf_lib=1
168+
enable_emulation_layer=1
169+
shift
170+
;;
171+
--mlsdk-manifest-url)
172+
# Ensure that there is a url provided.
173+
if [[ -n "$2" && "${2:0:1}" != "-" ]]; then
174+
mlsdk_manifest_url="$2"
175+
shift 2
176+
else
177+
echo "Error: --mlsdk-manifest-url requires a URL argument."
178+
print_usage "$@"
179+
exit 1
180+
fi
181+
;;
115182
--help)
116183
print_usage "$@"
117184
exit 0
@@ -267,7 +334,7 @@ function create_setup_path(){
267334

268335
echo "" > "${setup_path_script}"
269336

270-
if [[ "${skip_fvp_setup}" -eq 0 ]]; then
337+
if [[ "${enable_fvps}" -eq 1 ]]; then
271338
fvps=("corstone300" "corstone320")
272339
for fvp in "${fvps[@]}"; do
273340
model_dir_variable=${fvp}_model_dir
@@ -284,10 +351,29 @@ function create_setup_path(){
284351
echo "hash FVP_Corstone_SSE-320" >> ${setup_path_script}
285352
fi
286353

287-
if [[ "${skip_toolchain_setup}" -eq 0 ]]; then
354+
if [[ "${enable_baremetal_toolchain}" -eq 1 ]]; then
288355
toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)"
289356
echo "export PATH=\${PATH}:${toolchain_bin_path}" >> ${setup_path_script}
290357
fi
358+
359+
if [[ "${enable_model_converter}" -eq 1 ]]; then
360+
cd "${root_dir}"
361+
model_converter_bin_path="$(cd ${mlsdk_manifest_dir}/sw/model-converter/build && pwd)"
362+
echo "export PATH=\${PATH}:${model_converter_bin_path}" >> ${setup_path_script}
363+
fi
364+
365+
# Add Path for vgf-lib and emulation-layer
366+
if [[ "${enable_vgf_lib}" -eq 1 ]]; then
367+
cd "${root_dir}"
368+
model_vgf_lib_bin_path="$(cd ${mlsdk_manifest_dir}/sw/vgf-lib/build && pwd)"
369+
echo "export PATH=\${PATH}:${model_vgf_lib_bin_path}" >> ${setup_path_script}
370+
fi
371+
372+
if [[ "${enable_emulation_layer}" -eq 1 ]]; then
373+
cd "${root_dir}"
374+
model_emulation_layer_bin_path="$(cd ${mlsdk_manifest_dir}/sw/vgf-lib/build && pwd)"
375+
echo "export PATH=\${PATH}:${model_emulation_layer_bin_path}" >> ${setup_path_script}
376+
fi
291377
}
292378

293379
function check_platform_support() {
@@ -318,10 +404,14 @@ if [[ $is_script_sourced -eq 0 ]]; then
318404
setup_root_dir
319405
cd "${root_dir}"
320406
echo "[main] Using root dir ${root_dir} and options:"
321-
echo "skip-fvp-setup=${skip_fvp_setup}"
407+
echo "enable-fvps=${enable_fvps}"
322408
echo "target-toolchain=${target_toolchain}"
323-
echo "skip-toolchain-setup=${skip_toolchain_setup}"
324-
echo "skip-vela-setup=${skip_vela_setup}"
409+
echo "enable-baremetal-toolchain=${enable_baremetal_toolchain}"
410+
echo "enable-model-converter=${enable_model_converter}"
411+
echo "enable-vgf-lib=${enable_vgf_lib}"
412+
echo "enable-emulation-layer=${enable_emulation_layer}"
413+
echo "enable-vela=${enable_vela}"
414+
echo "mlsdk-manifest-url=${mlsdk_manifest_url}"
325415

326416
# Import utils
327417
source $et_dir/backends/arm/scripts/utils.sh
@@ -330,25 +420,42 @@ if [[ $is_script_sourced -eq 0 ]]; then
330420
select_toolchain
331421

332422
# Setup toolchain
333-
if [[ "${skip_toolchain_setup}" -eq 0 ]]; then
423+
if [[ "${enable_baremetal_toolchain}" -eq 1 ]]; then
334424
setup_toolchain
335425
fi
336426

337427
# Setup FVP
338-
if [[ "${skip_fvp_setup}" -eq 0 ]]; then
428+
if [[ "${enable_fvps}" -eq 1 ]]; then
339429
setup_fvp
340430
fi
341431

432+
433+
if [[ -z "$mlsdk_manifest_url" && "${enable_model_converter}" -eq 1 ]]; then
434+
echo "Warning: mlsdk-manifest-url is not set, but model converter setup is not skipped."
435+
echo " Please set the --mlsdk-manifest-url option to the correct URL."
436+
echo " Skipping MLSDK model converter setup."
437+
enable_model_converter=0 # Q: Can we assume if we enable mlsdk, we will always enable model converter
438+
enable_vgf_lib=0
439+
enable_emulation_layer=0
440+
fi
441+
442+
if [[ "${enable_model_converter}" -eq 1 ]]; then
443+
source $et_dir/backends/arm/scripts/mlsdk_utils.sh -u "${mlsdk_manifest_url}"
444+
setup_model_converter ${root_dir} ${mlsdk_manifest_dir} ${enable_vgf_lib} ${enable_emulation_layer}
445+
fi
446+
342447
# Create new setup_path script
343-
if [[ "${skip_toolchain_setup}" -eq 0 || "${skip_fvp_setup}" -eq 0 ]]; then
448+
if [[ "${enable_baremetal_toolchain}" -eq 1 || \
449+
"${enable_fvps}" -eq 1 || \
450+
"${enable_model_converter}" -eq 1 ]]; then
344451
create_setup_path
345452
fi
346453

347454
# Setup the tosa_reference_model
348455
$et_dir/backends/arm/scripts/install_reference_model.sh ${root_dir}
349456

350457
# Setup vela and patch in codegen fixes
351-
if [[ "${skip_vela_setup}" -eq 0 ]]; then
458+
if [[ "${enable_vela}" -eq 1 ]]; then
352459
setup_vela
353460
fi
354461

0 commit comments

Comments
 (0)