From 774c7caaaccacfa07b2ba144f1602e640a5edd86 Mon Sep 17 00:00:00 2001 From: Kshitij Sisodia Date: Fri, 12 Apr 2024 11:30:02 +0100 Subject: MLECO-4935: Refactoring user options Refactoring for CMake configuration options to allow target platform to drive their own defaults for certain dependent options. For example, the MPS3 target platform defaults to SSE-300 sub-system while native target doesn't need to worry about sub-system and CMSIS options which it will never use. This allows MPS4 target to default to SSE-315 and set the NPU arch to Arm Ethos-U65 as it should, which otherwise would have had to be explictly specified by the user. A welcome by-product of this is also that the options summary at the end of a successful CMake configuration stage would only include the settings that are actually used by the given target. Change-Id: Ibb7f8233d427cd33f39eeb4c71d88193aa998ebd Signed-off-by: Kshitij Sisodia Tested-by: mlecosys Reviewed-by: Alex Tawse Reviewed-by: Conor Kennedy Signed-off-by: Kshitij Sisodia --- CMakeLists.txt | 19 ++- CMakePresets.json | 2 +- docs/sections/customizing.md | 10 +- scripts/cmake/common_user_options.cmake | 169 --------------------- .../cmake/configuration_options/cmsis_opts.cmake | 41 +++++ .../cmake/configuration_options/common_opts.cmake | 65 ++++++++ .../configuration_options/fvp_test_opts.cmake | 36 +++++ scripts/cmake/configuration_options/npu_opts.cmake | 91 +++++++++++ .../configuration_options/options-preset.json | 71 +++++++++ scripts/cmake/options-preset.json | 71 --------- .../cmake/platforms/mps3/build_configuration.cmake | 28 +++- .../cmake/platforms/mps4/build_configuration.cmake | 28 +++- .../simple_platform/build_configuration.cmake | 14 +- scripts/cmake/source_gen_utils.cmake | 5 +- scripts/cmake/tensorflow.cmake | 160 ------------------- scripts/cmake/tensorflow_lite_micro.cmake | 161 ++++++++++++++++++++ scripts/cmake/util_functions.cmake | 7 +- source/hal/source/components/npu_ta/CMakeLists.txt | 2 +- source/math/CMakeLists.txt | 9 +- 19 files changed, 551 insertions(+), 438 deletions(-) delete mode 100644 scripts/cmake/common_user_options.cmake create mode 100644 scripts/cmake/configuration_options/cmsis_opts.cmake create mode 100644 scripts/cmake/configuration_options/common_opts.cmake create mode 100644 scripts/cmake/configuration_options/fvp_test_opts.cmake create mode 100644 scripts/cmake/configuration_options/npu_opts.cmake create mode 100644 scripts/cmake/configuration_options/options-preset.json delete mode 100644 scripts/cmake/options-preset.json delete mode 100644 scripts/cmake/tensorflow.cmake create mode 100644 scripts/cmake/tensorflow_lite_micro.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c458eb9..65119fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,8 +38,7 @@ set(CMAKE_C_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF) set(SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts) -set(CMAKE_SCRIPTS_DIR ${SCRIPTS_DIR}/cmake) -set(CMAKE_TOOLCHAIN_DIR ${CMAKE_SCRIPTS_DIR}/toolchains) +set(CMAKE_TOOLCHAIN_DIR ${SCRIPTS_DIR}/cmake/toolchains) set(DOWNLOAD_DEP_DIR ${CMAKE_BINARY_DIR}/dependencies) set(DEPENDENCY_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dependencies) set(CORE_PLATFORM_DIR ${DEPENDENCY_ROOT_DIR}/core-platform) @@ -46,8 +46,12 @@ set(CORE_PLATFORM_DIR ${DEPENDENCY_ROOT_DIR}/core-platform) set(RESOURCES_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources_downloaded CACHE PATH "Resources directory") set(HAL_PLATFORM_DIR ${CMAKE_CURRENT_SOURCE_DIR}/source/hal/source/platform) +list(APPEND CMAKE_MODULE_PATH + "${SCRIPTS_DIR}/cmake" + "${SCRIPTS_DIR}/cmake/configuration_options" + "${SCRIPTS_DIR}/cmake/timing_adapter") -include(${CMAKE_SCRIPTS_DIR}/source_gen_utils.cmake) +include(source_gen_utils) enable_testing() @@ -58,7 +62,8 @@ else() message(STATUS "Binary directory: ${CMAKE_BINARY_DIR}") endif() -include(${CMAKE_SCRIPTS_DIR}/common_user_options.cmake) +# Include common configuration options +include(common_opts) # Check if the resources_downloaded needs update check_update_public_resources(${RESOURCES_DIR}) @@ -73,8 +78,6 @@ message(STATUS "Using CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") assert_defined(LOG_LEVEL) assert_defined(TENSORFLOW_SRC_PATH) assert_defined(TARGET_PLATFORM) -assert_defined(TARGET_SUBSYSTEM) -assert_defined(ETHOS_U_NPU_ENABLED) assert_defined(USE_CASE_BUILD) assert_defined(CPU_PROFILE_ENABLED) assert_defined(CMAKE_TOOLCHAIN_FILE) @@ -114,7 +117,7 @@ endif () add_subdirectory(${PROFILER_DIR} ${CMAKE_BINARY_DIR}/profiler) # Include the tensorflow build target -include(${CMAKE_SCRIPTS_DIR}/tensorflow.cmake) +include(tensorflow_lite_micro) # Add the common API library target (tensorflow-lite-micro target is needed) add_subdirectory(${SRC_PATH}/application/api/common ${CMAKE_BINARY_DIR}/api/common) diff --git a/CMakePresets.json b/CMakePresets.json index 0385b04..6c2d053 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -6,7 +6,7 @@ "patch": 0 }, "include": [ - "scripts/cmake/options-preset.json", + "scripts/cmake/configuration_options/options-preset.json", "scripts/cmake/platforms/platforms-preset.json", "scripts/cmake/toolchains/toolchain-preset.json", "source/use_case/usecase-preset.json" diff --git a/docs/sections/customizing.md b/docs/sections/customizing.md index 42be12a..2a946aa 100644 --- a/docs/sections/customizing.md +++ b/docs/sections/customizing.md @@ -536,8 +536,8 @@ However, for clarity, here is the full list of available functions: ## Reading user input from console -The platform package under HAL must provide an implementation for a function `GetLine`. This is then wrapped by HAL to -expose a function called `hal_get_user_input`. +The platform package under HAL must provide an implementation for a function `GetLine`. This is then wrapped by HAL to +expose a function called `hal_get_user_input`. ```C++ char ch_input[128]; @@ -774,9 +774,9 @@ function like this: ```cmake add_linker_script( - ${PARSED_TARGET_NAME} # Target - ${CMAKE_SCRIPTS_DIR}/platforms/mps3 # linker scripts directory path - ${LINKER_SCRIPT_NAME}) # Name of the file without suffix + ${PARSED_TARGET_NAME} # Target + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${TARGET_SUBSYSTEM} # Linker scripts directory path + ${LINKER_SCRIPT_NAME}) # Name of the file without suffix ``` Please see existing platforms sources and build scripts for more details. diff --git a/scripts/cmake/common_user_options.cmake b/scripts/cmake/common_user_options.cmake deleted file mode 100644 index 97e9b40..0000000 --- a/scripts/cmake/common_user_options.cmake +++ /dev/null @@ -1,169 +0,0 @@ -#---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates -# 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 -# -# http://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. -#---------------------------------------------------------------------------- - -#---------------------------------------------------------------------------- -# This file should contain all the common user options for the application -# For use case specific options, see individual usecase.cmake files under -# each example use case. -#---------------------------------------------------------------------------- - -if (NOT DEFINED USER_OPTIONS_INCLUDED) - set(USER_OPTIONS_INCLUDED ON) -else() - return() -endif() - -message(STATUS "Assessing common user options...") - -include(${CMAKE_CURRENT_LIST_DIR}/util_functions.cmake) - -USER_OPTION(LOG_LEVEL "Log level for the application" - LOG_LEVEL_INFO - STRING) - -USER_OPTION(TENSORFLOW_SRC_PATH "Path to the root of the tensor flow directory" - "${DEPENDENCY_ROOT_DIR}/tensorflow" - PATH) - -USER_OPTION(TARGET_PLATFORM "Target platform to execute evaluation application: mps3, simple_platform, native" - mps3 - STRING) - -USER_OPTION(TARGET_SUBSYSTEM "Specify platform target subsystem: sse-300, sse-310 or none" - sse-300 - STRING) - -if (TARGET_PLATFORM STREQUAL native) - set(NPU_AVAILABLE OFF) -else() - set(NPU_AVAILABLE ON) -endif() - -USER_OPTION(ETHOS_U_NPU_ENABLED "If Arm Ethos-U NPU is enabled in the target system." - ${NPU_AVAILABLE} - BOOL) - -USER_OPTION(USE_CASE_BUILD "Optional. Defines the use-case to build from the available sources. By default, all use-cases are built." - all - STRING) - -USER_OPTION(CPU_PROFILE_ENABLED "Output CPU performance profiling information. Should be used only for MPS3 board." - OFF - BOOL) - -USER_OPTION(TENSORFLOW_LITE_MICRO_BUILD_TYPE "TensorFlow Lite Mirco build type (release/debug etc.)" - $,release_with_logs,debug> - STRING) - -USER_OPTION(TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS "Select if TPIP downloads should be cleaned before each build." - OFF - BOOL) - -USER_OPTION(TENSORFLOW_LITE_MICRO_CLEAN_BUILD "Select if clean target should be added to a list of targets" - ON - BOOL) - -USER_OPTION(USE_SINGLE_INPUT "Select if a use case should execute using a default known input file" - OFF - BOOL) - -if (NOT TARGET_PLATFORM STREQUAL native) - - USER_OPTION(CMSIS_SRC_PATH - "Path to CMSIS-5 sources" - "${DEPENDENCY_ROOT_DIR}/cmsis" - PATH) - USER_OPTION(CMSIS_DSP_SRC_PATH - "Path to CMSIS-5 DSP sources" - "${DEPENDENCY_ROOT_DIR}/cmsis-dsp" - PATH) - USER_OPTION(CMSIS_NN_SRC_PATH - "Path to CMSIS-5 NN sources" - "${DEPENDENCY_ROOT_DIR}/cmsis-nn" - PATH) - - # If we need NPU libraries: - if (ETHOS_U_NPU_ENABLED) - USER_OPTION(ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH - "Path to Ethos-U NPU timing adapter sources" - "${DEPENDENCY_ROOT_DIR}/core-platform/drivers/timing_adapter" - PATH - ) - - USER_OPTION(ETHOS_U_NPU_DRIVER_SRC_PATH - "Path to Ethos-U NPU core driver sources" - "${DEPENDENCY_ROOT_DIR}/core-driver" - PATH - ) - - USER_OPTION(ETHOS_U_NPU_ID "Arm Ethos-U NPU IP (U55 or U65)" - "U55" - STRING) - - if ((ETHOS_U_NPU_ID STREQUAL U55) OR (ETHOS_U_NPU_ID STREQUAL U65)) - if (ETHOS_U_NPU_ID STREQUAL U55) - set(DEFAULT_NPU_MEM_MODE "Shared_Sram") - set(DEFAULT_NPU_CONFIG_ID "H128") - elseif(ETHOS_U_NPU_ID STREQUAL U65) - set(DEFAULT_NPU_MEM_MODE "Dedicated_Sram") - set(DEFAULT_NPU_CONFIG_ID "Y256") - set(DEFAULT_NPU_CACHE_SIZE "393216") - - USER_OPTION(ETHOS_U_NPU_CACHE_SIZE "Arm Ethos-U65 NPU Cache Size" - "${DEFAULT_NPU_CACHE_SIZE}" - STRING) - endif() - else () - message(FATAL_ERROR "Non compatible Ethos-U NPU processor ${ETHOS_U_NPU_ID}") - endif () - - USER_OPTION(ETHOS_U_NPU_MEMORY_MODE "Specifies the memory mode used in the Vela command." - "${DEFAULT_NPU_MEM_MODE}" - STRING) - - USER_OPTION(ETHOS_U_NPU_CONFIG_ID "Specifies the configuration ID for the NPU." - "${DEFAULT_NPU_CONFIG_ID}" - STRING) - - if (ETHOS_U_NPU_ID STREQUAL U55) - set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_CURRENT_LIST_DIR}/timing_adapter/ta_config_u55_high_end.cmake") - else () - set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_CURRENT_LIST_DIR}/timing_adapter/ta_config_u65_high_end.cmake") - endif () - - USER_OPTION(ETHOS_U_NPU_TIMING_ADAPTER_ENABLED "Specifies if the Ethos-U timing adapter is enabled" - ON - BOOL) - - if (ETHOS_U_NPU_TIMING_ADAPTER_ENABLED) - USER_OPTION(TA_CONFIG_FILE "Path to the timing adapter configuration file" - ${DEFAULT_TA_CONFIG_FILE_PATH} - FILEPATH) - endif() - - USER_OPTION(BUILD_FVP_TESTS "Build tests for CTest driven FVP runs for built applications" - OFF - BOOL) - - if (BUILD_FVP_TESTS) - USER_OPTION(FVP_PATH "Path to FVP for verifying execution" - "" - FILEPATH) - endif() - - endif() -endif() diff --git a/scripts/cmake/configuration_options/cmsis_opts.cmake b/scripts/cmake/configuration_options/cmsis_opts.cmake new file mode 100644 index 0000000..86eedbc --- /dev/null +++ b/scripts/cmake/configuration_options/cmsis_opts.cmake @@ -0,0 +1,41 @@ +#---------------------------------------------------------------------------- +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its +# affiliates +# 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 +# +# http://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. +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# CMSIS configuration options +#---------------------------------------------------------------------------- +include_guard() + +include(util_functions) + +message(STATUS "Assessing CMSIS configuration options...") + +USER_OPTION(CMSIS_SRC_PATH + "Path to CMSIS-5 sources" + "${DEPENDENCY_ROOT_DIR}/cmsis" + PATH) + +USER_OPTION(CMSIS_DSP_SRC_PATH + "Path to CMSIS-5 DSP sources" + "${DEPENDENCY_ROOT_DIR}/cmsis-dsp" + PATH) + +USER_OPTION(CMSIS_NN_SRC_PATH + "Path to CMSIS-5 NN sources" + "${DEPENDENCY_ROOT_DIR}/cmsis-nn" + PATH) diff --git a/scripts/cmake/configuration_options/common_opts.cmake b/scripts/cmake/configuration_options/common_opts.cmake new file mode 100644 index 0000000..52c254e --- /dev/null +++ b/scripts/cmake/configuration_options/common_opts.cmake @@ -0,0 +1,65 @@ +#---------------------------------------------------------------------------- +# SPDX-FileCopyrightText: Copyright 2021-2022, 2024 Arm Limited and/or its +# affiliates +# 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 +# +# http://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. +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# This file should contain all the common user options for the application +# For use case specific options, see individual usecase.cmake files under +# each example use case. +#---------------------------------------------------------------------------- +include_guard() + +message(STATUS "Assessing common user options...") + +include(util_functions) + +USER_OPTION(LOG_LEVEL "Log level for the application" + LOG_LEVEL_INFO + STRING) + +## TensorFlow options +USER_OPTION(TENSORFLOW_SRC_PATH "Path to the root of the TensorFlow Lite Micro sources" + "${DEPENDENCY_ROOT_DIR}/tensorflow" + PATH) + +USER_OPTION(TENSORFLOW_LITE_MICRO_BUILD_TYPE "TensorFlow Lite Mirco build type (release/debug etc.)" + $,release_with_logs,debug> + STRING) + +USER_OPTION(TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS "Select if TPIP downloads should be cleaned before each build." + OFF + BOOL) + +USER_OPTION(TENSORFLOW_LITE_MICRO_CLEAN_BUILD "Select if clean target should be added to a list of targets" + ON + BOOL) + +USER_OPTION(TARGET_PLATFORM "Target platform to build for: mps3, mps4, simple_platform and native" + mps3 + STRING) + +USER_OPTION(USE_CASE_BUILD "Optional. Defines the use-case to build from the available sources. By default, all use-cases are built." + all + STRING) + +USER_OPTION(CPU_PROFILE_ENABLED "Output CPU performance profiling information. Should be used only for MPS3 board." + OFF + BOOL) + +USER_OPTION(USE_SINGLE_INPUT "Select if a use case should execute using a default known input file" + OFF + BOOL) diff --git a/scripts/cmake/configuration_options/fvp_test_opts.cmake b/scripts/cmake/configuration_options/fvp_test_opts.cmake new file mode 100644 index 0000000..91e8588 --- /dev/null +++ b/scripts/cmake/configuration_options/fvp_test_opts.cmake @@ -0,0 +1,36 @@ +#---------------------------------------------------------------------------- +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its +# affiliates +# 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 +# +# http://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. +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# FVP test configuration options +#---------------------------------------------------------------------------- +include_guard() + +include(util_functions) + +message(STATUS "Assessing FVP test configuration options...") + +USER_OPTION(BUILD_FVP_TESTS "Build tests for CTest driven FVP runs for built applications" + OFF + BOOL) + +if (BUILD_FVP_TESTS) + USER_OPTION(FVP_PATH "Path to FVP for verifying execution" + "" + FILEPATH) +endif() \ No newline at end of file diff --git a/scripts/cmake/configuration_options/npu_opts.cmake b/scripts/cmake/configuration_options/npu_opts.cmake new file mode 100644 index 0000000..dc0123b --- /dev/null +++ b/scripts/cmake/configuration_options/npu_opts.cmake @@ -0,0 +1,91 @@ +#---------------------------------------------------------------------------- +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its +# affiliates +# 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 +# +# http://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. +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# NPU configuration user options +#---------------------------------------------------------------------------- +include_guard() + +include(util_functions) + +USER_OPTION(ETHOS_U_NPU_ENABLED "If Arm Ethos-U NPU is enabled in the target system." + ON + BOOL) + +if (NOT ETHOS_U_NPU_ENABLED) + return() +endif() + +message(STATUS "Assessing NPU configuration options...") + +USER_OPTION(ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH + "Path to Ethos-U NPU timing adapter sources" + "${DEPENDENCY_ROOT_DIR}/core-platform/drivers/timing_adapter" + PATH +) + +USER_OPTION(ETHOS_U_NPU_DRIVER_SRC_PATH + "Path to Ethos-U NPU core driver sources" + "${DEPENDENCY_ROOT_DIR}/core-driver" + PATH +) + +USER_OPTION(ETHOS_U_NPU_ID "Arm Ethos-U NPU IP (U55 or U65)" + "U55" + STRING) + +if ((ETHOS_U_NPU_ID STREQUAL U55) OR (ETHOS_U_NPU_ID STREQUAL U65)) + if (ETHOS_U_NPU_ID STREQUAL U55) + set(DEFAULT_NPU_MEM_MODE "Shared_Sram") + set(DEFAULT_NPU_CONFIG_ID "H128") + elseif(ETHOS_U_NPU_ID STREQUAL U65) + set(DEFAULT_NPU_MEM_MODE "Dedicated_Sram") + set(DEFAULT_NPU_CONFIG_ID "Y256") + set(DEFAULT_NPU_CACHE_SIZE "393216") + + USER_OPTION(ETHOS_U_NPU_CACHE_SIZE "Arm Ethos-U65 NPU Cache Size" + "${DEFAULT_NPU_CACHE_SIZE}" + STRING) + endif() +else () + message(FATAL_ERROR "Non compatible Ethos-U NPU processor ${ETHOS_U_NPU_ID}") +endif () + +USER_OPTION(ETHOS_U_NPU_MEMORY_MODE "Specifies the memory mode used in the Vela command." + "${DEFAULT_NPU_MEM_MODE}" + STRING) + +USER_OPTION(ETHOS_U_NPU_CONFIG_ID "Specifies the configuration ID for the NPU." + "${DEFAULT_NPU_CONFIG_ID}" + STRING) + +if (ETHOS_U_NPU_ID STREQUAL U55) + set(DEFAULT_TA_CONFIG_FILE "ta_config_u55_high_end") +else () + set(DEFAULT_TA_CONFIG_FILE "ta_config_u65_high_end") +endif () + +USER_OPTION(ETHOS_U_NPU_TIMING_ADAPTER_ENABLED "Specifies if the Ethos-U timing adapter is enabled" + ON + BOOL) + +if (ETHOS_U_NPU_TIMING_ADAPTER_ENABLED) + USER_OPTION(TA_CONFIG_FILE "Path to the timing adapter configuration file" + ${DEFAULT_TA_CONFIG_FILE} + STRING) +endif() diff --git a/scripts/cmake/configuration_options/options-preset.json b/scripts/cmake/configuration_options/options-preset.json new file mode 100644 index 0000000..57b7a7d --- /dev/null +++ b/scripts/cmake/configuration_options/options-preset.json @@ -0,0 +1,71 @@ +{ + "version": 4, + "cmakeMinimumRequired": { + "major": 3, + "minor": 23, + "patch": 0 + }, + "configurePresets": [ + { + "name": "log-trace", + "hidden": true, + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "LOG_LEVEL_TRACE" + } + } + }, + { + "name": "log-debug", + "hidden": true, + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "LOG_LEVEL_DEBUG" + } + } + }, + { + "name": "log-info", + "hidden": true, + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "LOG_LEVEL_INFO" + } + } + }, + { + "name": "log-warning", + "hidden": true, + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "LOG_LEVEL_WARN" + } + } + }, + { + "name": "log-error", + "hidden": true, + "cacheVariables": { + "LOG_LEVEL": { + "type": "STRING", + "value": "LOG_LEVEL_ERROR" + } + } + }, + { + "name": "single-input", + "hidden": true, + "description": "Use single default input data for each use case.", + "cacheVariables": { + "USE_SINGLE_INPUT": { + "type": "BOOL", + "value": "TRUE" + } + } + } + ] +} \ No newline at end of file diff --git a/scripts/cmake/options-preset.json b/scripts/cmake/options-preset.json deleted file mode 100644 index 57b7a7d..0000000 --- a/scripts/cmake/options-preset.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "version": 4, - "cmakeMinimumRequired": { - "major": 3, - "minor": 23, - "patch": 0 - }, - "configurePresets": [ - { - "name": "log-trace", - "hidden": true, - "cacheVariables": { - "LOG_LEVEL": { - "type": "STRING", - "value": "LOG_LEVEL_TRACE" - } - } - }, - { - "name": "log-debug", - "hidden": true, - "cacheVariables": { - "LOG_LEVEL": { - "type": "STRING", - "value": "LOG_LEVEL_DEBUG" - } - } - }, - { - "name": "log-info", - "hidden": true, - "cacheVariables": { - "LOG_LEVEL": { - "type": "STRING", - "value": "LOG_LEVEL_INFO" - } - } - }, - { - "name": "log-warning", - "hidden": true, - "cacheVariables": { - "LOG_LEVEL": { - "type": "STRING", - "value": "LOG_LEVEL_WARN" - } - } - }, - { - "name": "log-error", - "hidden": true, - "cacheVariables": { - "LOG_LEVEL": { - "type": "STRING", - "value": "LOG_LEVEL_ERROR" - } - } - }, - { - "name": "single-input", - "hidden": true, - "description": "Use single default input data for each use case.", - "cacheVariables": { - "USE_SINGLE_INPUT": { - "type": "BOOL", - "value": "TRUE" - } - } - } - ] -} \ No newline at end of file diff --git a/scripts/cmake/platforms/mps3/build_configuration.cmake b/scripts/cmake/platforms/mps3/build_configuration.cmake index 1743253..101abdd 100644 --- a/scripts/cmake/platforms/mps3/build_configuration.cmake +++ b/scripts/cmake/platforms/mps3/build_configuration.cmake @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +19,21 @@ function(set_platform_global_defaults) message(STATUS "Platform: MPS3 FPGA Prototyping Board or FVP") + # Set default subsystem for MPS3: + USER_OPTION(TARGET_SUBSYSTEM "Specify platform target subsystem: sse-300 or sse-310" + sse-300 + STRING) + + # Default NPU for SSE-300 target: + USER_OPTION(ETHOS_U_NPU_ID "Arm Ethos-U NPU IP (U55 or U65)" + "U55" + STRING) + + # Include NPU, FVP tests and CMSIS configuration options + include(npu_opts) + include(fvp_test_opts) + include(cmsis_opts) + if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) if (TARGET_SUBSYSTEM STREQUAL sse-300) set(CMAKE_SYSTEM_PROCESSOR cortex-m55 CACHE STRING "Cortex-M CPU to use") @@ -61,13 +77,13 @@ function(platform_custom_post_build) # Add link options for the linker script to be used: add_linker_script( - ${PARSED_TARGET_NAME} # Target - ${CMAKE_SCRIPTS_DIR}/platforms/mps3/${TARGET_SUBSYSTEM} # Directory path - ${LINKER_SCRIPT_NAME}) # Name of the file without suffix + ${PARSED_TARGET_NAME} # Target + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${TARGET_SUBSYSTEM} # Directory path + ${LINKER_SCRIPT_NAME}) # Name of the file without suffix add_target_map_file( - ${PARSED_TARGET_NAME} - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map) + ${PARSED_TARGET_NAME} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map) set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) diff --git a/scripts/cmake/platforms/mps4/build_configuration.cmake b/scripts/cmake/platforms/mps4/build_configuration.cmake index 3a3966d..918091a 100644 --- a/scripts/cmake/platforms/mps4/build_configuration.cmake +++ b/scripts/cmake/platforms/mps4/build_configuration.cmake @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +19,21 @@ function(set_platform_global_defaults) message(STATUS "Platform: Arm MPS4 FPGA Prototyping Board or FVP") + # Default sub-system for MPS4 + USER_OPTION(TARGET_SUBSYSTEM "Specify platform target subsystem: sse-315" + sse-315 + STRING) + + # Default NPU for SSE-315 target: + USER_OPTION(ETHOS_U_NPU_ID "Arm Ethos-U NPU IP (U55 or U65)" + "U65" + STRING) + + # Include NPU, FVP tests and CMSIS configuration options + include(npu_opts) + include(fvp_test_opts) + include(cmsis_opts) + if (NOT DEFINED CMAKE_SYSTEM_PROCESSOR) if(TARGET_SUBSYSTEM STREQUAL sse-315) set(CMAKE_SYSTEM_PROCESSOR cortex-m85 CACHE STRING "Cortex-M CPU to use") @@ -52,13 +68,13 @@ function(platform_custom_post_build) # Add link options for the linker script to be used: add_linker_script( - ${PARSED_TARGET_NAME} # Target - ${CMAKE_SCRIPTS_DIR}/platforms/mps4/${TARGET_SUBSYSTEM} # Directory path - ${LINKER_SCRIPT_NAME}) # Name of the file without suffix + ${PARSED_TARGET_NAME} # Target + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${TARGET_SUBSYSTEM} # Directory path + ${LINKER_SCRIPT_NAME}) # Name of the file without suffix add_target_map_file( - ${PARSED_TARGET_NAME} - ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map) + ${PARSED_TARGET_NAME} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PARSED_TARGET_NAME}.map) set(SECTORS_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sectors) set(SECTORS_BIN_DIR ${SECTORS_DIR}/${use_case}) diff --git a/scripts/cmake/platforms/simple_platform/build_configuration.cmake b/scripts/cmake/platforms/simple_platform/build_configuration.cmake index 3536c5b..07c9e05 100644 --- a/scripts/cmake/platforms/simple_platform/build_configuration.cmake +++ b/scripts/cmake/platforms/simple_platform/build_configuration.cmake @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022-2023 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,6 +18,11 @@ function(set_platform_global_defaults) message(STATUS "Platform: Simple platform with minimal peripherals") + + # Include NPU and CMSIS configuration options + include(npu_opts) + include(cmsis_opts) + if (NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(CMAKE_TOOLCHAIN_FILE ${CMAKE_TOOLCHAIN_DIR}/bare-metal-gcc.cmake CACHE FILEPATH "Toolchain file") @@ -41,9 +47,9 @@ function(platform_custom_post_build) # Add link options for the linker script to be used: add_linker_script( - ${PARSED_TARGET_NAME} # Target - ${CMAKE_SCRIPTS_DIR}/platforms/simple_platform # Directory path - ${LINKER_SCRIPT_NAME}) # Name of the file without suffix + ${PARSED_TARGET_NAME} # Target + ${CMAKE_CURRENT_FUNCTION_LIST_DIR} # Directory path + ${LINKER_SCRIPT_NAME}) # Name of the file without suffix add_target_map_file( ${PARSED_TARGET_NAME} diff --git a/scripts/cmake/source_gen_utils.cmake b/scripts/cmake/source_gen_utils.cmake index 6287cb6..3406615 100644 --- a/scripts/cmake/source_gen_utils.cmake +++ b/scripts/cmake/source_gen_utils.cmake @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2021, 2024 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -14,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. #---------------------------------------------------------------------------- +include_guard() + set(SCRIPTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts) ############################################################################## diff --git a/scripts/cmake/tensorflow.cmake b/scripts/cmake/tensorflow.cmake deleted file mode 100644 index 0fa0f8c..0000000 --- a/scripts/cmake/tensorflow.cmake +++ /dev/null @@ -1,160 +0,0 @@ -#---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates -# 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 -# -# http://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. -#---------------------------------------------------------------------------- - -if (DEFINED ENV{CMAKE_BUILD_PARALLEL_LEVEL}) - set(PARALLEL_JOBS $ENV{CMAKE_BUILD_PARALLEL_LEVEL}) -else() - include(ProcessorCount) - ProcessorCount(PARALLEL_JOBS) -endif() - -if (CMAKE_BUILD_TYPE STREQUAL Debug) - set(TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL "-O0") - set(TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL "-O0") -elseif (CMAKE_BUILD_TYPE STREQUAL Release) - set(TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL "-Ofast") - set(TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL "-Ofast") -endif() - -assert_defined(TENSORFLOW_LITE_MICRO_BUILD_TYPE) -assert_defined(TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS) -assert_defined(TENSORFLOW_LITE_MICRO_CLEAN_BUILD) - -if (CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang") - set(TENSORFLOW_LITE_MICRO_TOOLCHAIN "armclang") -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(TENSORFLOW_LITE_MICRO_TOOLCHAIN "gcc") -else () - message(FATAL_ERROR "No compiler ID is set") -endif() - -get_filename_component(TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT ${CMAKE_C_COMPILER} DIRECTORY) -set(TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT "${TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT}/") - -set(TENSORFLOW_LITE_MICRO_PATH "${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro") -set(TENSORFLOW_LITE_MICRO_GENDIR ${CMAKE_CURRENT_BINARY_DIR}/tensorflow/) -set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") - -# Add virtual environment's Python directory path to the system path. -# NOTE: This path is passed to the TensorFlow Lite Micro's make env -# as it depends on some basic Python packages (like Pillow) installed -# and the system-wide Python installation might not have them. -set(ENV_PATH "${PYTHON_VENV}/bin:$ENV{PATH}") - -if (TARGET_PLATFORM STREQUAL native) - set(TENSORFLOW_LITE_MICRO_TARGET "linux") - set(TENSORFLOW_LITE_MICRO_TARGET_ARCH x86_64) -else() - set(TENSORFLOW_LITE_MICRO_TARGET "cortex_m_generic") - - if ("${CMAKE_SYSTEM_ARCH}" STREQUAL "armv8.1-m.main") - set(TENSORFLOW_LITE_MICRO_TARGET_ARCH "cortex-m55") - else() - set(TENSORFLOW_LITE_MICRO_TARGET_ARCH "${CMAKE_SYSTEM_PROCESSOR}") - endif() - - if(ETHOS_U_NPU_ENABLED) - # Arm Ethos-U55 NPU is the co-processor for ML workload: - set(TENSORFLOW_LITE_MICRO_CO_PROCESSOR "ethos_u") - set(ETHOS_U_NPU_ID "u55") # Currently only u55 is supported by TFLite Micro. - endif() - - set(TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL "cmsis_nn") -endif() - -if (TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS) - message(STATUS "Refreshing TensorFlow Lite Micro's third party downloads...") - set(ENV{PATH} "${ENV_PATH}") - execute_process( - COMMAND - make -f ${TENSORFLOW_LITE_MICRO_PATH}/tools/make/Makefile clean_downloads third_party_downloads - RESULT_VARIABLE return_code - WORKING_DIRECTORY ${TENSORFLOW_SRC_PATH}) - if (NOT return_code EQUAL "0") - message(FATAL_ERROR "Failed to clean TensorFlow Lite Micro's third party downloads.") - else() - message(STATUS "Refresh completed.") - endif () -endif() - -if (TENSORFLOW_LITE_MICRO_CLEAN_BUILD) - list(APPEND MAKE_TARGETS_LIST "clean") -endif() - -# Primary target -list(APPEND MAKE_TARGETS_LIST "microlite") -message(STATUS "TensorFlow Lite Micro build to be called for these targets: ${MAKE_TARGETS_LIST}") - -# Commands and targets -add_custom_target(tensorflow_build ALL - - # Command to build the TensorFlow Lite Micro library - COMMAND ${CMAKE_COMMAND} -E env PATH="${ENV_PATH}" - make -j${PARALLEL_JOBS} -f ${TENSORFLOW_LITE_MICRO_PATH}/tools/make/Makefile ${MAKE_TARGETS_LIST} - TARGET_TOOLCHAIN_ROOT=${TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT} - TOOLCHAIN=${TENSORFLOW_LITE_MICRO_TOOLCHAIN} - GENDIR=${TENSORFLOW_LITE_MICRO_GENDIR} - TARGET=${TENSORFLOW_LITE_MICRO_TARGET} - TARGET_ARCH=${TENSORFLOW_LITE_MICRO_TARGET_ARCH} - BUILD_TYPE=${TENSORFLOW_LITE_MICRO_BUILD_TYPE} - CMSIS_PATH=${CMSIS_SRC_PATH} - CMSIS_NN_PATH=${CMSIS_NN_SRC_PATH} - # Conditional arguments - $<$:ETHOSU_ARCH=${ETHOS_U_NPU_ID}> - $<$:ETHOSU_DRIVER_PATH=${ETHOS_U_NPU_DRIVER_SRC_PATH}> - $<$:ETHOSU_DRIVER_LIBS=$> - - $<$:CORE_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL}> - $<$:KERNEL_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL}> - $<$:THIRD_PARTY_KERNEL_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL}> - $<$:OPTIMIZED_KERNEL_DIR=${TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL}> - $<$:CO_PROCESSOR=${TENSORFLOW_LITE_MICRO_CO_PROCESSOR}> - - # Command to copy over the generated library to the local build tree. - COMMAND ${CMAKE_COMMAND} -E copy ${TENSORFLOW_LITE_MICRO_GENDIR}/lib/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} - ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} - - COMMENT "Building TensorFlow Lite Micro library..." - - BYPRODUCTS ${TENSORFLOW_SRC_PATH}/tensorflow/tensorflow/lite/micro/tools/make/downloads - ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} - ${TENSORFLOW_LITE_MICRO_GENDIR}/lib/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} - - WORKING_DIRECTORY ${TENSORFLOW_SRC_PATH}) - -# Create library - - -set(TENSORFLOW_LITE_MICRO_TARGET tensorflow-lite-micro) -add_library(${TENSORFLOW_LITE_MICRO_TARGET} STATIC IMPORTED) - -if(ETHOS_U_NPU_ENABLED) - add_dependencies(tensorflow_build ethosu_core_driver) -endif() - -add_dependencies(tensorflow-lite-micro tensorflow_build) - -set_property(TARGET tensorflow-lite-micro PROPERTY IMPORTED_LOCATION - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME}") - -target_include_directories(tensorflow-lite-micro - INTERFACE - ${TENSORFLOW_SRC_PATH}) - -target_compile_definitions(tensorflow-lite-micro - INTERFACE - TF_LITE_STATIC_MEMORY) diff --git a/scripts/cmake/tensorflow_lite_micro.cmake b/scripts/cmake/tensorflow_lite_micro.cmake new file mode 100644 index 0000000..cb45274 --- /dev/null +++ b/scripts/cmake/tensorflow_lite_micro.cmake @@ -0,0 +1,161 @@ +#---------------------------------------------------------------------------- +# SPDX-FileCopyrightText: Copyright 2021-2024 Arm Limited and/or its +# affiliates +# 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 +# +# http://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. +#---------------------------------------------------------------------------- + +if (DEFINED ENV{CMAKE_BUILD_PARALLEL_LEVEL}) + set(PARALLEL_JOBS $ENV{CMAKE_BUILD_PARALLEL_LEVEL}) +else() + include(ProcessorCount) + ProcessorCount(PARALLEL_JOBS) +endif() + +if (CMAKE_BUILD_TYPE STREQUAL Debug) + set(TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL "-O0") + set(TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL "-O0") +elseif (CMAKE_BUILD_TYPE STREQUAL Release) + set(TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL "-Ofast") + set(TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL "-Ofast") +endif() + +assert_defined(TENSORFLOW_LITE_MICRO_BUILD_TYPE) +assert_defined(TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS) +assert_defined(TENSORFLOW_LITE_MICRO_CLEAN_BUILD) + +if (CMAKE_CXX_COMPILER_ID STREQUAL "ARMClang") + set(TENSORFLOW_LITE_MICRO_TOOLCHAIN "armclang") +elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(TENSORFLOW_LITE_MICRO_TOOLCHAIN "gcc") +else () + message(FATAL_ERROR "No compiler ID is set") +endif() + +get_filename_component(TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT ${CMAKE_C_COMPILER} DIRECTORY) +set(TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT "${TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT}/") + +set(TENSORFLOW_LITE_MICRO_PATH "${TENSORFLOW_SRC_PATH}/tensorflow/lite/micro") +set(TENSORFLOW_LITE_MICRO_GENDIR ${CMAKE_CURRENT_BINARY_DIR}/tensorflow/) +set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a") + +# Add virtual environment's Python directory path to the system path. +# NOTE: This path is passed to the TensorFlow Lite Micro's make env +# as it depends on some basic Python packages (like Pillow) installed +# and the system-wide Python installation might not have them. +set(ENV_PATH "${PYTHON_VENV}/bin:$ENV{PATH}") + +if (TARGET_PLATFORM STREQUAL native) + set(TENSORFLOW_LITE_MICRO_TARGET "linux") + set(TENSORFLOW_LITE_MICRO_TARGET_ARCH x86_64) +else() + set(TENSORFLOW_LITE_MICRO_TARGET "cortex_m_generic") + + if ("${CMAKE_SYSTEM_ARCH}" STREQUAL "armv8.1-m.main") + set(TENSORFLOW_LITE_MICRO_TARGET_ARCH "cortex-m55") + else() + set(TENSORFLOW_LITE_MICRO_TARGET_ARCH "${CMAKE_SYSTEM_PROCESSOR}") + endif() + + if(ETHOS_U_NPU_ENABLED) + # Arm Ethos-U55 NPU is the co-processor for ML workload: + set(TENSORFLOW_LITE_MICRO_CO_PROCESSOR "ethos_u") + set(TENSORFLOW_LITE_MICRO_CO_PROCESSOR_ARCH "u55") # Currently only u55 is supported by TFLite Micro. + endif() + + set(TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL "cmsis_nn") +endif() + +if (TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS) + message(STATUS "Refreshing TensorFlow Lite Micro's third party downloads...") + set(ENV{PATH} "${ENV_PATH}") + execute_process( + COMMAND + make -f ${TENSORFLOW_LITE_MICRO_PATH}/tools/make/Makefile clean_downloads third_party_downloads + RESULT_VARIABLE return_code + WORKING_DIRECTORY ${TENSORFLOW_SRC_PATH}) + if (NOT return_code EQUAL "0") + message(FATAL_ERROR "Failed to clean TensorFlow Lite Micro's third party downloads.") + else() + message(STATUS "Refresh completed.") + endif () +endif() + +if (TENSORFLOW_LITE_MICRO_CLEAN_BUILD) + list(APPEND MAKE_TARGETS_LIST "clean") +endif() + +# Primary target +list(APPEND MAKE_TARGETS_LIST "microlite") +message(STATUS "TensorFlow Lite Micro build to be called for these targets: ${MAKE_TARGETS_LIST}") + +# Commands and targets +add_custom_target(tensorflow_build ALL + + # Command to build the TensorFlow Lite Micro library + COMMAND ${CMAKE_COMMAND} -E env PATH="${ENV_PATH}" + make -j${PARALLEL_JOBS} -f ${TENSORFLOW_LITE_MICRO_PATH}/tools/make/Makefile ${MAKE_TARGETS_LIST} + TARGET_TOOLCHAIN_ROOT=${TENSORFLOW_LITE_MICRO_TARGET_TOOLCHAIN_ROOT} + TOOLCHAIN=${TENSORFLOW_LITE_MICRO_TOOLCHAIN} + GENDIR=${TENSORFLOW_LITE_MICRO_GENDIR} + TARGET=${TENSORFLOW_LITE_MICRO_TARGET} + TARGET_ARCH=${TENSORFLOW_LITE_MICRO_TARGET_ARCH} + BUILD_TYPE=${TENSORFLOW_LITE_MICRO_BUILD_TYPE} + CMSIS_PATH=${CMSIS_SRC_PATH} + CMSIS_NN_PATH=${CMSIS_NN_SRC_PATH} + # Conditional arguments + $<$:ETHOSU_ARCH=${TENSORFLOW_LITE_MICRO_CO_PROCESSOR_ARCH}> + $<$:ETHOSU_DRIVER_PATH=${ETHOS_U_NPU_DRIVER_SRC_PATH}> + $<$:ETHOSU_DRIVER_LIBS=$> + + $<$:CORE_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_CORE_OPTIMIZATION_LEVEL}> + $<$:KERNEL_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL}> + $<$:THIRD_PARTY_KERNEL_OPTIMIZATION_LEVEL=${TENSORFLOW_LITE_MICRO_KERNEL_OPTIMIZATION_LEVEL}> + $<$:OPTIMIZED_KERNEL_DIR=${TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL}> + $<$:CO_PROCESSOR=${TENSORFLOW_LITE_MICRO_CO_PROCESSOR}> + + # Command to copy over the generated library to the local build tree. + COMMAND ${CMAKE_COMMAND} -E copy ${TENSORFLOW_LITE_MICRO_GENDIR}/lib/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} + + COMMENT "Building TensorFlow Lite Micro library..." + + BYPRODUCTS ${TENSORFLOW_SRC_PATH}/tensorflow/tensorflow/lite/micro/tools/make/downloads + ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} + ${TENSORFLOW_LITE_MICRO_GENDIR}/lib/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME} + + WORKING_DIRECTORY ${TENSORFLOW_SRC_PATH}) + +# Create library + + +set(TENSORFLOW_LITE_MICRO_TARGET tensorflow-lite-micro) +add_library(${TENSORFLOW_LITE_MICRO_TARGET} STATIC IMPORTED) + +if(ETHOS_U_NPU_ENABLED) + add_dependencies(tensorflow_build ethosu_core_driver) +endif() + +add_dependencies(tensorflow-lite-micro tensorflow_build) + +set_property(TARGET tensorflow-lite-micro PROPERTY IMPORTED_LOCATION + "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME}") + +target_include_directories(tensorflow-lite-micro + INTERFACE + ${TENSORFLOW_SRC_PATH}) + +target_compile_definitions(tensorflow-lite-micro + INTERFACE + TF_LITE_STATIC_MEMORY) diff --git a/scripts/cmake/util_functions.cmake b/scripts/cmake/util_functions.cmake index 0567ee0..6966963 100644 --- a/scripts/cmake/util_functions.cmake +++ b/scripts/cmake/util_functions.cmake @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2021-2022, 2024 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +19,8 @@ ############################################################################## # Helper function to provide user option and corresponding default value ############################################################################## +include_guard() + function(USER_OPTION name description default type) if (${type} STREQUAL PATH_OR_FILE) @@ -180,7 +183,7 @@ function(add_platform_build_configuration) set(oneValueArgs TARGET_PLATFORM) cmake_parse_arguments(PARSED "" "${oneValueArgs}" "" ${ARGN} ) message(STATUS "Searching for ${PARSED_TARGET_PLATFORM} build configuration") - list(APPEND PLATFORM_BUILD_CONFIG_DIRS ${CMAKE_SCRIPTS_DIR}/platforms) + list(APPEND PLATFORM_BUILD_CONFIG_DIRS ${SCRIPTS_DIR}/cmake/platforms) FIND_PATH(PLATFORM_BUILD_CONFIG NAMES build_configuration.cmake diff --git a/source/hal/source/components/npu_ta/CMakeLists.txt b/source/hal/source/components/npu_ta/CMakeLists.txt index 9956384..2030849 100644 --- a/source/hal/source/components/npu_ta/CMakeLists.txt +++ b/source/hal/source/components/npu_ta/CMakeLists.txt @@ -90,5 +90,5 @@ target_link_libraries(${ETHOS_U_NPU_TA_COMPONENT} PUBLIC # Display status message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR}) message(STATUS "*******************************************************") -message(STATUS "Library : " ${ETHOS_U_NPU_TA_COMPONENT}) +message(STATUS "Library : " ${ETHOS_U_NPU_TA_COMPONENT}) message(STATUS "*******************************************************") diff --git a/source/math/CMakeLists.txt b/source/math/CMakeLists.txt index 9b61905..2cd7989 100644 --- a/source/math/CMakeLists.txt +++ b/source/math/CMakeLists.txt @@ -1,5 +1,6 @@ #---------------------------------------------------------------------------- -# SPDX-FileCopyrightText: Copyright 2022 Arm Limited and/or its affiliates +# SPDX-FileCopyrightText: Copyright 2022, 2024 Arm Limited and/or its +# affiliates # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -34,11 +35,11 @@ target_include_directories(arm_math PUBLIC include) target_link_libraries(arm_math PRIVATE log) if (${CMAKE_CROSSCOMPILING}) - include(${CMAKE_SCRIPTS_DIR}/cmsis-dsp.cmake) + include(cmsis-dsp) target_link_libraries(arm_math PUBLIC cmsis-dsp) endif () message(STATUS "*******************************************************") -message(STATUS "Library : " arm_math) -message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) +message(STATUS "Library : " arm_math) +message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR}) message(STATUS "*******************************************************") -- cgit v1.2.1