Skip to content

Plumbing for Arm Example Runnner to use Zephyr Toolchain #12078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
18 changes: 11 additions & 7 deletions backends/arm/scripts/build_executor_runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -eu
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
et_root_dir=$(realpath ${et_root_dir})
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
toolchain=arm-none-eabi-gcc
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."

Expand Down Expand Up @@ -46,6 +46,7 @@ help() {
echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte"
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}"
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
exit 0
}

Expand All @@ -63,11 +64,15 @@ for arg in "$@"; do
--output=*) output_folder="${arg#*=}" ; output_folder_set=true ;;
--et_build_root=*) et_build_root="${arg#*=}";;
--ethosu_tools_dir=*) ethosu_tools_dir="${arg#*=}";;
--toolchain=*) toolchain="${arg#*=}";;
*)
;;
esac
done

toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/${toolchain}.cmake
toolchain_cmake=$(realpath ${toolchain_cmake})

# Source the tools
# This should be prepared by the setup.sh
[[ -f ${setup_path_script} ]] \
Expand Down Expand Up @@ -116,7 +121,7 @@ else
target_cpu=cortex-m85
fi
echo "--------------------------------------------------------------------------------"
echo "Build Arm Baremetal executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}/cmake-out'"
echo "Build Arm ${toolchain/-gcc/} executor_runner for ${target} with ${pte_file} using ${system_config} ${memory_mode} ${extra_build_flags} to '${output_folder}/cmake-out'"
echo "--------------------------------------------------------------------------------"

cd ${et_root_dir}/examples/arm/executor_runner
Expand All @@ -130,7 +135,6 @@ if [ "$build_with_etdump" = true ] ; then
fi

echo "Building with BundleIO/etdump/extra flags: ${build_bundleio_flags} ${build_with_etdump_flags} ${extra_build_flags}"

cmake \
-DCMAKE_BUILD_TYPE=${build_type} \
-DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
Expand All @@ -152,8 +156,8 @@ echo "[${BASH_SOURCE[0]}] Configured CMAKE"

cmake --build ${output_folder}/cmake-out -j$(nproc) -- arm_executor_runner

echo "[${BASH_SOURCE[0]}] Generated baremetal elf file:"
echo "[${BASH_SOURCE[0]}] Generated ${toolchain} elf file:"
find ${output_folder}/cmake-out -name "arm_executor_runner"
echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $1}') bytes"
echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $2}') bytes"
echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $3}') bytes"
echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $1}') bytes"
echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $2}') bytes"
echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec ${toolchain/-gcc/-size} {} \; | grep -v filename | awk '{print $3}') bytes"
8 changes: 6 additions & 2 deletions backends/arm/scripts/build_executorch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ set -eu
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
et_root_dir=$(realpath ${et_root_dir})
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
toolchain_cmake=$(realpath ${toolchain_cmake})
toolchain=arm-none-eabi-gcc
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."

Expand All @@ -30,6 +29,7 @@ help() {
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
echo " --devtools Build Devtools libs"
echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log"
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
exit 0
}

Expand All @@ -40,11 +40,15 @@ for arg in "$@"; do
--build_type=*) build_type="${arg#*=}";;
--devtools) build_devtools=true ;;
--etdump) build_with_etdump=true ;;
--toolchain=*) toolchain="${arg#*=}";;
*)
;;
esac
done

toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/${toolchain}.cmake
toolchain_cmake=$(realpath ${toolchain_cmake})

# Source the tools
# This should be prepared by the setup.sh
[[ -f ${setup_path_script} ]] \
Expand Down
8 changes: 6 additions & 2 deletions backends/arm/scripts/build_portable_kernels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ set -eu
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
et_root_dir=$(realpath ${et_root_dir})
toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
toolchain_cmake=$(realpath ${toolchain_cmake})
toolchain=arm-none-eabi-gcc
setup_path_script=${et_root_dir}/examples/arm/ethos-u-scratch/setup_path.sh
_setup_msg="please refer to ${et_root_dir}/examples/arm/setup.sh to properly install necessary tools."

Expand All @@ -29,6 +28,7 @@ help() {
echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}"
echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}"
echo " --portable_kernels=<OPS> Comma separated list of portable (non delagated) kernels to include Default: ${portable_kernels}"
echo " --toolchain=<TOOLCHAIN> Toolchain can be specified (e.g. bare metal as arm-none-eabi-gcc or zephyr as arm-zephyr-eabi-gcc"
exit 0
}

Expand All @@ -38,11 +38,15 @@ for arg in "$@"; do
--et_build_root=*) et_build_root="${arg#*=}";;
--build_type=*) build_type="${arg#*=}";;
--portable_kernels=*) portable_kernels="${arg#*=}";;
--toolchain=*) toolchain="${arg#*=}";;
*)
;;
esac
done

toolchain_cmake=${script_dir}/../../../examples/arm/ethos-u-setup/${toolchain}.cmake
toolchain_cmake=$(realpath ${toolchain_cmake})

# Source the tools
# This should be prepared by the setup.sh
[[ -f ${setup_path_script} ]] \
Expand Down
106 changes: 106 additions & 0 deletions examples/arm/ethos-u-setup/arm-zephyr-eabi-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#
# Copyright (c) 2020-2022 Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the License); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake And
# modified to align better with cs300 platform

set(TARGET_CPU
"cortex-m55"
CACHE STRING "Target CPU"
)
string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER "arm-zephyr-eabi-gcc")
set(CMAKE_CXX_COMPILER "arm-zephyr-eabi-g++")
set(CMAKE_ASM_COMPILER "arm-zephyr-eabi-gcc")
set(CMAKE_LINKER "arm-zephyr-eabi-ld")

