Skip to content

Commit

Permalink
Sync from tflite-micro at 79f6def.
Browse files Browse the repository at this point in the history
Signed-off-by: CFU-Playground-Bot <cfu-playground-bot@google.com>
  • Loading branch information
cfu-playground-bot committed Sep 6, 2022
1 parent 9db039e commit 52cedbb
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 65 deletions.
2 changes: 1 addition & 1 deletion conf/tflite-micro.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
76663ed
79f6def
14 changes: 8 additions & 6 deletions third_party/tflite-micro/tensorflow/lite/context_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ 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 provides a few C++ helpers that are useful for manipulating C structures
// in C++.
/// \file
/// This provides a few C++ helpers that are useful for manipulating C
/// structures in C++.
#ifndef TENSORFLOW_LITE_CONTEXT_UTIL_H_
#define TENSORFLOW_LITE_CONTEXT_UTIL_H_

Expand All @@ -23,13 +24,14 @@ limitations under the License.

namespace tflite {

// Provide a range iterable wrapper for TfLiteIntArray* (C lists that TfLite
// C api uses. Can't use the google array_view, since we can't depend on even
/// Provides a range iterable wrapper for TfLiteIntArray* (C lists) that TfLite
/// C api uses.
// Can't use the google array_view, since we can't depend on even
// absl for embedded device reasons.
class TfLiteIntArrayView {
public:
// Construct a view of a TfLiteIntArray*. Note, `int_array` should be non-null
// and this view does not take ownership of it.
/// Construct a view of a TfLiteIntArray*. Note, `int_array` should be
/// non-null and this view does not take ownership of it.
explicit TfLiteIntArrayView(const TfLiteIntArray* int_array)
: int_array_(int_array) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ make -f tensorflow/lite/micro/tools/make/Makefile TARGET=disco_f746ng OPTIMIZED_
Running the make command will result in the creation of a new folder:

```
tensorflow/lite/micro/tools/make/gen/disco_f746ng_cortex-m4_default/prj/micro_speech/mbed
gen/disco_f746ng_cortex-m4_default/prj/micro_speech/mbed
```

This folder contains all of the example's dependencies structured in the correct
Expand Down Expand Up @@ -153,7 +153,7 @@ using [ARM Mbed](https://github.com/ARMmbed/mbed-cli).
```

4. Change into the following directory that has been generated:
`tensorflow/lite/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed`
`gen/mbed_cortex-m4/prj/micro_speech/mbed`

5. Create an Mbed project using the generated files, run ensuring your
environment is using Python 2.7: `mbed config root .`
Expand Down Expand Up @@ -233,7 +233,7 @@ The following instructions will help you build and deploy the sample to the
tensorflow/lite/micro/tools/make/Makefile TARGET=ceva TARGET_ARCH=CEVA_SP500
generate_micro_speech_make_project
5. Build the project:
/tensorflow/lite/micro/tools/make/gen/ceva_bx1/prj/micro_speech/make$ make
/gen/ceva_bx1/prj/micro_speech/make$ make
6. This should build the project and create a file called micro_speech.elf.
7. The supplied configuration reads input from a files and expects a file
called input.wav (easily changed in audio_provider.cc) to be placed in the
Expand All @@ -260,7 +260,7 @@ make -f tensorflow/lite/micro/tools/make/Makefile micro_speech
Once the build completes, you can run the example with the following command:

```
tensorflow/lite/micro/tools/make/gen/osx_x86_64/bin/micro_speech
gen/osx_x86_64/bin/micro_speech
```

You might see a pop-up asking for microphone access. If so, grant it, and the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cd "${ROOT_DIR}"

source tensorflow/lite/micro/tools/ci_build/helper_functions.sh

if [ $1 = "armclang" ]; then
if [[ $1 = "armclang" ]]; then
TOOLCHAIN=armclang
else
TOOLCHAIN=gcc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,28 @@ rm -rf "${TEST_OUTPUT_DIR}"
# Remove existing state prior to testing project generation for cortex-m target.
make -f tensorflow/lite/micro/tools/make/Makefile clean clean_downloads

ARM_CPU=55

TEST_OUTPUT_DIR_CMSIS="$(mktemp -d)"

readable_run \
python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \
--makefile_options="TARGET=cortex_m_generic OPTIMIZED_KERNEL_DIR=cmsis_nn TARGET_ARCH=cortex-m${ARM_CPU}" \
--makefile_options="TARGET=cortex_m_generic OPTIMIZED_KERNEL_DIR=cmsis_nn TARGET_ARCH=project_generation" \
"${TEST_OUTPUT_DIR_CMSIS}" \
${EXAMPLES}

readable_run \
cp tensorflow/lite/micro/tools/project_generation/Makefile "${TEST_OUTPUT_DIR_CMSIS}"

readable_run \
cp tensorflow/lite/micro/tools/make/targets/cortex_m_generic_makefile.inc "${TEST_OUTPUT_DIR_CMSIS}"

readable_run \
mkdir -p "${TEST_OUTPUT_DIR_CMSIS}/third_party/cmsis/Device/ARM/ARMCM${ARM_CPU}"

readable_run \
cp -r tensorflow/lite/micro/tools/make/downloads/cmsis/Device/ARM/ARMCM${ARM_CPU}/Include \
"${TEST_OUTPUT_DIR_CMSIS}/third_party/cmsis/Device/ARM/ARMCM${ARM_CPU}/"

pushd "${TEST_OUTPUT_DIR_CMSIS}" > /dev/null

PATH="${PATH}:${ROOT_DIR}/tensorflow/lite/micro/tools/make/downloads/gcc_embedded/bin" \
readable_run \
make -j8 BUILD_TYPE=cmsis_nn TARGET_ARCH=cortex-m${ARM_CPU}
make -j8 BUILD_TYPE=cmsis_nn

popd > /dev/null

rm -rf "${TEST_OUTPUT_DIR_CMSIS}"


# Test that C++ files are renamed to .cpp

TEST_OUTPUT_DIR_RENAME_CC="$(mktemp -d)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function build_target() {
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile build build_type=${build_type} TARGET=${target} TARGET_ARCH=${target_arch} ${binary_target}

# Return the relative binary with path and name.
__BINARY_TARGET_PATH="tensorflow/lite/micro/tools/make/gen/${target}_${target_arch}_${build_type}/bin/${binary_target}"
__BINARY_TARGET_PATH="gen/${target}_${target_arch}_${build_type}/bin/${binary_target}"
}

FLAG_ERROR_ON_MEM_INCREASE=$1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
downloads
gen

Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ endif
MICROLITE_LIB_NAME := libtensorflow-microlite.a

# Where compiled objects are stored.
GENDIR := $(MAKEFILE_DIR)/gen/$(TARGET)_$(TARGET_ARCH)_$(BUILD_TYPE)/
BASE_GENDIR := gen
GENDIR := $(BASE_GENDIR)/$(TARGET)_$(TARGET_ARCH)_$(BUILD_TYPE)/
CORE_OBJDIR := $(GENDIR)obj/core/
KERNEL_OBJDIR := $(GENDIR)obj/kernels/
THIRD_PARTY_KERNEL_OBJDIR := $(GENDIR)obj/third_party_kernels/
Expand Down Expand Up @@ -802,7 +803,7 @@ list_generator_dir:

# Gets rid of all generated files.
clean:
rm -rf $(MAKEFILE_DIR)/gen
rm -rf $(BASE_GENDIR)

# Removes third-party downloads.
clean_downloads:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ if [ ! -f ${CONVERTED_PERSON_MODEL_INT8} ]; then
${CONVERTED_PERSON_MODEL_INT8}
echo -n "const " >> ${CONVERTED_PERSON_MODEL_INT8}
xxd -i ${MODEL_DIR}/person_detect_vela.tflite >> ${CONVERTED_PERSON_MODEL_INT8}
sed -i 's/tensorflow_lite_micro_tools_make_gen_cortex_m_corstone_300_cortex_m55_default_genfiles_tensorflow_lite_micro_models_person_detect_vela_tflite/g_person_detect_model_data/' \
sed -i 's/gen_cortex_m_corstone_300_cortex_m55_default_genfiles_tensorflow_lite_micro_models_person_detect_vela_tflite/g_person_detect_model_data/' \
${CONVERTED_PERSON_MODEL_INT8}
sed -i 's/^const unsigned char g_person_detect_model_data/alignas\(16\) &/' ${CONVERTED_PERSON_MODEL_INT8}
sed -i 's/g_person_detect_model_data_len/g_person_detect_model_data_size/' ${CONVERTED_PERSON_MODEL_INT8}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ OPTIMIZED_KERNEL_DIR=arc_mli \
microlite
```

Generated library *libtensorflow-microlite.a* can be found in *tensorflow/lite/micro/tools/make/gen/{target}/lib*.
Generated library *libtensorflow-microlite.a* can be found in *gen/{target}/lib*.

### Example Applications for ARC EM SDP

Expand Down Expand Up @@ -255,7 +255,7 @@ TCF_FILE=<path_to_tcf_file> \
microlite
```

Generated library *libtensorflow-microlite.a* can be found in *tensorflow/lite/micro/tools/make/gen/{target}/lib*.
Generated library *libtensorflow-microlite.a* can be found in *gen/{target}/lib*.

### Example Applications for ARC EM/HS/VPX custom configuration.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CCFLAGS += $(PLATFORM_FLAGS)

LDFLAGS += \
-T $(MAKEFILE_DIR)/targets/bluepill/bluepill.lds \
-Wl,-Map=$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref
-Wl,-Map=gen/$(TARGET).map,--cref

# Additional include paths needed for the stm_32_bare_lib only.
INCLUDES += \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ifeq ($(TOOLCHAIN), armclang)
ARMC6_LDFLAGS += -Wl,--strict,--summary_stderr,--info,summarysizes,--map
ARMC6_LDFLAGS += -Wl,--load_addr_map_info,--xref,--callgraph,--symbols
ARMC6_LDFLAGS += -Wl,--info,sizes,--info,totals,--info,unused,--info,veneers
ARMC6_LDFLAGS += -Wl,--list=${TENSORFLOW_ROOT}$(MAKEFILE_DIR)/gen/$(TARGET).map
ARMC6_LDFLAGS += -Wl,--list=${TENSORFLOW_ROOT}gen/$(TARGET).map
ARMC6_LDFLAGS += -Wl,--entry=Reset_Handler --verbose
ARMC6_LDFLAGS += -Wl,--scatter=$(ETHOS_U_CORE_PLATFORM)/platform.scatter

Expand Down Expand Up @@ -148,7 +148,7 @@ else ifeq ($(TOOLCHAIN), gcc)
LDFLAGS += \
--specs=nosys.specs \
-T $(ETHOS_U_CORE_PLATFORM)/platform_parsed.ld \
-Wl,-Map=${TENSORFLOW_ROOT}$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref \
-Wl,-Map=${TENSORFLOW_ROOT}gen/$(TARGET).map,--cref \
-Wl,--gc-sections \
--entry Reset_Handler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ else ifeq ($(TARGET_ARCH), cortex-m85)

else ifeq ($(TARGET_ARCH), project_generation)
# No flags needed here as project_generation does not build anything.
# Make explicit there is to be no gcc download as project_generation does
# not build anything.
SKIP_ARM_GCC_DOWNLOAD = yes

else
$(error "TARGET_ARCH=$(TARGET_ARCH) is not supported")
endif
Expand Down Expand Up @@ -144,17 +140,12 @@ ifeq ($(TOOLCHAIN), armclang)
MICROLITE_LIBS := $(filter-out -lm,$(MICROLITE_LIBS))

else ifeq ($(TOOLCHAIN), gcc)
# Download may be skipped in some cases, for example project generation.
SKIP_ARM_GCC_DOWNLOAD ?= no

TARGET_DEFAULT_TOOLCHAIN_ROOT := ${TENSORFLOW_ROOT}$(MAKEFILE_DIR)/downloads/gcc_embedded/bin/
TARGET_TOOLCHAIN_ROOT := $(TARGET_DEFAULT_TOOLCHAIN_ROOT)
ifeq ($(SKIP_ARM_GCC_DOWNLOAD), no)
ifeq ($(TARGET_TOOLCHAIN_ROOT), $(TARGET_DEFAULT_TOOLCHAIN_ROOT))
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/arm_gcc_download.sh ${MAKEFILE_DIR}/downloads)
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
$(error Something went wrong with the GCC download: $(DOWNLOAD_RESULT))
endif
ifeq ($(TARGET_TOOLCHAIN_ROOT), $(TARGET_DEFAULT_TOOLCHAIN_ROOT))
DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/arm_gcc_download.sh ${MAKEFILE_DIR}/downloads)
ifneq ($(DOWNLOAD_RESULT), SUCCESS)
$(error Something went wrong with the GCC download: $(DOWNLOAD_RESULT))
endif
endif

Expand Down Expand Up @@ -212,4 +203,4 @@ ifneq ($(TARGET_ARCH), project_generation)
EXCLUDED_EXAMPLE_TESTS := \
tensorflow/lite/micro/examples/micro_speech/Makefile.inc
MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TESTS))
endif
endif
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ CCFLAGS += $(PLATFORM_FLAGS)
LDFLAGS += \
--specs=nosys.specs \
-T ${TENSORFLOW_ROOT}$(MAKEFILE_DIR)/targets/stm32f4/stm32f4.lds \
-Wl,-Map=${TENSORFLOW_ROOT}$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref \
-Wl,-Map=${TENSORFLOW_ROOT}gen/$(TARGET).map,--cref \
-Wl,--gc-sections
BUILD_TYPE := micro
MICROLITE_LIBS := \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ def _profile_a_binary(root_dir, binary_name, makefile_options, build_info):
target_dir = "%s_%s_%s" % (makefile_options["TARGET"],
makefile_options["TARGET_ARCH"],
makefile_options["BUILD_TYPE"])
binary_path = os.path.join(root_dir, 'tensorflow/lite/micro/tools/make/gen/',
target_dir, 'bin', binary_name)
binary_path = os.path.join(root_dir, 'gen/', target_dir, 'bin', binary_name)
csv_path = os.path.join(root_dir, 'data/continuous_builds/size_profiling',
target_dir, "%s.csv" % binary_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ INCLUDES := \
-I./third_party/kissfft/tools \
-I./third_party/ruy

CXXFLAGS :=
CCFLAGS :=

ifeq ($(BUILD_TYPE), cmsis_nn)
CXX := arm-none-eabi-g++
CC := arm-none-eabi-gcc
Expand All @@ -56,30 +53,24 @@ ifeq ($(BUILD_TYPE), cmsis_nn)

COMMON_FLAGS += \
-DTF_LITE_MCU_DEBUG_LOG \
-DPROJECT_GENERATION \
-mthumb \
-mlittle-endian \
-funsigned-char \
-fomit-frame-pointer \
-MD \
-DCMSIS_NN

# For this build type there is additional dependency to CMSIS.
TOOLCHAIN = gcc
SKIP_ARM_GCC_DOWNLOAD := "yes please"
include cortex_m_generic_makefile.inc
INCLUDES += \
-I./third_party/cmsis/Device/ARM/$(ARM_CPU)/Include

endif

CXXFLAGS += \
CXXFLAGS := \
-std=c++11 \
-fno-rtti \
-fno-exceptions \
-fno-threadsafe-statics \
$(COMMON_FLAGS)

CCFLAGS += \
CCFLAGS := \
-std=c11 \
$(COMMON_FLAGS)

Expand Down

0 comments on commit 52cedbb

Please sign in to comment.