Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions backends/arm/scripts/mlsdk_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash
# Copyright 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 -euo pipefail

# TODO
mlsdk_manifest_url=""

script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)

source ${script_dir}/utils.sh

usage() { echo "Usage: $0 [-u <mlsdk-manifest-url>]" 1>&2; exit 1; }

while getopts ":u:" opt; do
case "${opt}" in
u)
mlsdk_manifest_url=${OPTARG}
;;
*)
usage
;;
esac
done

function download_ai_mlsdk_manifest() {
local _dada_dir="$1"

if [[ -z "${_dada_dir}" ]]; then
echo "Error: _dada_dir parameter missing?"
return 1
fi

if [[ -z "${mlsdk_manifest_url}" ]]; then
echo "Error: mlsdk_manifest_url parameter missing?"
return 1
fi

if [[ ! -d "${_dada_dir}" ]]; then
mkdir -p "$_dada_dir"
pushd "$_dada_dir" || exit 1

curl https://storage.googleapis.com/git-repo-downloads/repo > repo
chmod u+x repo
./repo init --no-repo-verify --depth=1 --manifest-url ${mlsdk_manifest_url} -g model-converter,emulation-layer,vgf-library
./repo sync

popd
fi
}

function setup_model_converter() {
local work_dir="$1"
local manifest_dir="$2"
local enable_vgf_lib="$3"
local enable_emulation_layer="$4"

if [[ -z "$work_dir" ]]; then
echo "Error: work_dir parameter is required."
return 1
fi

if [[ -z "$manifest_dir" ]]; then
echo "Error: manifest_dir parameter is required."
return 1
fi

mkdir -p "$work_dir"
pushd "$work_dir" || exit 1

download_ai_mlsdk_manifest ${manifest_dir}

pushd "$manifest_dir"

# model-converter
# TODO: Remove macOS patch after mlsdk fully supports macOS
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' '/^ *print(f"Unsupported host platform/ i\
if system == "Darwin":\
# Use default Apple toolchain (Clang) on macOS\
return True\
\
' sw/model-converter/scripts/build.py
fi
python sw/model-converter/scripts/build.py -j$(nproc)

# libvgf
if [[ "${enable_vgf_lib}" -eq 1 ]]; then
# TODO: Remove macOS patch after mlsdk fully supports macOS
if [[ "$(uname)" == "Darwin" ]]; then
sed -i '' '/^ *print(f"ERROR: Unsupported host platform/ i\
if system == "Darwin":\
# Use default Apple toolchain (Clang) on macOS\
return True\
\
' sw/vgf-lib/scripts/build.py
fi
python sw/vgf-lib/scripts/build.py -j$(nproc)
fi

# emu layer
if [[ "${enable_emulation_layer}" -eq 1 ]]; then
pushd sw/emulation-layer
cmake -B build \
-DGLSLANG_PATH=../../dependencies/glslang \
-DSPIRV_CROSS_PATH=../../dependencies/SPIRV-Cross \
-DSPIRV_HEADERS_PATH=../../dependencies/SPIRV-Headers \
-DSPIRV_TOOLS_PATH=../../dependencies/SPIRV-Tools \
-DVULKAN_HEADERS_PATH=../../dependencies/Vulkan-Headers
cmake --build build
popd
fi

popd
}

#setup_model_converter() $1
# `"$manifest_dir"'
149 changes: 128 additions & 21 deletions examples/arm/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ 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"
root_dir="${script_dir}/ethos-u-scratch" # TODO: rename
eula_acceptance=0
skip_toolchain_setup=0
enable_baremetal_toolchain=1
target_toolchain=""
skip_fvp_setup=0
skip_vela_setup=0
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
mlsdk_manifest_url=""


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

# vela
# Vela
vela_repo_url="https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-vela"
vela_rev="8cac2b9a7204b57125a8718049519b091a98846c"

# MLSDK dependencies
mlsdk_manifest_dir="ml-sdk-for-vulkan-manifest"

# 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) <--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]"
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: $*"
}