set(CMAKE_EXECUTABLE_SUFFIX ".elf")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Select C/C++ version
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR})
string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU})

# Compile options
add_compile_options(
-mcpu=${GCC_CPU} -mthumb "$<$<CONFIG:DEBUG>:-gdwarf-3>"
"$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>"
-fdata-sections -ffunction-sections
)

# Compile defines
add_compile_definitions("$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")

# Link options
add_link_options(-mcpu=${GCC_CPU} -mthumb)

if(SEMIHOSTING)
add_link_options(--specs=rdimon.specs)
else()
add_link_options(--specs=nosys.specs)
endif()

# Set floating point unit
if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp")
set(FLOAT hard)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp")
set(FLOAT soft)
elseif(
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)"
)
set(FLOAT hard)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)"
OR CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)"
)
set(FLOAT hard)
set(FPU_CONFIG "fpv4-sp-d16")
add_compile_options(-mfpu=${FPU_CONFIG})
add_link_options(-mfpu=${FPU_CONFIG})
else()
set(FLOAT soft)
endif()

if(FLOAT)
add_compile_options(-mfloat-abi=${FLOAT})
add_link_options(-mfloat-abi=${FLOAT})
endif()

add_link_options(LINKER:--nmagic,--gc-sections)

# Compilation warnings
add_compile_options(
# -Wall -Wextra -Wcast-align -Wdouble-promotion -Wformat
# -Wmissing-field-initializers -Wnull-dereference -Wredundant-decls -Wshadow
# -Wswitch -Wswitch-default -Wunused -Wno-redundant-decls
-Wno-stringop-overread
-Wno-error=format=
-Wno-error=maybe-uninitialized
-Wno-error=deprecated-declarations
-Wno-error=shift-count-overflow
-Wno-psabi
)
14 changes: 8 additions & 6 deletions examples/arm/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ memory_mode=""
et_build_root="${et_root_dir}/arm_test"
ethos_u_scratch_dir=${script_dir}/ethos-u-scratch
scratch_dir_set=false
toolchain=arm-none-eabi-gcc

function help() {
echo "Usage: $(basename $0) [options]"
Expand Down Expand Up @@ -75,6 +76,7 @@ for arg in "$@"; do
--no_quantize) aot_arm_compiler_flag_quantize="" ;;
--portable_kernels=*) portable_kernels="${arg#*=}";;
--target=*) target="${arg#*=}";;
--toolchain=*) toolchain="${arg#*=}";;
--output=*) output_folder="${arg#*=}" ; output_folder_set=true ;;
--bundleio) bundleio=true ;;
--etdump) build_with_etdump=true ;;
Expand All @@ -94,7 +96,7 @@ done
# Default Ethos-u tool folder override with --scratch-dir=<FOLDER>
ethos_u_scratch_dir=$(realpath ${ethos_u_scratch_dir})
setup_path_script=${ethos_u_scratch_dir}/setup_path.sh
toolchain_cmake=${script_dir}/ethos-u-setup/arm-none-eabi-gcc.cmake
toolchain_cmake=${script_dir}/ethos-u-setup/${toolchain}.cmake
_setup_msg="please refer to ${script_dir}/setup.sh to properly install necessary tools."


Expand Down Expand Up @@ -134,8 +136,8 @@ function check_setup () {
fi

# If setup_path_script was correct all these checks should now pass
hash arm-none-eabi-gcc \
|| { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; return 1; }
hash ${toolchain} \
|| { echo "Could not find ${toolchain} toolchain on PATH, ${_setup_msg}"; return 1; }

[[ -f ${toolchain_cmake} ]] \
|| { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; return 1; }
Expand Down Expand Up @@ -180,8 +182,8 @@ if [ "$bundleio" = true ] ; then
et_dump_flag="--etdump"
fi

backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag
backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels
backends/arm/scripts/build_executorch.sh --et_build_root="${et_build_root}" --build_type=$build_type $devtools_flag --toolchain="${toolchain}"
backends/arm/scripts/build_portable_kernels.sh --et_build_root="${et_build_root}" --build_type=$build_type --portable_kernels=$portable_kernels --toolchain="${toolchain}"

if [[ -z "$model_name" ]]; then
# the test models run, and whether to delegate
Expand Down Expand Up @@ -265,7 +267,7 @@ for i in "${!test_model[@]}"; do
else
set -x
# Rebuild the application as the pte is imported as a header/c array
backends/arm/scripts/build_executor_runner.sh --et_build_root="${et_build_root}" --pte="${pte_file}" --build_type=${build_type} --target=${target} --system_config=${system_config} --memory_mode=${memory_mode} ${bundleio_flag} ${et_dump_flag} --extra_build_flags="${extra_build_flags}" --ethosu_tools_dir="${ethos_u_scratch_dir}"
backends/arm/scripts/build_executor_runner.sh --et_build_root="${et_build_root}" --pte="${pte_file}" --build_type=${build_type} --target=${target} --system_config=${system_config} --memory_mode=${memory_mode} ${bundleio_flag} ${et_dump_flag} --extra_build_flags="${extra_build_flags}" --ethosu_tools_dir="${ethos_u_scratch_dir}" --toolchain="${toolchain}"
if [ "$build_only" = false ] ; then
# Execute the executor_runner on FVP Simulator
elf_file="${output_folder}/${elf_folder}/cmake-out/arm_executor_runner"
Expand Down
Loading