|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | +# All rights reserved. |
| 4 | +# |
| 5 | +# This source code is licensed under the BSD-style license found in the |
| 6 | +# LICENSE file in the root directory of this source tree. |
| 7 | + |
| 8 | +set -eu |
| 9 | + |
| 10 | +######## |
| 11 | +### Hardcoded constants |
| 12 | +######## |
| 13 | +script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) |
| 14 | +et_root_dir=$(readlink -f ${script_dir}/../../../) |
| 15 | +et_build_dir=${et_root_dir}/cmake-out |
| 16 | +ethos_u_root_dir=${1:-"$(readlink -f ${script_dir}/../ethos-u)"} |
| 17 | +ethos_u_build_dir=${ethos_u_root_dir}/core_platform/build |
| 18 | +fvp_model=FVP_Corstone_SSE-300_Ethos-U55 |
| 19 | +toolchain_cmake=${ethos_u_root_dir}/core_platform/cmake/toolchain/arm-none-eabi-gcc.cmake |
| 20 | +_setup_msg="please refer to ${script_dir}/ethos-u-setup/setup.sh to properly install necessary tools." |
| 21 | + |
| 22 | + |
| 23 | +# Generate eager mode results |
| 24 | +# TODO |
| 25 | + |
| 26 | +# Generate the PTE file |
| 27 | +function generate_pte_file() { |
| 28 | + cd $et_root_dir |
| 29 | + python3 -m examples.export.export_example --model_name="softmax" |
| 30 | + local pte_file=$(readlink -f ./softmax.pte) |
| 31 | + [[ -f ${pte_file} ]] || { echo "Failed to generate a pte file - ${pte_file}"; exit 1; } |
| 32 | + echo "${pte_file}" |
| 33 | +} |
| 34 | + |
| 35 | +# build ExecuTorch Libraries |
| 36 | +function build_executorch() { |
| 37 | + mkdir "${et_build_dir}" |
| 38 | + cd "${et_build_dir}" |
| 39 | + cmake \ |
| 40 | + -DBUCK2=/tmp/buck2 \ |
| 41 | + -DEXECUTORCH_BUILD_XNNPACK=OFF \ |
| 42 | + -DFLATC_EXECUTABLE="$(which flatc)" \ |
| 43 | + -DCMAKE_TOOLCHAIN_FILE="${toolchain_cmake}" \ |
| 44 | + -DEXECUTORCH_BUILD_HOST_TARGETS=OFF \ |
| 45 | + -DCMAKE_BUILD_TYPE=Release \ |
| 46 | + -DEXECUTORCH_ENABLE_LOGGING_RELEASE_MODE=ON \ |
| 47 | + -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=OFF \ |
| 48 | + -DEXECUTORCH_BUILD_GFLAGS=OFF \ |
| 49 | + -DSELECT_OPS_LIST="aten::_softmax.out" \ |
| 50 | + "${et_root_dir}" |
| 51 | + |
| 52 | + echo "[${FUNCNAME[0]}] Configured CMAKE" |
| 53 | + |
| 54 | + n=$(nproc) |
| 55 | + cmake --build . -j"$((n - 5))" |
| 56 | + echo "[${FUNCNAME[0]}] Generated static libraries for ExecuTorch:" |
| 57 | + find . -name "*.a" -exec ls -al {} \; |
| 58 | +} |
| 59 | + |
| 60 | +# build Arm Baremetal executor_runner |
| 61 | +function build_executorch_runner() { |
| 62 | + [[ $# -ne 1 ]] && { echo "[${FUNCNAME[0]}] Expecting pte file as an argument got, $@"; exit 1; } |
| 63 | + local pte=${1} |
| 64 | + cd "${ethos_u_root_dir}"/core_platform |
| 65 | + cmake \ |
| 66 | + -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \ |
| 67 | + -B build targets/corstone-300 \ |
| 68 | + -DET_DIR_PATH:PATH=${et_root_dir} \ |
| 69 | + -DET_BUILD_DIR_PATH:PATH=${et_build_dir} \ |
| 70 | + -DET_PTE_FILE_PATH:PATH="${pte}" \ |
| 71 | + -DPYTHON_EXECUTABLE=$(which python3) |
| 72 | + echo "[${FUNCNAME[0]}] Configured CMAKE" |
| 73 | + |
| 74 | + n=$(nproc) |
| 75 | + cmake --build build -- -j"$((n - 5))" executor_runner VERBOSE=1 |
| 76 | + echo "[${FUNCNAME[0]}] Generated baremetal elf file:" |
| 77 | + find . -name "executor_runner.elf" |
| 78 | +} |
| 79 | + |
| 80 | +# Execute the executor_runner on FVP Simulator |
| 81 | +function run_fvp() { |
| 82 | + elf=$(find ${ethos_u_build_dir} -name "executor_runner.elf") |
| 83 | + [[ ! -f $elf ]] && { echo "[${FUNCNAME[0]}]: Unable to find executor_runner elf: ${elf}"; exit 1; } |
| 84 | + FVP_Corstone_SSE-300_Ethos-U55 \ |
| 85 | + -C ethosu.num_macs=128 \ |
| 86 | + -C mps3_board.visualisation.disable-visualisation=1 \ |
| 87 | + -C mps3_board.telnetterminal0.start_telnet=0 \ |
| 88 | + -C mps3_board.uart0.out_file='-' \ |
| 89 | + -a "${elf}" \ |
| 90 | + --timelimit 30 # seconds |
| 91 | + echo "[${FUNCNAME[0]} Simulation complete, $?" |
| 92 | +} |
| 93 | + |
| 94 | +####### |
| 95 | +### Main |
| 96 | +####### |
| 97 | + |
| 98 | +# basic checks before we get started |
| 99 | +hash ${fvp_model} \ |
| 100 | + || { echo "Could not find ${fvp_model} on PATH, ${_setup_msg}"; exit 1; } |
| 101 | + |
| 102 | +hash arm-none-eabi-gcc \ |
| 103 | + || { echo "Could not find arm baremetal toolchain on PATH, ${_setup_msg}"; exit 1; } |
| 104 | + |
| 105 | +[[ -f ${toolchain_cmake} ]] \ |
| 106 | + || { echo "Could not find ${toolchain_cmake} file, ${_setup_msg}"; exit 1; } |
| 107 | + |
| 108 | +[[ -f ${et_root_dir}/CMakeLists.txt ]] \ |
| 109 | + || { echo "Executorch repo doesn't contain CMakeLists.txt file at root level"; exit 1; } |
| 110 | + |
| 111 | +# get the pte |
| 112 | +pte=$(generate_pte_file) |
| 113 | + |
| 114 | +# build et |
| 115 | +build_executorch |
| 116 | + |
| 117 | +# build the et baremetal app |
| 118 | +build_executorch_runner "${pte}" |
| 119 | + |
| 120 | +# run the app |
| 121 | +run_fvp |
| 122 | + |
| 123 | +exit $? |
0 commit comments