diff --git a/backends/arm/cmake/ArmRunnerUtils.cmake b/backends/arm/cmake/ArmRunnerUtils.cmake index bf98dcf7ff4..547b98c6bee 100644 --- a/backends/arm/cmake/ArmRunnerUtils.cmake +++ b/backends/arm/cmake/ArmRunnerUtils.cmake @@ -5,8 +5,8 @@ include_guard(GLOBAL) -# Helper routines shared by the standalone runner and any superbuild that reuses -# the runner targets. +# Internal helper routines shared by Arm runner examples and superbuilds. These +# functions are not a stable public CMake API. get_filename_component( _arm_runner_executorch_root "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE @@ -19,6 +19,342 @@ endif() if(NOT COMMAND gen_selected_ops) include(${EXECUTORCH_ROOT}/tools/cmake/Codegen.cmake) endif() +include(${EXECUTORCH_ROOT}/backends/arm/scripts/corstone_utils.cmake) +include(${EXECUTORCH_ROOT}/backends/arm/cmake/ArmEthosUSDK.cmake) + +macro(arm_runner_require_python) + if(NOT PYTHON_EXECUTABLE) + find_package( + Python3 + COMPONENTS Interpreter + REQUIRED + ) + set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}") + endif() +endmacro() + +macro(arm_runner_add_standalone_executorch) + if(DEFINED CMAKE_SKIP_INSTALL_RULES) + set(_arm_runner_skip_install_rules_was_defined TRUE) + set(_arm_runner_skip_install_rules "${CMAKE_SKIP_INSTALL_RULES}") + else() + set(_arm_runner_skip_install_rules_was_defined FALSE) + endif() + if(DEFINED CACHE{CMAKE_SKIP_INSTALL_RULES}) + set(_arm_runner_skip_install_rules_cache_was_defined TRUE) + get_property( + _arm_runner_skip_install_rules_cache_type + CACHE CMAKE_SKIP_INSTALL_RULES + PROPERTY TYPE + ) + set(_arm_runner_skip_install_rules_cache "$CACHE{CMAKE_SKIP_INSTALL_RULES}") + else() + set(_arm_runner_skip_install_rules_cache_was_defined FALSE) + endif() + + arm_runner_require_python() + + include(${EXECUTORCH_ROOT}/tools/cmake/common/preset.cmake) + if(NOT DEFINED EXECUTORCH_BUILD_PRESET_FILE) + set(EXECUTORCH_BUILD_PRESET_FILE + "${EXECUTORCH_ROOT}/tools/cmake/preset/arm_baremetal.cmake" + CACHE PATH "ExecuTorch build preset" + ) + endif() + load_build_preset() + foreach( + _arm_runner_option + EXECUTORCH_BUILD_ARM_BAREMETAL EXECUTORCH_BUILD_CORTEX_M + EXECUTORCH_BUILD_KERNELS_QUANTIZED EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL + ) + set(${_arm_runner_option} + ON + CACHE BOOL "" FORCE + ) + endforeach() + set(EXECUTORCH_SKIP_ARM_EXECUTOR_RUNNER + ON + CACHE BOOL "" FORCE + ) + set(MAX_KERNEL_NUM + 2000 + CACHE STRING "Maximum registered kernels" + ) + + set(_arm_runner_select_ops "${EXECUTORCH_SELECT_OPS_LIST}") + set(EXECUTORCH_SELECT_OPS_LIST "") + set(CMAKE_SKIP_INSTALL_RULES ON) + add_subdirectory( + ${EXECUTORCH_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/executorch EXCLUDE_FROM_ALL + ) + if(_arm_runner_skip_install_rules_cache_was_defined) + set(CMAKE_SKIP_INSTALL_RULES + "${_arm_runner_skip_install_rules_cache}" + CACHE "${_arm_runner_skip_install_rules_cache_type}" "" FORCE + ) + else() + unset(CMAKE_SKIP_INSTALL_RULES CACHE) + endif() + if(_arm_runner_skip_install_rules_was_defined) + set(CMAKE_SKIP_INSTALL_RULES "${_arm_runner_skip_install_rules}") + else() + unset(CMAKE_SKIP_INSTALL_RULES) + endif() + unset(_arm_runner_skip_install_rules) + unset(_arm_runner_skip_install_rules_was_defined) + unset(_arm_runner_skip_install_rules_cache) + unset(_arm_runner_skip_install_rules_cache_type) + unset(_arm_runner_skip_install_rules_cache_was_defined) + set(EXECUTORCH_SELECT_OPS_LIST "${_arm_runner_select_ops}") + include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) +endmacro() + +function(arm_runner_add_minimal_executable) + set(one_value_args TARGET SOURCE OPS_PREFIX) + set(multi_value_args COMPILE_DEFINITIONS) + cmake_parse_arguments( + ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN} + ) + if(NOT ARG_TARGET + OR NOT ARG_SOURCE + OR NOT ARG_OPS_PREFIX + ) + message(FATAL_ERROR "TARGET, SOURCE, and OPS_PREFIX are required.") + endif() + + add_executable( + ${ARG_TARGET} + ${ARG_SOURCE} + ${EXECUTORCH_ROOT}/examples/arm/common/arm_memory_allocator.cpp + ) + target_include_directories( + ${ARG_TARGET} + PRIVATE ${EXECUTORCH_ROOT} + ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10 + ${EXECUTORCH_ROOT}/examples/arm/common ${CMAKE_CURRENT_BINARY_DIR} + ) + target_compile_definitions( + ${ARG_TARGET} + PRIVATE + C10_USING_CUSTOM_GENERATED_MACROS + ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE} + ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE=${ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE} + ${ARG_COMPILE_DEFINITIONS} + ) + arm_runner_configure_model( + TARGET + ${ARG_TARGET} + PTE_FILE + "${ET_PTE_FILE_PATH}" + MODEL_PTE_ADDR + "${ET_MODEL_PTE_ADDR}" + MODEL_PTE_SIZE + "${ET_MODEL_PTE_SIZE}" + ) + arm_runner_configure_linker_script( + TARGET ${ARG_TARGET} SYSTEM_CONFIG "${SYSTEM_CONFIG}" + ) + arm_runner_link_minimal_specs(${ARG_TARGET}) + arm_runner_link_registration_libraries( + TARGET + ${ARG_TARGET} + BASE_LIBS + extension_runner_util + ethosu_target_init + REGISTRATION_LIBS + executorch + executorch_delegate_ethos_u + ${ARG_OPS_PREFIX}_portable_ops + ${ARG_OPS_PREFIX}_quantized_ops + ${ARG_OPS_PREFIX}_cortex_m_ops + NORMAL_LIBS + cortex_m_kernels + quantized_kernels + portable_kernels + kernels_util_all_deps + ) + target_link_options(${ARG_TARGET} PRIVATE LINKER:-Map=${ARG_TARGET}.map) +endfunction() + +function(arm_runner_define_cache_options) + set(one_value_args METHOD_ALLOCATOR_SIZE) + cmake_parse_arguments(ARG "" "${one_value_args}" "" ${ARGN}) + set(ET_PTE_FILE_PATH + "" + CACHE PATH "Path to an ExecuTorch model PTE" + ) + set(ET_MODEL_PTE_ADDR + "" + CACHE STRING "Address of a memory-mapped PTE" + ) + set(ET_MODEL_PTE_SIZE + "" + CACHE STRING "Size in bytes of a memory-mapped PTE" + ) + set(EXECUTORCH_SELECT_OPS_LIST + "" + CACHE STRING "Explicit operator selection" + ) + set(ETHOS_SDK_PATH + "${EXECUTORCH_ROOT}/examples/arm/arm-scratch/ethos-u" + CACHE PATH "Path to the Ethos-U bare-metal SDK" + ) + set(SYSTEM_CONFIG + "Ethos_U55_High_End_Embedded" + CACHE STRING "Ethos-U system configuration" + ) + set(MEMORY_MODE + "Shared_Sram" + CACHE STRING "Ethos-U memory mode" + ) + if(MEMORY_MODE MATCHES "^Dedicated_Sram($|_)") + set(_scratch_size 0x4000000) + else() + set(_scratch_size 0x200000) + endif() + if(NOT DEFINED ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE) + set(ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE + ${_scratch_size} + PARENT_SCOPE + ) + endif() + set(ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE + "${ARG_METHOD_ALLOCATOR_SIZE}" + CACHE STRING "Persistent method allocator size" + ) +endfunction() + +function(arm_runner_validate_model_source) + cmake_parse_arguments(ARG "ALLOW_SEMIHOSTING" "" "" ${ARGN}) + if(NOT (ARG_ALLOW_SEMIHOSTING AND SEMIHOSTING) + AND NOT ET_MODEL_PTE_ADDR + AND "${ET_PTE_FILE_PATH}" STREQUAL "" + ) + message(FATAL_ERROR "Set ET_PTE_FILE_PATH or ET_MODEL_PTE_ADDR.") + endif() + if(NOT "${ET_PTE_FILE_PATH}" STREQUAL "" AND NOT EXISTS "${ET_PTE_FILE_PATH}") + message(FATAL_ERROR "ET_PTE_FILE_PATH does not exist: ${ET_PTE_FILE_PATH}") + endif() + if(ET_MODEL_PTE_ADDR AND NOT ET_MODEL_PTE_SIZE) + message( + WARNING + "ET_MODEL_PTE_SIZE is unset; using the legacy 0x10000000 upper bound." + ) + set(ET_MODEL_PTE_SIZE + 0x10000000 + PARENT_SCOPE + ) + endif() + if(ET_MODEL_PTE_SIZE AND NOT ET_MODEL_PTE_ADDR) + message(FATAL_ERROR "ET_MODEL_PTE_SIZE requires ET_MODEL_PTE_ADDR.") + endif() +endfunction() + +#[[ +Configure how an ExecuTorch model is made available to a runner target. + +Arguments: + TARGET: Existing runner target to configure. + PTE_FILE: PTE file to convert into a generated model_pte.h header. + MODEL_PTE_ADDR: Address of a PTE already present in target memory. This takes + precedence over PTE_FILE. + MODEL_PTE_SIZE: Size in bytes of the PTE at MODEL_PTE_ADDR. If omitted, the + legacy 0x10000000 upper bound is used. + PUBLIC: Propagate the selected model compile definition to dependants. +]] +function(arm_runner_configure_model) + set(options PUBLIC) + set(one_value_args TARGET PTE_FILE MODEL_PTE_ADDR MODEL_PTE_SIZE) + cmake_parse_arguments(ARG "${options}" "${one_value_args}" "" ${ARGN}) + if(NOT ARG_TARGET) + message(FATAL_ERROR "TARGET is required.") + endif() + + if(ARG_PUBLIC) + set(_scope PUBLIC) + else() + set(_scope PRIVATE) + endif() + + if(ARG_MODEL_PTE_ADDR) + target_compile_definitions( + ${ARG_TARGET} ${_scope} ET_MODEL_PTE_ADDR=${ARG_MODEL_PTE_ADDR} + ET_MODEL_PTE_SIZE=${ARG_MODEL_PTE_SIZE} + ) + elseif(NOT "${ARG_PTE_FILE}" STREQUAL "") + if(Python3_EXECUTABLE) + set(_python_executable "${Python3_EXECUTABLE}") + elseif(PYTHON_EXECUTABLE) + set(_python_executable "${PYTHON_EXECUTABLE}") + else() + find_package( + Python3 + COMPONENTS Interpreter + REQUIRED + ) + set(_python_executable "${Python3_EXECUTABLE}") + endif() + set(_model_header "${CMAKE_CURRENT_BINARY_DIR}/model_pte.h") + add_custom_command( + OUTPUT ${_model_header} + COMMAND + ${_python_executable} + ${EXECUTORCH_ROOT}/examples/arm/common/pte_to_header.py --pte + ${ARG_PTE_FILE} --outdir ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${ARG_PTE_FILE} + ) + add_custom_target(${ARG_TARGET}_model_header DEPENDS ${_model_header}) + add_dependencies(${ARG_TARGET} ${ARG_TARGET}_model_header) + target_compile_definitions(${ARG_TARGET} ${_scope} ET_COMPILED_PTE) + endif() +endfunction() + +function(arm_runner_configure_ethos_u_platform) + set(one_value_args SDK_PATH SYSTEM_CONFIG MEMORY_MODE) + cmake_parse_arguments(ARG "" "${one_value_args}" "" ${ARGN}) + if(NOT ARG_SDK_PATH + OR NOT ARG_SYSTEM_CONFIG + OR NOT ARG_MEMORY_MODE + ) + message( + FATAL_ERROR "SDK_PATH, SYSTEM_CONFIG, and MEMORY_MODE are required." + ) + endif() + + arm_ethos_u_default_fetch("${ARG_SDK_PATH}" _fetch_ethos_u_default) + option(FETCH_ETHOS_U_CONTENT "Fetch Ethos-U dependencies" + ${_fetch_ethos_u_default} + ) + arm_ensure_ethos_u_content( + "${ARG_SDK_PATH}" "${EXECUTORCH_ROOT}" ${FETCH_ETHOS_U_CONTENT} + ) + add_corstone_subdirectory(${ARG_SYSTEM_CONFIG} ${ARG_SDK_PATH}) + configure_timing_adapters(${ARG_SYSTEM_CONFIG} ${ARG_MEMORY_MODE}) + foreach(_platform_variable TARGET_BOARD ETHOSU_MODEL ETHOSU_ARENA) + if(DEFINED ${_platform_variable}) + set(${_platform_variable} + "${${_platform_variable}}" + PARENT_SCOPE + ) + endif() + endforeach() + + if(NOT CMAKE_SKIP_INSTALL_RULES AND TARGET ethosu_core_driver) + get_property( + _ethosu_core_driver_exported GLOBAL + PROPERTY ET_ETHOSU_CORE_DRIVER_EXPORTED + ) + if(NOT _ethosu_core_driver_exported) + install( + TARGETS ethosu_core_driver + EXPORT ExecuTorchTargets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + set_property(GLOBAL PROPERTY ET_ETHOSU_CORE_DRIVER_EXPORTED TRUE) + endif() + endif() +endfunction() # Verify that targets required for building the executor runner are present. function(arm_runner_require_baremetal_targets) @@ -197,10 +533,122 @@ function(arm_runner_create_selected_ops_lib) ) endfunction() +function(arm_runner_create_default_selected_ops_libs) + set(one_value_args PREFIX SUFFIX OP_LIST OPS_FROM_MODEL DTYPE_SELECTIVE_BUILD + OUT_LIBS + ) + set(multi_value_args DEPS) + cmake_parse_arguments( + ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN} + ) + if(NOT ARG_PREFIX) + message(FATAL_ERROR "PREFIX is required.") + endif() + + if(ARG_DEPS) + set(_portable_deps ${ARG_DEPS}) + set(_quantized_deps ${ARG_DEPS}) + set(_cortex_m_deps ${ARG_DEPS}) + else() + set(_portable_deps executorch) + set(_quantized_deps executorch_core) + set(_cortex_m_deps executorch) + endif() + + set(_portable_ops "${ARG_PREFIX}_portable_ops${ARG_SUFFIX}") + set(_quantized_ops "${ARG_PREFIX}_quantized_ops${ARG_SUFFIX}") + set(_cortex_m_ops "${ARG_PREFIX}_cortex_m_ops${ARG_SUFFIX}") + + arm_runner_create_selected_ops_lib( + LIB_NAME + ${_portable_ops} + FUNCTIONS_YAML + "${EXECUTORCH_ROOT}/kernels/portable/functions.yaml" + OP_LIST + "${ARG_OP_LIST}" + OPS_FROM_MODEL + "${ARG_OPS_FROM_MODEL}" + DTYPE_SELECTIVE_BUILD + "${ARG_DTYPE_SELECTIVE_BUILD}" + KERNEL_LIBS + portable_kernels + DEPS + ${_portable_deps} + ) + arm_runner_create_selected_ops_lib( + LIB_NAME + ${_quantized_ops} + CUSTOM_OPS_YAML + "${EXECUTORCH_ROOT}/kernels/quantized/quantized.yaml" + OP_LIST + "${ARG_OP_LIST}" + OPS_FROM_MODEL + "${ARG_OPS_FROM_MODEL}" + KERNEL_LIBS + quantized_kernels + DEPS + ${_quantized_deps} + ) + arm_runner_create_selected_ops_lib( + LIB_NAME + ${_cortex_m_ops} + CUSTOM_OPS_YAML + "${EXECUTORCH_ROOT}/backends/cortex_m/ops/operators.yaml" + OP_LIST + "${ARG_OP_LIST}" + OPS_FROM_MODEL + "${ARG_OPS_FROM_MODEL}" + KERNEL_LIBS + cortex_m_kernels + DEPS + ${_cortex_m_deps} + ) + if(ARG_OUT_LIBS) + set(${ARG_OUT_LIBS} + ${_portable_ops} ${_quantized_ops} ${_cortex_m_ops} + PARENT_SCOPE + ) + endif() +endfunction() + # Ensure a runner target emits its binary to a predictable location. Uses # FALLBACK_DIR when TARGET_NAME has no runtime output directory set, and also # fills per-configuration runtime output directories for multi-config generators # when they are unset. +function(arm_runner_link_registration_libraries) + set(one_value_args TARGET SCOPE) + set(multi_value_args BASE_LIBS REGISTRATION_LIBS NORMAL_LIBS SUPPRESS_LIBS) + cmake_parse_arguments( + ARG "" "${one_value_args}" "${multi_value_args}" ${ARGN} + ) + if(NOT ARG_TARGET) + message(FATAL_ERROR "TARGET is required.") + endif() + if(NOT ARG_SCOPE) + set(ARG_SCOPE PRIVATE) + endif() + + foreach(_registration_target IN LISTS ARG_REGISTRATION_LIBS ARG_SUPPRESS_LIBS) + if(TARGET ${_registration_target}) + set_property( + TARGET ${_registration_target} PROPERTY INTERFACE_LINK_OPTIONS "" + ) + endif() + endforeach() + + target_link_libraries( + ${ARG_TARGET} + ${ARG_SCOPE} + -Wl,--start-group + ${ARG_BASE_LIBS} + -Wl,--whole-archive + ${ARG_REGISTRATION_LIBS} + -Wl,--no-whole-archive + ${ARG_NORMAL_LIBS} + -Wl,--end-group + ) +endfunction() + function(arm_runner_configure_runtime_output TARGET_NAME FALLBACK_DIR) if(NOT TARGET ${TARGET_NAME}) return() @@ -246,3 +694,60 @@ function(arm_runner_link_minimal_specs TARGET_NAME) ) endif() endfunction() + +#[[ +Preprocess and attach the Corstone linker script for a runner target. + +Arguments: + TARGET: Existing runner target to configure. + SYSTEM_CONFIG: Ethos-U system configuration used to select the Corstone FVP. + OUTPUT_NAME: Optional basename for the generated linker script. +]] +function(arm_runner_configure_linker_script) + set(one_value_args TARGET SYSTEM_CONFIG OUTPUT_NAME) + cmake_parse_arguments(ARG "" "${one_value_args}" "" ${ARGN}) + + if(NOT ARG_TARGET OR NOT ARG_SYSTEM_CONFIG) + message( + FATAL_ERROR + "arm_runner_configure_linker_script requires TARGET and SYSTEM_CONFIG." + ) + endif() + verify_targets_exist( + CONTEXT arm_runner_configure_linker_script TARGETS ${ARG_TARGET} + ) + + get_corstone_linker_script(_linker_script "${ARG_SYSTEM_CONFIG}") + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(LINK_FILE_EXT ld) + set(LINK_FILE_OPTION "-T") + set(COMPILER_PREPROCESSOR_OPTIONS -E -x c -P) + else() + message( + FATAL_ERROR + "arm_runner_configure_linker_script only supports the GNU compiler." + ) + endif() + + if(NOT ARG_OUTPUT_NAME) + set(ARG_OUTPUT_NAME "${ARG_TARGET}_linker_script") + endif() + set(_linker_script_out + "${CMAKE_CURRENT_BINARY_DIR}/${ARG_OUTPUT_NAME}.${LINK_FILE_EXT}" + ) + set(_preprocessor_options ${COMPILER_PREPROCESSOR_OPTIONS}) + foreach(_define IN ITEMS HEAP_SIZE STACK_SIZE ETHOSU_MODEL ETHOSU_ARENA) + if(DEFINED ${_define}) + list(APPEND _preprocessor_options "-D${_define}=${${_define}}") + endif() + endforeach() + + execute_process( + COMMAND ${CMAKE_C_COMPILER} ${_preprocessor_options} -o + ${_linker_script_out} ${_linker_script} COMMAND_ERROR_IS_FATAL ANY + ) + target_link_options( + ${ARG_TARGET} PRIVATE "${LINK_FILE_OPTION}" "${_linker_script_out}" + ) +endfunction() diff --git a/examples/arm/executor_runner/Corstone-300.ld b/backends/arm/cmake/linker_scripts/Corstone-300.ld similarity index 100% rename from examples/arm/executor_runner/Corstone-300.ld rename to backends/arm/cmake/linker_scripts/Corstone-300.ld diff --git a/examples/arm/executor_runner/Corstone-320.ld b/backends/arm/cmake/linker_scripts/Corstone-320.ld similarity index 100% rename from examples/arm/executor_runner/Corstone-320.ld rename to backends/arm/cmake/linker_scripts/Corstone-320.ld diff --git a/backends/arm/scripts/corstone_utils.cmake b/backends/arm/scripts/corstone_utils.cmake index ca49a1183f7..72a0c27a8c4 100644 --- a/backends/arm/scripts/corstone_utils.cmake +++ b/backends/arm/scripts/corstone_utils.cmake @@ -109,6 +109,23 @@ function(set_ethosu_dedicated_sram_fast_scratch_size OUT_VAR MEMORY_MODE) ) endfunction() +#[[ +Return the linker script used by the Corstone FVP for SYSTEM_CONFIG. +]] +function(get_corstone_linker_script OUT_VAR SYSTEM_CONFIG) + if(SYSTEM_CONFIG MATCHES "Ethos_U55" OR SYSTEM_CONFIG MATCHES "Ethos_U65") + set(_linker_script "Corstone-300.ld") + elseif(SYSTEM_CONFIG MATCHES "Ethos_U85") + set(_linker_script "Corstone-320.ld") + else() + message(FATAL_ERROR "Unsupported SYSTEM_CONFIG ${SYSTEM_CONFIG}.") + endif() + set(${OUT_VAR} + "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../cmake/linker_scripts/${_linker_script}" + PARENT_SCOPE + ) +endfunction() + function(add_corstone_subdirectory SYSTEM_CONFIG ETHOS_SDK_PATH) if(MEMORY_MODE MATCHES "^Dedicated_Sram($|_)") # Both model and scratch in DRAM. diff --git a/examples/arm/executor_runner/arm_memory_allocator.cpp b/examples/arm/common/arm_memory_allocator.cpp similarity index 100% rename from examples/arm/executor_runner/arm_memory_allocator.cpp rename to examples/arm/common/arm_memory_allocator.cpp diff --git a/examples/arm/executor_runner/arm_memory_allocator.h b/examples/arm/common/arm_memory_allocator.h similarity index 100% rename from examples/arm/executor_runner/arm_memory_allocator.h rename to examples/arm/common/arm_memory_allocator.h diff --git a/examples/arm/executor_runner/pte_to_header.py b/examples/arm/common/pte_to_header.py similarity index 100% rename from examples/arm/executor_runner/pte_to_header.py rename to examples/arm/common/pte_to_header.py diff --git a/examples/arm/executor_runner/CMakeLists.txt b/examples/arm/executor_runner/CMakeLists.txt index 5732524d3fb..9c769868984 100644 --- a/examples/arm/executor_runner/CMakeLists.txt +++ b/examples/arm/executor_runner/CMakeLists.txt @@ -47,12 +47,6 @@ if(NOT COMMAND executorch_target_link_options_shared_lib) include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake) endif() -option( - ET_MODEL_PTE_ADDR - "Place in memory that the PTE file is located/flashed, if set to OFF the PTE is built into the code as a big data area." - OFF -) - set(ET_NUM_INFERENCES "1" CACHE STRING "Number of inferences to run" @@ -96,88 +90,19 @@ set(ET_DEBUG_BUFFER_SIZE option(SEMIHOSTING "Enable semihosting" OFF) -option( - ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE - "Set ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE to specify memory alloction pool size" - OFF -) set(ET_ARM_BAREMETAL_PLANNED_FAST_MEMORY_SIZE "" CACHE STRING "Size of the SRAM-backed planned fast memory pool used for mem_id=3" ) -if(NOT DEFINED PYTHON_EXECUTABLE) - find_package( - Python3 - COMPONENTS Interpreter - REQUIRED - ) - set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}") -endif() - -include(${EXECUTORCH_ROOT}/backends/arm/scripts/corstone_utils.cmake) -include(${EXECUTORCH_ROOT}/backends/arm/cmake/ArmEthosUSDK.cmake) include(${EXECUTORCH_ROOT}/backends/arm/cmake/ArmRunnerUtils.cmake) +arm_runner_define_cache_options() +arm_runner_validate_model_source(ALLOW_SEMIHOSTING) +arm_runner_require_python() arm_runner_require_baremetal_targets() -# Keep the default scratch location aligned with the scratch tree used by -# setup.sh/run.sh so developers who just ran those scripts do not need extra -# CMake flags. -set(ETHOS_SDK_PATH - "${EXECUTORCH_ROOT}/examples/arm/arm-scratch/ethos-u" - CACHE PATH "Path to Ethos-U bare metal driver/env" -) - -arm_ethos_u_default_fetch("${ETHOS_SDK_PATH}" _fetch_ethos_u_default) -option(FETCH_ETHOS_U_CONTENT - "Fetch ethos_u dependencies instead of relying on pre-downloads" - ${_fetch_ethos_u_default} -) -arm_ensure_ethos_u_content( - "${ETHOS_SDK_PATH}" "${EXECUTORCH_ROOT}" ${FETCH_ETHOS_U_CONTENT} -) - -set(ET_PTE_FILE_PATH - "" - CACHE PATH "Path to ExecuTorch model pte" -) - -if(NOT ET_MODEL_PTE_ADDR - AND "${ET_PTE_FILE_PATH}" STREQUAL "" - AND NOT SEMIHOSTING -) - message( - FATAL_ERROR - "You must specify one of " - "ET_MODEL_PTE_ADDR - .pte (or .bpte) on address, " - "ET_PTE_FILE_PATH - .pte (or .bpte) built into the binary or " - "SEMIHOSTING - pte and input via host filesystem (use by pytest)" - ) -endif() - -if(NOT ET_MODEL_PTE_ADDR AND NOT "${ET_PTE_FILE_PATH}" STREQUAL "") - if(NOT EXISTS "${ET_PTE_FILE_PATH}") - message( - FATAL_ERROR - "ET_PTE_FILE_PATH is set to ${ET_PTE_FILE_PATH}, but no file was found. Generate the model first or point ET_PTE_FILE_PATH at an existing .pte/.bpte." - ) - endif() -endif() - -# Selects timing adapter values matching system_config. Default is -# Ethos_U55_High_End_Embedded, simulating optimal hardware for the -# Corestone-300. -set(SYSTEM_CONFIG - "Ethos_U55_High_End_Embedded" - CACHE STRING "System config" -) -set(MEMORY_MODE - "Shared_Sram" - CACHE STRING "Vela memory mode" -) - message(STATUS "SYSTEM_CONFIG is ${SYSTEM_CONFIG}") message(STATUS "MEMORY_MODE is ${MEMORY_MODE}") message(STATUS "ET_NUM_INFERENCES is ${ET_NUM_INFERENCES}") @@ -186,18 +111,11 @@ message(STATUS "ET_NUM_INFERENCES is ${ET_NUM_INFERENCES}") # for the temporary scratch buffer and derive the fast scratch buffer size from # the memory mode suffix, e.g. Dedicated_Sram_384KB. Allow -D overrides. if(MEMORY_MODE MATCHES "^Dedicated_Sram($|_)") - if(NOT DEFINED ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE) - set(ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE 0x4000000) - endif() if(NOT DEFINED ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE) set_ethosu_dedicated_sram_fast_scratch_size( ET_ARM_BAREMETAL_FAST_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE "${MEMORY_MODE}" ) endif() -else() - if(NOT DEFINED ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE) - set(ET_ARM_BAREMETAL_SCRATCH_TEMP_ALLOCATOR_POOL_SIZE 0x200000) - endif() endif() message( STATUS @@ -212,134 +130,26 @@ message( "ET_ARM_BAREMETAL_PLANNED_FAST_MEMORY_SIZE = ${ET_ARM_BAREMETAL_PLANNED_FAST_MEMORY_SIZE}" ) -# Dependencies from the Ethos-U Core This is the platform target of -# Corstone-300, that includes ethosu_core_driver and bare-metal bringup -# libraries. We link against ethosu_target_init which includes all of these -# dependencies. -add_corstone_subdirectory(${SYSTEM_CONFIG} ${ETHOS_SDK_PATH}) -configure_timing_adapters(${SYSTEM_CONFIG} ${MEMORY_MODE}) - -if(NOT CMAKE_SKIP_INSTALL_RULES AND TARGET ethosu_core_driver) - get_property( - _et_ethosu_core_driver_exported GLOBAL - PROPERTY ET_ETHOSU_CORE_DRIVER_EXPORTED - ) - if(NOT _et_ethosu_core_driver_exported) - install( - TARGETS ethosu_core_driver - EXPORT ExecuTorchTargets - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) - set_property(GLOBAL PROPERTY ET_ETHOSU_CORE_DRIVER_EXPORTED TRUE) - endif() -endif() - -# Convert pte to header -if(NOT ET_MODEL_PTE_ADDR AND NOT "${ET_PTE_FILE_PATH}" STREQUAL "") - add_custom_target( - gen_model_header DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/model_pte.h - ) - - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/model_pte.h - COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/pte_to_header.py - --pte ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${ET_PTE_FILE_PATH} - ) -endif() +arm_runner_configure_ethos_u_platform( + SDK_PATH "${ETHOS_SDK_PATH}" SYSTEM_CONFIG "${SYSTEM_CONFIG}" MEMORY_MODE + "${MEMORY_MODE}" +) # The arm_executor_runner executable add_executable(arm_executor_runner) target_sources( arm_executor_runner PRIVATE arm_executor_runner.cpp arm_perf_monitor.cpp - arm_memory_allocator.cpp -) - -# Check for "U55" in SYSTEM_CONFIG -string(FIND "${SYSTEM_CONFIG}" "U55" U55_FOUND) - -# Check for "U65" in SYSTEM_CONFIG -string(FIND "${SYSTEM_CONFIG}" "U65" U65_FOUND) - -# Check for "U85" in SYSTEM_CONFIG -string(FIND "${SYSTEM_CONFIG}" "U85" U85_FOUND) - -# Check if neither "U55", "U65" nor "U85" was found -if(U55_FOUND EQUAL -1 - AND U65_FOUND EQUAL -1 - AND U85_FOUND EQUAL -1 -) - message( - FATAL_ERROR - "SYSTEM_CONFIG does not contain 'U55', 'U65' or 'U85'. Configuration aborting." - ) -endif() - -# Proceed with specific actions if either is found -if(NOT U55_FOUND EQUAL -1) - message(STATUS "SYSTEM_CONFIG contains 'U55'.") - set(LINK_FILE_IN "${CMAKE_CURRENT_LIST_DIR}/Corstone-300.ld") -endif() - -if(NOT U65_FOUND EQUAL -1) - message(STATUS "SYSTEM_CONFIG contains 'U65'.") - set(LINK_FILE_IN "${CMAKE_CURRENT_LIST_DIR}/Corstone-300.ld") -endif() - -if(NOT U85_FOUND EQUAL -1) - message(STATUS "SYSTEM_CONFIG contains 'U85'.") - set(LINK_FILE_IN "${CMAKE_CURRENT_LIST_DIR}/Corstone-320.ld") -endif() - -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(LINK_FILE_EXT ld) - set(LINK_FILE_OPTION "-T") - set(COMPILER_PREPROCESSOR_OPTIONS -E -x c -P) -endif() - -set(_arm_runner_linker_preprocessor_options ${COMPILER_PREPROCESSOR_OPTIONS}) -foreach(_arm_runner_linker_define IN ITEMS HEAP_SIZE STACK_SIZE ETHOSU_MODEL - ETHOSU_ARENA -) - if(DEFINED ${_arm_runner_linker_define}) - list(APPEND _arm_runner_linker_preprocessor_options - "-D${_arm_runner_linker_define}=${${_arm_runner_linker_define}}" - ) - endif() -endforeach() - -get_filename_component(LINK_FILE_OUT_BASE "${LINK_FILE}" NAME) -set(LINK_FILE_OUT - "${CMAKE_CURRENT_BINARY_DIR}/${LINK_FILE_OUT_BASE}.${LINK_FILE_EXT}" + ../common/arm_memory_allocator.cpp ) -execute_process( - COMMAND ${CMAKE_C_COMPILER} ${_arm_runner_linker_preprocessor_options} -o - ${LINK_FILE_OUT} ${LINK_FILE_IN} +arm_runner_configure_linker_script( + TARGET arm_executor_runner SYSTEM_CONFIG "${SYSTEM_CONFIG}" ) -target_link_options(arm_executor_runner PRIVATE "-T" "${LINK_FILE_OUT}") if(EXECUTORCH_OPTIMIZE_SIZE) arm_runner_link_minimal_specs(arm_executor_runner) endif() -set(arm_executor_runner_link) -list( - APPEND - arm_executor_runner_link - -Wl,--start-group - extension_runner_util - ethosu_target_init - -Wl,--whole-archive - executorch_delegate_ethos_u - -Wl,--no-whole-archive - executorch_core - -Wl,--end-group - -Xlinker - -Map=arm_executor_runner.map -) - # Create ops libraries from included operators. Handle portable, cortex_m, and # quantized ops. set(_arm_runner_dtype_selective_build @@ -349,38 +159,25 @@ if(NOT ET_PTE_FILE_PATH) set(_arm_runner_dtype_selective_build "") endif() -set(_arm_runner_selected_ops_libs) -set(_arm_runner_normal_archive_libs) - -arm_runner_create_selected_ops_lib( - LIB_NAME - "arm_portable_ops_lib" - FUNCTIONS_YAML - "${EXECUTORCH_ROOT}/kernels/portable/functions.yaml" +arm_runner_create_default_selected_ops_libs( + PREFIX + arm + SUFFIX + _lib OP_LIST "${EXECUTORCH_SELECT_OPS_LIST}" OPS_FROM_MODEL "${ET_PTE_FILE_PATH}" DTYPE_SELECTIVE_BUILD "${_arm_runner_dtype_selective_build}" - KERNEL_LIBS - portable_kernels DEPS executorch_core ) -list(APPEND _arm_runner_selected_ops_libs arm_portable_ops_lib) -set(_arm_runner_portable_archive_libs portable_kernels kernels_util_all_deps) -verify_targets_exist( - CONTEXT arm_executor_runner TARGETS ${_arm_runner_portable_archive_libs} -) -list(APPEND _arm_runner_normal_archive_libs - ${_arm_runner_portable_archive_libs} -) arm_runner_create_selected_ops_lib( PRIM_OPS LIB_NAME - "arm_prim_ops_lib" + arm_prim_ops_lib OP_LIST "${EXECUTORCH_SELECT_OPS_LIST}" OPS_FROM_MODEL @@ -388,87 +185,46 @@ arm_runner_create_selected_ops_lib( DEPS executorch_core ) -list(APPEND _arm_runner_selected_ops_libs arm_prim_ops_lib) -set(_arm_runner_prim_archive_libs arm_prim_ops_lib_impl) -verify_targets_exist( - CONTEXT arm_executor_runner TARGETS ${_arm_runner_prim_archive_libs} -) -list(APPEND _arm_runner_normal_archive_libs ${_arm_runner_prim_archive_libs}) -arm_runner_create_selected_ops_lib( - LIB_NAME - "arm_quantized_ops_lib" - CUSTOM_OPS_YAML - "${EXECUTORCH_ROOT}/kernels/quantized/quantized.yaml" - OP_LIST - "${EXECUTORCH_SELECT_OPS_LIST}" - OPS_FROM_MODEL - "${ET_PTE_FILE_PATH}" - KERNEL_LIBS - quantized_kernels - DEPS - executorch_core +set(_arm_runner_selected_ops_libs arm_portable_ops_lib arm_prim_ops_lib + arm_quantized_ops_lib arm_cortex_m_ops_lib ) -list(APPEND _arm_runner_selected_ops_libs arm_quantized_ops_lib) -set(_arm_runner_quantized_archive_libs quantized_kernels portable_kernels - kernels_util_all_deps +set(_arm_runner_normal_archive_libs + portable_kernels kernels_util_all_deps arm_prim_ops_lib_impl + quantized_kernels cortex_m_kernels cmsis-nn ) verify_targets_exist( - CONTEXT arm_executor_runner TARGETS ${_arm_runner_quantized_archive_libs} -) -list(APPEND _arm_runner_normal_archive_libs - ${_arm_runner_quantized_archive_libs} + CONTEXT arm_executor_runner TARGETS ${_arm_runner_selected_ops_libs} + ${_arm_runner_normal_archive_libs} ) -arm_runner_create_selected_ops_lib( - LIB_NAME - "arm_cortex_m_ops_lib" - CUSTOM_OPS_YAML - "${EXECUTORCH_ROOT}/backends/cortex_m/ops/operators.yaml" - OP_LIST - "${EXECUTORCH_SELECT_OPS_LIST}" - OPS_FROM_MODEL - "${ET_PTE_FILE_PATH}" - KERNEL_LIBS - cortex_m_kernels - DEPS +arm_runner_link_registration_libraries( + TARGET + arm_executor_runner + SCOPE + PUBLIC + BASE_LIBS + extension_runner_util + ethosu_target_init + REGISTRATION_LIBS + executorch_delegate_ethos_u + ${_arm_runner_selected_ops_libs} + NORMAL_LIBS executorch_core + ${_arm_runner_normal_archive_libs} + SUPPRESS_LIBS + executorch ) -list(APPEND _arm_runner_selected_ops_libs arm_cortex_m_ops_lib) -set(_arm_runner_cortex_m_archive_libs cortex_m_kernels portable_kernels - cmsis-nn kernels_util_all_deps -) -verify_targets_exist( - CONTEXT arm_executor_runner TARGETS ${_arm_runner_cortex_m_archive_libs} -) -list(APPEND _arm_runner_normal_archive_libs - ${_arm_runner_cortex_m_archive_libs} -) - -list(FIND arm_executor_runner_link -Wl,--no-whole-archive - _arm_runner_no_whole_archive_idx -) -list(INSERT arm_executor_runner_link ${_arm_runner_no_whole_archive_idx} - ${_arm_runner_selected_ops_libs} -) - -if(_arm_runner_normal_archive_libs) - list(REMOVE_DUPLICATES _arm_runner_normal_archive_libs) - list(FIND arm_executor_runner_link -Wl,--end-group _arm_runner_end_group_idx) - list(INSERT arm_executor_runner_link ${_arm_runner_end_group_idx} - ${_arm_runner_normal_archive_libs} - ) -endif() if(EXECUTORCH_ENABLE_EVENT_TRACER) - target_compile_options(arm_executor_runner PUBLIC -DET_EVENT_TRACER_ENABLED) + target_compile_definitions(arm_executor_runner PUBLIC ET_EVENT_TRACER_ENABLED) - list(APPEND arm_executor_runner_link etdump flatccrt) + target_link_libraries(arm_executor_runner PUBLIC etdump flatccrt) endif() if(ET_BUNDLE_IO) if(TARGET bundled_program) - list(APPEND arm_executor_runner_link bundled_program) + target_link_libraries(arm_executor_runner PUBLIC bundled_program) target_link_directories( arm_executor_runner PRIVATE $ ) @@ -504,7 +260,9 @@ if(ET_BUNDLE_IO) ) endif() if(_bundled_program_library) - list(APPEND arm_executor_runner_link ${_bundled_program_library}) + target_link_libraries( + arm_executor_runner PUBLIC ${_bundled_program_library} + ) else() message( FATAL_ERROR @@ -514,27 +272,6 @@ if(ET_BUNDLE_IO) endif() endif() -# Keep static registration libraries force-loaded, but do it in the executable -# link list rather than through INTERFACE_LINK_OPTIONS. The latter is emitted -# before this target's objects and before the runner's dependency closure, which -# breaks bare-metal archive resolution for the runner. The same needs to be done -# for the executorch target, that can be transitively included from the bundled -# program lib. the executorch lib registers all prim-ops, but we want to include -# them selectively. -set(_suppress_interface_link_options_targets - executorch executorch_delegate_ethos_u ${_arm_runner_selected_ops_libs} -) -foreach(_target_to_suppress IN LISTS _suppress_interface_link_options_targets) - if(TARGET ${_target_to_suppress}) - set_property( - TARGET ${_target_to_suppress} PROPERTY INTERFACE_LINK_OPTIONS "" - ) - endif() -endforeach() - -# Need whole-archive to ensure C++ ctors are called for registration targets. -target_link_libraries(arm_executor_runner PUBLIC ${arm_executor_runner_link}) - # Ensure the ELF lands next to the CMake build tree so run.sh (and downstream # tooling) can locate it deterministically regardless of multi-config vs # single-config generators. @@ -579,26 +316,26 @@ if(CMAKE_BUILD_TYPE MATCHES "AddressSanitizer") endif() # ET headers and generated headers includes -set(_arm_runner_include_dirs - ${ET_INCLUDE_PATH} ${ET_INCLUDE_PATH}/runtime/core/portable_type/c10 - ${CMAKE_CURRENT_BINARY_DIR} -) target_include_directories( - arm_executor_runner PRIVATE ${_arm_runner_include_dirs} + arm_executor_runner + PRIVATE ${ET_INCLUDE_PATH} ${ET_INCLUDE_PATH}/runtime/core/portable_type/c10 + ${EXECUTORCH_ROOT}/examples/arm/common ${CMAKE_CURRENT_BINARY_DIR} ) target_compile_definitions( arm_executor_runner PRIVATE C10_USING_CUSTOM_GENERATED_MACROS ) -if(NOT ET_MODEL_PTE_ADDR AND NOT "${ET_PTE_FILE_PATH}" STREQUAL "") - add_dependencies(arm_executor_runner gen_model_header) -endif() - -if(ET_MODEL_PTE_ADDR) - target_compile_definitions( - arm_executor_runner PUBLIC -DET_MODEL_PTE_ADDR=${ET_MODEL_PTE_ADDR} - ) -endif() +arm_runner_configure_model( + PUBLIC + TARGET + arm_executor_runner + PTE_FILE + "${ET_PTE_FILE_PATH}" + MODEL_PTE_ADDR + "${ET_MODEL_PTE_ADDR}" + MODEL_PTE_SIZE + "${ET_MODEL_PTE_SIZE}" +) if(ET_NUM_INFERENCES) target_compile_definitions( @@ -607,18 +344,18 @@ if(ET_NUM_INFERENCES) endif() if(ET_LOG_DUMP_INPUT) - target_compile_definitions(arm_executor_runner PUBLIC -DET_LOG_DUMP_INPUT) + target_compile_definitions(arm_executor_runner PUBLIC ET_LOG_DUMP_INPUT) endif() if(ET_LOG_DUMP_OUTPUT) - target_compile_definitions(arm_executor_runner PUBLIC -DET_LOG_DUMP_OUTPUT) + target_compile_definitions(arm_executor_runner PUBLIC ET_LOG_DUMP_OUTPUT) endif() # Devtool BundleIO: Use Bundle PTE with input and reference output included to # check if it matches. if(ET_BUNDLE_IO) - target_compile_definitions(arm_executor_runner PUBLIC -DET_BUNDLE_IO) + target_compile_definitions(arm_executor_runner PUBLIC ET_BUNDLE_IO) endif() if(ET_ATOL) @@ -632,12 +369,12 @@ endif() # Devtools ETDump: Speed and dumping output if(ET_DUMP_OUTPUTS) - target_compile_definitions(arm_executor_runner PUBLIC -DET_DUMP_OUTPUTS) + target_compile_definitions(arm_executor_runner PUBLIC ET_DUMP_OUTPUTS) endif() if(ET_DUMP_INTERMEDIATE_OUTPUTS) target_compile_definitions( - arm_executor_runner PUBLIC -DET_DUMP_INTERMEDIATE_OUTPUTS + arm_executor_runner PUBLIC ET_DUMP_INTERMEDIATE_OUTPUTS ) endif() @@ -653,10 +390,6 @@ if(SEMIHOSTING) target_compile_definitions(arm_executor_runner PUBLIC SEMIHOSTING) endif() -if(NOT ET_MODEL_PTE_ADDR AND NOT "${ET_PTE_FILE_PATH}" STREQUAL "") - target_compile_definitions(arm_executor_runner PUBLIC ET_COMPILED_PTE) -endif() - # Memory buffer sizes for Executorch flow if(ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE) diff --git a/examples/arm/executor_runner/arm_executor_runner.cpp b/examples/arm/executor_runner/arm_executor_runner.cpp index 3f20ab2a7ea..0a863a9f074 100644 --- a/examples/arm/executor_runner/arm_executor_runner.cpp +++ b/examples/arm/executor_runner/arm_executor_runner.cpp @@ -13,12 +13,14 @@ * * Some defines used to configure the code: * - * ET_MODEL_PTE_ADDR - Where in memory/flash your PTE model data is, if - * not set the model is supposed to have been converted to - * a c-array named model_pte and put into model_pte.h - * this is placed in network_model_sec linker section - * that is controlled by your memory mode via the - * ETHOSU_MODEL cmake parameter. This is not used by the + * ET_MODEL_PTE_ADDR - Where in memory/flash your PTE model data is. + * ET_MODEL_PTE_SIZE - Size in bytes of the PTE at ET_MODEL_PTE_ADDR. CMake + * defaults to the legacy 0x10000000 upper bound. + * If the address is not set, the model is converted to a + * c-array named model_pte and put into model_pte.h in the + * network_model_sec linker section, controlled by your + * memory mode via the ETHOSU_MODEL cmake parameter. This + * is not used by the * semihosting path, which either loads the model from a * file or can reuse an embedded model with * ET_COMPILED_PTE. @@ -172,6 +174,10 @@ unsigned char __attribute__(( #error "ET_MODEL_PTE_ADDR and ET_COMPILED_PTE are mutually exclusive" #endif +#if defined(ET_MODEL_PTE_ADDR) && !defined(ET_MODEL_PTE_SIZE) +#error "ET_MODEL_PTE_ADDR requires ET_MODEL_PTE_SIZE" +#endif + #if !defined(ET_MODEL_PTE_ADDR) && !defined(ET_COMPILED_PTE) && \ !defined(SEMIHOSTING) #error \ @@ -957,11 +963,11 @@ void log_mem_status(RunnerContext& ctx) { #if defined(ET_MODEL_PTE_ADDR) ET_LOG( Info, - "model_pte_program_size: %lu bytes. (pte size unknown when not baked into elf)", + "model_pte_program_size: %lu bytes.", static_cast(ctx.program_data_len)); ET_LOG( Info, - "model_pte_loaded_size: %lu bytes. (pte size unknown when not baked into elf)", + "model_pte_loaded_size: %lu bytes.", static_cast(ctx.model_data_size)); #else ET_LOG( @@ -1437,10 +1443,9 @@ int main(int argc, const char* argv[]) { #if defined(ET_MODEL_PTE_ADDR) // Read the PTE from a fixed memory/flash address configured via - // -DET_MODEL_PTE_ADDR=
. Since the runner does not know the exact - // size up front, use a large upper bound for the buffer span. + // -DET_MODEL_PTE_ADDR=
and -DET_MODEL_PTE_SIZE=. model_data = reinterpret_cast(ET_MODEL_PTE_ADDR); - model_size = 0x10000000; + model_size = ET_MODEL_PTE_SIZE; #elif defined(ET_COMPILED_PTE) model_data = model_pte; model_size = sizeof(model_pte); diff --git a/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt b/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt index 1a86e9344fa..3ed5acc07ef 100644 --- a/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt +++ b/examples/arm/image_classification_example_ethos_u/runtime/CMakeLists.txt @@ -83,8 +83,7 @@ arm_runner_link_minimal_specs(img_class_example) target_sources( img_class_example - PRIVATE main.cpp - ${CMAKE_SOURCE_DIR}/../../executor_runner/arm_memory_allocator.cpp + PRIVATE main.cpp ${ET_DIR_PATH}/examples/arm/common/arm_memory_allocator.cpp ) arm_runner_create_selected_ops_lib( @@ -125,7 +124,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() set(LINK_FILE_OUT_BASE "platform_linker_script") -set(LINK_FILE_IN "${CMAKE_SOURCE_DIR}/../../executor_runner/Corstone-320.ld") +set(LINK_FILE_IN + "${ET_DIR_PATH}/backends/arm/cmake/linker_scripts/Corstone-320.ld" +) set(LINK_FILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/${LINK_FILE_OUT_BASE}.${LINK_FILE_EXT} ) @@ -153,9 +154,8 @@ target_link_options(img_class_example PRIVATE "-T" "${LINK_FILE_OUT}") # file execute_process( COMMAND - ${PYTHON_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/../../executor_runner/pte_to_header.py --pte - ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} + ${PYTHON_EXECUTABLE} ${ET_DIR_PATH}/examples/arm/common/pte_to_header.py + --pte ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} ) # Convert an RGB image to an array in a .h file @@ -167,5 +167,5 @@ execute_process( target_include_directories( img_class_example PRIVATE ${ET_INCLUDE_PATH} ${ET_DIR_PATH}/runtime/core/portable_type/c10 - ${CMAKE_SOURCE_DIR}/../../executor_runner ${CMAKE_CURRENT_BINARY_DIR} + ${ET_DIR_PATH}/examples/arm/common ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt b/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt index 15676044f92..6f30110b95c 100644 --- a/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt +++ b/examples/arm/mobilesam_prompt_segmentation_example_ethos_u/runtime/CMakeLists.txt @@ -106,8 +106,7 @@ configure_timing_adapters(${SYSTEM_CONFIG} ${MEMORY_MODE}) add_executable(mobilesam_prompt_segmentation_example main.cpp) target_sources( mobilesam_prompt_segmentation_example - PRIVATE main.cpp - ${CMAKE_SOURCE_DIR}/../../executor_runner/arm_memory_allocator.cpp + PRIVATE main.cpp ${ET_DIR_PATH}/examples/arm/common/arm_memory_allocator.cpp ) target_link_libraries( mobilesam_prompt_segmentation_example @@ -178,7 +177,9 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() set(LINK_FILE_OUT_BASE "platform_linker_script") -set(LINK_FILE_IN "${CMAKE_SOURCE_DIR}/../../executor_runner/Corstone-320.ld") +set(LINK_FILE_IN + "${ET_DIR_PATH}/backends/arm/cmake/linker_scripts/Corstone-320.ld" +) set(LINK_FILE_OUT ${CMAKE_CURRENT_BINARY_DIR}/${LINK_FILE_OUT_BASE}.${LINK_FILE_EXT} ) @@ -194,11 +195,10 @@ set(MODEL_PTE_HEADER "${CMAKE_CURRENT_BINARY_DIR}/model_pte.h") add_custom_command( OUTPUT "${MODEL_PTE_HEADER}" COMMAND - ${PYTHON_EXECUTABLE} - ${CMAKE_SOURCE_DIR}/../../executor_runner/pte_to_header.py --pte - ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} + ${PYTHON_EXECUTABLE} ${ET_DIR_PATH}/examples/arm/common/pte_to_header.py + --pte ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ET_PTE_FILE_PATH} - ${CMAKE_SOURCE_DIR}/../../executor_runner/pte_to_header.py + ${ET_DIR_PATH}/examples/arm/common/pte_to_header.py VERBATIM ) set(IMAGE_HEADER "${CMAKE_CURRENT_BINARY_DIR}/image.h") @@ -219,5 +219,5 @@ target_sources( target_include_directories( mobilesam_prompt_segmentation_example PRIVATE ${ET_INCLUDE_PATH} ${ET_DIR_PATH}/runtime/core/portable_type/c10 - ${CMAKE_SOURCE_DIR}/../../executor_runner ${CMAKE_CURRENT_BINARY_DIR} + ${ET_DIR_PATH}/examples/arm/common ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/zephyr/samples/hello-executorch/CMakeLists.txt b/zephyr/samples/hello-executorch/CMakeLists.txt index 06ae15dfbe0..1511bcb2f29 100644 --- a/zephyr/samples/hello-executorch/CMakeLists.txt +++ b/zephyr/samples/hello-executorch/CMakeLists.txt @@ -156,9 +156,8 @@ set(EXECUTORCH_FLATCC_INSTALL_ROOT CACHE PATH "" FORCE ) -set(app_sources - src/arm_executor_runner.cpp - ${EXECUTORCH_DIR}/examples/arm/executor_runner/arm_memory_allocator.cpp +set(app_sources src/arm_executor_runner.cpp + ${EXECUTORCH_DIR}/examples/arm/common/arm_memory_allocator.cpp ) target_sources(app PRIVATE ${app_sources}) @@ -166,12 +165,11 @@ set(_model_pte_header ${CMAKE_CURRENT_BINARY_DIR}/model_pte.h) add_custom_command( OUTPUT ${_model_pte_header} COMMAND - ${Python3_EXECUTABLE} - ${EXECUTORCH_DIR}/examples/arm/executor_runner/pte_to_header.py --pte - ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} --section + ${Python3_EXECUTABLE} ${EXECUTORCH_DIR}/examples/arm/common/pte_to_header.py + --pte ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} --section ${ET_PTE_SECTION} DEPENDS ${ET_PTE_FILE_PATH} - ${EXECUTORCH_DIR}/examples/arm/executor_runner/pte_to_header.py + ${EXECUTORCH_DIR}/examples/arm/common/pte_to_header.py COMMENT "Converting ${ET_PTE_FILE_PATH} to model_pte.h" ) add_custom_target(gen_model_header DEPENDS ${_model_pte_header}) diff --git a/zephyr/samples/hello-executorch/src/arm_executor_runner.cpp b/zephyr/samples/hello-executorch/src/arm_executor_runner.cpp index 0a8cec1d158..3404de55c85 100644 --- a/zephyr/samples/hello-executorch/src/arm_executor_runner.cpp +++ b/zephyr/samples/hello-executorch/src/arm_executor_runner.cpp @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include #include diff --git a/zephyr/samples/mv2-ethosu/CMakeLists.txt b/zephyr/samples/mv2-ethosu/CMakeLists.txt index 20581783598..2f66a5f0114 100644 --- a/zephyr/samples/mv2-ethosu/CMakeLists.txt +++ b/zephyr/samples/mv2-ethosu/CMakeLists.txt @@ -198,9 +198,8 @@ set(EXECUTORCH_FLATCC_INSTALL_ROOT CACHE PATH "" FORCE ) -set(app_sources - src/main.cpp - ${EXECUTORCH_DIR}/examples/arm/executor_runner/arm_memory_allocator.cpp +set(app_sources src/main.cpp + ${EXECUTORCH_DIR}/examples/arm/common/arm_memory_allocator.cpp ) target_sources(app PRIVATE ${app_sources}) @@ -208,12 +207,11 @@ set(_model_pte_header ${CMAKE_CURRENT_BINARY_DIR}/model_pte.h) add_custom_command( OUTPUT ${_model_pte_header} COMMAND - ${Python3_EXECUTABLE} - ${EXECUTORCH_DIR}/examples/arm/executor_runner/pte_to_header.py --pte - ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} --section + ${Python3_EXECUTABLE} ${EXECUTORCH_DIR}/examples/arm/common/pte_to_header.py + --pte ${ET_PTE_FILE_PATH} --outdir ${CMAKE_CURRENT_BINARY_DIR} --section ${ET_PTE_SECTION} DEPENDS ${ET_PTE_FILE_PATH} - ${EXECUTORCH_DIR}/examples/arm/executor_runner/pte_to_header.py + ${EXECUTORCH_DIR}/examples/arm/common/pte_to_header.py COMMENT "Converting ${ET_PTE_FILE_PATH} to model_pte.h" ) add_custom_target(gen_model_header DEPENDS ${_model_pte_header}) diff --git a/zephyr/samples/mv2-ethosu/src/main.cpp b/zephyr/samples/mv2-ethosu/src/main.cpp index 98e94992f14..42bbd9269ef 100644 --- a/zephyr/samples/mv2-ethosu/src/main.cpp +++ b/zephyr/samples/mv2-ethosu/src/main.cpp @@ -8,7 +8,7 @@ * MobileNetV2 Image Classification using ExecuTorch with Ethos-U NPU */ -#include +#include #include #include #include