|
| 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 -eu |
| 8 | + |
| 9 | +script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) |
| 10 | +et_root_dir=$(cd ${script_dir}/../../.. && pwd) |
| 11 | +et_root_dir=$(realpath ${et_root_dir}) |
| 12 | +toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake |
| 13 | + |
| 14 | +pte_file="" |
| 15 | +target="ethos-u55-128" |
| 16 | +build_type="Release" |
| 17 | +system_config="" |
| 18 | +build_with_etdump=false |
| 19 | +extra_build_flags="" |
| 20 | +output_folder_set=false |
| 21 | +output_folder="." |
| 22 | +et_build_root="${et_root_dir}/arm_test" |
| 23 | +ethosu_tools_dir=${et_root_dir}/examples/arm/ethos-u-scratch |
| 24 | + |
| 25 | +help() { |
| 26 | + echo "Usage: $(basename $0) [options]" |
| 27 | + echo "Options:" |
| 28 | + echo " --pte=<PTE_FILE> pte file (genrated by the aot_arm_compier from the model to include in the elf" |
| 29 | + echo " --target=<TARGET> Target to build and run for Default: ${target}" |
| 30 | + echo " --build_type=<TYPE> Build with Release, Debug or RelWithDebInfo, default is ${build_type}" |
| 31 | + echo " --system_config=<CONFIG> System configuration to select from the Vela configuration file (see vela.ini). Default: Ethos_U55_High_End_Embedded for EthosU55 targets, Ethos_U85_SYS_DRAM_Mid for EthosU85 targets." |
| 32 | + echo " NOTE: If given, this option must match the given target. This option also sets timing adapter values customized for specific hardware, see ./executor_runner/CMakeLists.txt." |
| 33 | + echo " --etdump Adds Devtools etdump support to track timing, etdump area will be base64 encoded in the log" |
| 34 | + echo " --extra_build_flags=<FLAGS> Extra flags to pass to cmake like -DET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=60000 Default: none " |
| 35 | + echo " --output=<FOLDER> Output folder Default: <MODEL>/<MODEL>_<TARGET INFO>.pte" |
| 36 | + echo " --et_build_root=<FOLDER> Build output root folder to use, defaults to ${et_build_root}" |
| 37 | + echo " --ethosu_tools_dir=<FOLDER> Path to your Ethos-U tools dir if you not using default: ${ethosu_tools_dir}" |
| 38 | + exit 0 |
| 39 | +} |
| 40 | + |
| 41 | +for arg in "$@"; do |
| 42 | + case $arg in |
| 43 | + -h|--help) help ;; |
| 44 | + --pte=*) pte_file="${arg#*=}";; |
| 45 | + --target=*) target="${arg#*=}";; |
| 46 | + --build_type=*) build_type="${arg#*=}";; |
| 47 | + --system_config=*) system_config="${arg#*=}";; |
| 48 | + --etdump) build_with_etdump=true ;; |
| 49 | + --extra_build_flags=*) extra_build_flags="${arg#*=}";; |
| 50 | + --output=*) output_folder="${arg#*=}" ; output_folder_set=true ;; |
| 51 | + --et_build_root=*) et_build_root="${arg#*=}";; |
| 52 | + --ethosu_tools_dir=*) ethosu_tools_dir="${arg#*=}";; |
| 53 | + *) |
| 54 | + ;; |
| 55 | + esac |
| 56 | +done |
| 57 | + |
| 58 | +pte_file=$(realpath ${pte_file}) |
| 59 | +ethosu_tools_dir=$(realpath ${ethosu_tools_dir}) |
| 60 | +ethos_u_root_dir="$ethosu_tools_dir/ethos-u" |
| 61 | +ethosu_tools_dir=$(realpath ${ethos_u_root_dir}) |
| 62 | + |
| 63 | +et_build_dir=${et_build_root}/cmake-out |
| 64 | +et_build_dir=$(realpath ${et_build_dir}) |
| 65 | + |
| 66 | +if [ "$output_folder_set" = false ] ; then |
| 67 | + pte_folder=$(cd -- "$( dirname -- "${pte_file}" )" &> /dev/null && pwd) |
| 68 | + pte_short_name=$(basename -- "${pte_file}" ".pte") |
| 69 | + output_folder="$pte_folder/$pte_short_name" |
| 70 | +fi |
| 71 | + |
| 72 | +if [[ ${system_config} == "" ]] |
| 73 | +then |
| 74 | + system_config="Ethos_U55_High_End_Embedded" |
| 75 | + if [[ ${target} =~ "ethos-u85" ]] |
| 76 | + then |
| 77 | + system_config="Ethos_U85_SYS_DRAM_Mid" |
| 78 | + fi |
| 79 | +fi |
| 80 | + |
| 81 | +output_folder=$(realpath ${output_folder}) |
| 82 | + |
| 83 | +if [[ ${target} == *"ethos-u55"* ]]; then |
| 84 | + target_cpu=cortex-m55 |
| 85 | +else |
| 86 | + target_cpu=cortex-m85 |
| 87 | +fi |
| 88 | +echo "--------------------------------------------------------------------------------" |
| 89 | +echo "Build Arm Baremetal executor_runner for ${target} with ${pte_file} using ${system_config} to '${output_folder}/cmake-out'" |
| 90 | +echo "--------------------------------------------------------------------------------" |
| 91 | + |
| 92 | +cd ${et_root_dir}/examples/arm/executor_runner |
| 93 | + |
| 94 | +build_with_etdump_flags="" |
| 95 | +if [ "$build_with_etdump" = true ] ; then |
| 96 | + echo "Building with etdump e.g. -DEXECUTORCH_ENABLE_EVENT_TRACER=ON" |
| 97 | + build_with_etdump_flags=" -DEXECUTORCH_ENABLE_EVENT_TRACER=ON " |
| 98 | +fi |
| 99 | + |
| 100 | +mkdir -p "$output_folder" |
| 101 | + |
| 102 | +cmake \ |
| 103 | + -DCMAKE_BUILD_TYPE=${build_type} \ |
| 104 | + -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \ |
| 105 | + -DTARGET_CPU=${target_cpu} \ |
| 106 | + -DET_DIR_PATH:PATH=${et_root_dir} \ |
| 107 | + -DET_BUILD_DIR_PATH:PATH=${et_build_dir} \ |
| 108 | + -DET_PTE_FILE_PATH:PATH="${pte_file}" \ |
| 109 | + -DETHOS_SDK_PATH:PATH=${ethos_u_root_dir} \ |
| 110 | + -DETHOSU_TARGET_NPU_CONFIG=${target} \ |
| 111 | + ${build_with_etdump_flags} \ |
| 112 | + -DPYTHON_EXECUTABLE=$(which python3) \ |
| 113 | + -DSYSTEM_CONFIG=${system_config} \ |
| 114 | + ${extra_build_flags} \ |
| 115 | + -B ${output_folder}/cmake-out |
| 116 | + |
| 117 | +echo "[${BASH_SOURCE[0]}] Configured CMAKE" |
| 118 | + |
| 119 | +cmake --build ${output_folder}/cmake-out --parallel -- arm_executor_runner |
| 120 | + |
| 121 | +echo "[${BASH_SOURCE[0]}] Generated baremetal elf file:" |
| 122 | +find ${output_folder}/cmake-out -name "arm_executor_runner" |
| 123 | +echo "executable_text: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $1}') bytes" |
| 124 | +echo "executable_data: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $2}') bytes" |
| 125 | +echo "executable_bss: $(find ${output_folder}/cmake-out -name arm_executor_runner -exec arm-none-eabi-size {} \; | grep -v filename | awk '{print $3}') bytes" |
0 commit comments