From 68549b4afbe5098e46bda12be3769c7bf70b6e8b Mon Sep 17 00:00:00 2001 From: Nina Drozd Date: Tue, 15 Feb 2022 14:32:57 +0000 Subject: MLECO-2927: Build Arm Ethos-U NPU driver outside TFLu * TensorFlow CMake uses Arm Ethos-U NPU driver lib path * armclang DWARF level config flag removed * uses and mentions of DWARF level removed * TensorFlow uses Arm Cortex-M generic target * removed Arm Cortex-M custom target makefile and dir Change-Id: Ie0d3edb5473462ef8552f8b9f832190de5e99a7c --- docs/sections/building.md | 24 ----- scripts/cmake/common_user_options.cmake | 8 -- scripts/cmake/tensorflow.cmake | 26 ++--- scripts/make/cortex_m_ethos_eval_makefile.inc | 149 -------------------------- 4 files changed, 14 insertions(+), 193 deletions(-) delete mode 100644 scripts/make/cortex_m_ethos_eval_makefile.inc diff --git a/docs/sections/building.md b/docs/sections/building.md index c39cabc..5fdadb0 100644 --- a/docs/sections/building.md +++ b/docs/sections/building.md @@ -234,16 +234,6 @@ chosen configuration. - `TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS`: Optional parameter to enable wiping out `TPIP` downloads from TensorFlow source tree prior to each build. Disabled by default. -- `ARMCLANG_DEBUG_DWARF_LEVEL`: When the CMake build type is specified as `Debug` and when the `armclang` toolchain is - being used to build for a *Cortex-M* CPU target, this optional argument can be set to specify the `DWARF` format. - - By default, this is set to 4 and is synonymous with passing `-g` flag to the compiler. This is compatible with Arm - DS and other tools which can interpret the latest DWARF format. To allow debugging using the Model Debugger from Arm - Fast Model Tools Suite, this argument can be used to pass DWARF format version as "3". - - > **Note:** This option is only available when the CMake project is configured with the `-DCMAKE_BUILD_TYPE=Debug` - > argument. Also, the same dwarf format is used for building TensorFlow Lite Micro library. - For details on the specific use-case build options, follow the instructions in the use-case specific documentation. Also, when setting any of the CMake configuration parameters that expect a directory, or file, path, **use absolute @@ -452,20 +442,6 @@ cmake \ ml-embedded-evaluation-kit ``` -#### Working with model debugger from Arm Fast Model Tools - -To configure a build that can be debugged using a tool that only supports the `DWARF format 3`, such as *Modeldebugger*, -you can use: - -```commandline -cmake .. \ - -DTARGET_PLATFORM=mps3 \ - -DTARGET_SUBSYSTEM=sse-300 \ - -DCMAKE_TOOLCHAIN_FILE=scripts/cmake/toolchains/bare-metal-armclang.cmake \ - -DCMAKE_BUILD_TYPE=Debug \ - -DARMCLANG_DEBUG_DWARF_LEVEL=3 -``` - #### Configuring with custom TPIP dependencies If the TensorFlow source tree is not in its default expected location, set the path using `TENSORFLOW_SRC_PATH`. diff --git a/scripts/cmake/common_user_options.cmake b/scripts/cmake/common_user_options.cmake index afc5386..9a13287 100644 --- a/scripts/cmake/common_user_options.cmake +++ b/scripts/cmake/common_user_options.cmake @@ -84,14 +84,6 @@ if (NOT TARGET_PLATFORM STREQUAL native) "${DEPENDENCY_ROOT_DIR}/cmsis" PATH) - if (CMAKE_BUILD_TYPE STREQUAL Debug) - # For use with Arm compiler: - USER_OPTION(ARMCLANG_DEBUG_DWARF_LEVEL - "Dwarf conformance level for armclang toolchain" - "4" # Default = 4 (Arm-DS etc). For model debugger specify "3" - STRING) - endif() - # If we need NPU libraries: if (ETHOS_U_NPU_ENABLED) USER_OPTION(ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH diff --git a/scripts/cmake/tensorflow.cmake b/scripts/cmake/tensorflow.cmake index 9d72405..284c70a 100644 --- a/scripts/cmake/tensorflow.cmake +++ b/scripts/cmake/tensorflow.cmake @@ -45,24 +45,19 @@ 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") -set(ETHOS_EVAL_TARGET_MAKEFILE_INC ${CMAKE_CURRENT_SOURCE_DIR}/scripts/make/cortex_m_ethos_eval_makefile.inc) - 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_ethos_eval") + set(TENSORFLOW_LITE_MICRO_TARGET "cortex_m_generic") set(TENSORFLOW_LITE_MICRO_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR}${CPU_FEATURES}) if(ETHOS_U_NPU_ENABLED) # Arm Ethos-U55 NPU is the co-processor for ML workload: set(TENSORFLOW_LITE_MICRO_CO_PROCESSOR "ethos_u") + string(TOLOWER ${ETHOS_U_NPU_ID} ETHOSU_ARCH) endif() set(TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL "cmsis_nn") - - # Copy over the target helper (cortex_m_ethos_eval) - file(COPY ${ETHOS_EVAL_TARGET_MAKEFILE_INC} - DESTINATION ${TENSORFLOW_LITE_MICRO_PATH}/tools/make/targets/) endif() if (TENSORFLOW_LITE_MICRO_CLEAN_DOWNLOADS) @@ -92,11 +87,12 @@ add_custom_target(tensorflow_build ALL TARGET=${TENSORFLOW_LITE_MICRO_TARGET} TARGET_ARCH=${TENSORFLOW_LITE_MICRO_TARGET_ARCH} BUILD_TYPE=${TENSORFLOW_LITE_MICRO_BUILD_TYPE} - ETHOSU_ARCH=${ETHOSU_ARCH} - ETHOSU_DRIVER_PATH=${ETHOS_U_NPU_DRIVER_SRC_PATH} CMSIS_PATH=${CMSIS_SRC_PATH} # Conditional arguments - $<$:ARMCLANG_DEBUG_DWARF_LEVEL=${ARMCLANG_DEBUG_DWARF_LEVEL}> + $<$:ETHOSU_ARCH=${ETHOSU_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}> $<$:OPTIMIZED_KERNEL_DIR=${TENSORFLOW_LITE_MICRO_OPTIMIZED_KERNEL}> @@ -116,7 +112,13 @@ add_custom_target(tensorflow_build ALL # Create library -add_library(tensorflow-lite-micro STATIC IMPORTED) + +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) @@ -129,4 +131,4 @@ target_include_directories(tensorflow-lite-micro target_compile_definitions(tensorflow-lite-micro INTERFACE - TF_LITE_STATIC_MEMORY) + TF_LITE_STATIC_MEMORY) \ No newline at end of file diff --git a/scripts/make/cortex_m_ethos_eval_makefile.inc b/scripts/make/cortex_m_ethos_eval_makefile.inc deleted file mode 100644 index 234534a..0000000 --- a/scripts/make/cortex_m_ethos_eval_makefile.inc +++ /dev/null @@ -1,149 +0,0 @@ -# Copyright (c) 2021 Arm Limited. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# 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. - -# Generic Makefile target for ARM Cortex M builds. -# For more info see: tensorflow/lite/micro/cortex_m_generic/README.md -ifeq ($(TARGET),$(filter $(TARGET), cortex_m_ethos_eval)) - FLOAT := soft - GCC_TARGET_ARCH := $(TARGET_ARCH) - - ifeq ($(TARGET_ARCH), cortex-m0) - CORE=M0 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M0 - - else ifeq ($(TARGET_ARCH), cortex-m3) - CORE=M3 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M3 - - else ifeq ($(TARGET_ARCH), cortex-m33) - CORE=M33 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M33 - TARGET_SPECIFIC_FLAGS += -D__DSP_PRESENT=1 -D__FPU_PRESENT=1 -D__VTOR_PRESENT=1 -D__FPU_USED=1 - FLOAT=hard - - else ifeq ($(TARGET_ARCH), cortex-m33+nodsp) - CORE=M33 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M33.no_dsp.no_fp - - else ifeq ($(TARGET_ARCH), cortex-m4) - CORE=M4 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M4.no_fp - GCC_TARGET_ARCH := cortex-m4+nofp - - else ifeq ($(TARGET_ARCH), cortex-m4+fp) - CORE=M4 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M4 - TARGET_SPECIFIC_FLAGS += -D__FPU_PRESENT=1 - FLOAT=hard - GCC_TARGET_ARCH := cortex-m4 - - else ifeq ($(TARGET_ARCH), cortex-m55) - CORE=M55 - ARM_LDFLAGS := -Wl,--cpu=8.1-M.Main.mve.fp - TARGET_SPECIFIC_FLAGS += -D__DSP_PRESENT=1 -D__FPU_PRESENT=1 - FLOAT=hard - - else ifeq ($(TARGET_ARCH), cortex-m55+nodsp+nofp) - CORE=M55 - ARM_LDFLAGS := -Wl,--cpu=8.1-M.Main.mve.no_dsp.no_fp - - else ifeq ($(TARGET_ARCH), cortex-m55+nofp) - CORE=M55 - ARM_LDFLAGS := -Wl,--cpu=8.1-M.Main.mve.no_fp - TARGET_SPECIFIC_FLAGS += -D__DSP_PRESENT=1 - - else ifeq ($(TARGET_ARCH), cortex-m7) - CORE=M7 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M7.no_fp - GCC_TARGET_ARCH := cortex-m7+nofp - - else ifeq ($(TARGET_ARCH), cortex-m7+fp) - CORE=M7 - ARM_LDFLAGS := -Wl,--cpu=Cortex-M7 - FLOAT=hard - GCC_TARGET_ARCH := cortex-m7 - - else - $(error "TARGET_ARCH=$(TARGET_ARCH) is not supported") - endif - - ifneq ($(filter cortex-m55%,$(TARGET_ARCH)),) - # soft-abi=soft disables MVE - use softfp instead for M55. - ifeq ($(FLOAT),soft) - FLOAT=softfp - endif - endif - - # Toolchain specfic flags - ifeq ($(TOOLCHAIN), armclang) - CXX_TOOL := armclang - CC_TOOL := armclang - AR_TOOL := armar - LD := armlink - - FLAGS_ARMC = \ - --target=arm-arm-none-eabi \ - -mcpu=$(TARGET_ARCH) - - # For debug, include specific dwarf format symbols - ifeq ($(BUILD_TYPE), debug) - ifneq ($(ARMCLANG_DEBUG_DWARF_LEVEL),) - FLAGS_ARMC += -gdwarf-$(ARMCLANG_DEBUG_DWARF_LEVEL) - endif - endif - - CXXFLAGS += $(FLAGS_ARMC) - CCFLAGS += $(FLAGS_ARMC) - LDFLAGS += $(ARM_LDFLAGS) - - # Arm Compiler will not link the Math library (see below), therefore we're filtering it out. - # See Fatal error: L6450U: Cannot find library m: - # "Arm Compiler is designed to run in a bare metal environment, - # and automatically includes implementations of these functions, - # and so no such flag is necessary." - # https://developer.arm.com/documentation/100891/0611/troubleshooting/general-troubleshooting-advice - MICROLITE_LIBS := $(filter-out -lm,$(MICROLITE_LIBS)) - - else ifeq ($(TOOLCHAIN), gcc) - TARGET_TOOLCHAIN_PREFIX := arm-none-eabi- - - FLAGS_GCC = -mcpu=$(GCC_TARGET_ARCH) -mfpu=auto - CXXFLAGS += $(FLAGS_GCC) - CCFLAGS += $(FLAGS_GCC) - - else - $(error "TOOLCHAIN=$(TOOLCHAIN) is not supported.") - endif - - - PLATFORM_FLAGS = \ - -DTF_LITE_MCU_DEBUG_LOG \ - -mthumb \ - -mfloat-abi=$(FLOAT) \ - -funsigned-char \ - -mlittle-endian \ - -Wno-type-limits \ - -Wno-unused-private-field \ - -fomit-frame-pointer \ - -MD \ - -DCPU_CORTEX_$(CORE)=1 \ - -DETHOSU_ARCH=${ETHOSU_ARCH} \ - $(TARGET_SPECIFIC_FLAGS) - - # Common + C/C++ flags - CXXFLAGS += $(PLATFORM_FLAGS) - CCFLAGS += $(PLATFORM_FLAGS) - -endif -- cgit v1.2.1