Expand All @@ -87,8 +119,8 @@ function check_options() {
exit 1
fi
;;
--skip-toolchain-setup)
skip_toolchain_setup=1
--enable-baremetal-toolchain)
enable_baremetal_toolchain=1
shift
;;
--target-toolchain)
Expand All @@ -104,14 +136,49 @@ function check_options() {
exit 1
fi
;;
--skip-fvp-setup)
skip_fvp_setup=1
--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
;;
--skip-vela-setup)
skip_vela_setup=1
--enable-emulation-layer)
enable_emulation_layer=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
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
;;
--help)
print_usage "$@"
exit 0
Expand Down Expand Up @@ -267,7 +334,7 @@ function create_setup_path(){

echo "" > "${setup_path_script}"

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

if [[ "${skip_toolchain_setup}" -eq 0 ]]; then
if [[ "${enable_baremetal_toolchain}" -eq 1 ]]; then
toolchain_bin_path="$(cd ${toolchain_dir}/bin && pwd)"
echo "export PATH=\${PATH}:${toolchain_bin_path}" >> ${setup_path_script}
fi

if [[ "${enable_model_converter}" -eq 1 ]]; then
cd "${root_dir}"
model_converter_bin_path="$(cd ${mlsdk_manifest_dir}/sw/model-converter/build && pwd)"
echo "export PATH=\${PATH}:${model_converter_bin_path}" >> ${setup_path_script}
fi

# Add Path for vgf-lib and emulation-layer
if [[ "${enable_vgf_lib}" -eq 1 ]]; then
cd "${root_dir}"
model_vgf_lib_bin_path="$(cd ${mlsdk_manifest_dir}/sw/vgf-lib/build && pwd)"
echo "export PATH=\${PATH}:${model_vgf_lib_bin_path}" >> ${setup_path_script}
fi

if [[ "${enable_emulation_layer}" -eq 1 ]]; then
cd "${root_dir}"
model_emulation_layer_bin_path="$(cd ${mlsdk_manifest_dir}/sw/vgf-lib/build && pwd)"
echo "export PATH=\${PATH}:${model_emulation_layer_bin_path}" >> ${setup_path_script}
fi
}

function check_platform_support() {
Expand Down Expand Up @@ -318,10 +404,14 @@ if [[ $is_script_sourced -eq 0 ]]; then
setup_root_dir
cd "${root_dir}"
echo "[main] Using root dir ${root_dir} and options:"
echo "skip-fvp-setup=${skip_fvp_setup}"
echo "enable-fvps=${enable_fvps}"
echo "target-toolchain=${target_toolchain}"
echo "skip-toolchain-setup=${skip_toolchain_setup}"
echo "skip-vela-setup=${skip_vela_setup}"
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-vela=${enable_vela}"
echo "mlsdk-manifest-url=${mlsdk_manifest_url}"

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

# Setup toolchain
if [[ "${skip_toolchain_setup}" -eq 0 ]]; then
if [[ "${enable_baremetal_toolchain}" -eq 1 ]]; then
setup_toolchain
fi

# Setup FVP
if [[ "${skip_fvp_setup}" -eq 0 ]]; then
if [[ "${enable_fvps}" -eq 1 ]]; then
setup_fvp
fi


if [[ -z "$mlsdk_manifest_url" && "${enable_model_converter}" -eq 1 ]]; then
echo "Warning: mlsdk-manifest-url is not set, but model converter setup is not skipped."
echo " Please set the --mlsdk-manifest-url option to the correct URL."
echo " Skipping MLSDK model converter setup."
enable_model_converter=0 # Q: Can we assume if we enable mlsdk, we will always enable model converter
enable_vgf_lib=0
enable_emulation_layer=0
fi

if [[ "${enable_model_converter}" -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_vgf_lib} ${enable_emulation_layer}
fi

# Create new setup_path script
if [[ "${skip_toolchain_setup}" -eq 0 || "${skip_fvp_setup}" -eq 0 ]]; then
if [[ "${enable_baremetal_toolchain}" -eq 1 || \
"${enable_fvps}" -eq 1 || \
"${enable_model_converter}" -eq 1 ]]; then
create_setup_path
fi

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

# Setup vela and patch in codegen fixes
if [[ "${skip_vela_setup}" -eq 0 ]]; then
if [[ "${enable_vela}" -eq 1 ]]; then
setup_vela
fi

Expand Down
Loading