From 562fb191a6c36d79590f1ddd6e7577d392cce311 Mon Sep 17 00:00:00 2001 From: ddavis-2015 Date: Mon, 21 Jul 2025 11:38:52 -0700 Subject: [PATCH 1/3] Updates to Xtensa makefiles @tensorflow/micro Reorganize Xtensa makefiles such that all references to optimized kernel sources are moved to the Xtensa target makefile. Move hifimini kernel sources to the parent directory, and rename them so they do not interfere with the target overlay mechanism of the root makefile. bug=fixes #3153 --- ...nt_utils.h => fixedpoint_utils_hifimini.h} | 0 ...nnected.cc => fully_connected_hifimini.cc} | 4 +- .../{hifimini/svdf.cc => svdf_hifimini.cc} | 4 +- .../lite/micro/tools/make/ext_libs/xtensa.inc | 28 ----------- .../tools/make/targets/xtensa_makefile.inc | 47 ++++++++++++++----- 5 files changed, 39 insertions(+), 44 deletions(-) rename tensorflow/lite/micro/kernels/xtensa/{hifimini/fixedpoint_utils.h => fixedpoint_utils_hifimini.h} (100%) rename tensorflow/lite/micro/kernels/xtensa/{hifimini/fully_connected.cc => fully_connected_hifimini.cc} (97%) rename tensorflow/lite/micro/kernels/xtensa/{hifimini/svdf.cc => svdf_hifimini.cc} (98%) diff --git a/tensorflow/lite/micro/kernels/xtensa/hifimini/fixedpoint_utils.h b/tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils_hifimini.h similarity index 100% rename from tensorflow/lite/micro/kernels/xtensa/hifimini/fixedpoint_utils.h rename to tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils_hifimini.h diff --git a/tensorflow/lite/micro/kernels/xtensa/hifimini/fully_connected.cc b/tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc similarity index 97% rename from tensorflow/lite/micro/kernels/xtensa/hifimini/fully_connected.cc rename to tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc index b63c5001a91..6698b0f7191 100644 --- a/tensorflow/lite/micro/kernels/xtensa/hifimini/fully_connected.cc +++ b/tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc @@ -1,4 +1,4 @@ -/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2025 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ limitations under the License. #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" #include "tensorflow/lite/kernels/kernel_util.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" -#include "tensorflow/lite/micro/kernels/xtensa/hifimini/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils_hifimini.h" #include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" namespace tflite { diff --git a/tensorflow/lite/micro/kernels/xtensa/hifimini/svdf.cc b/tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc similarity index 98% rename from tensorflow/lite/micro/kernels/xtensa/hifimini/svdf.cc rename to tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc index 08ef4d9bb0c..056091b8490 100644 --- a/tensorflow/lite/micro/kernels/xtensa/hifimini/svdf.cc +++ b/tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc @@ -1,4 +1,4 @@ -/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2025 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ limitations under the License. #include "tensorflow/lite/kernels/op_macros.h" #include "tensorflow/lite/micro/kernels/activation_utils.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" -#include "tensorflow/lite/micro/kernels/xtensa/hifimini/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils_hifimini.h" #include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" #include "tensorflow/lite/micro/kernels/xtensa/xtensa_svdf.h" diff --git a/tensorflow/lite/micro/tools/make/ext_libs/xtensa.inc b/tensorflow/lite/micro/tools/make/ext_libs/xtensa.inc index 70e1880c800..38a959d5fe5 100644 --- a/tensorflow/lite/micro/tools/make/ext_libs/xtensa.inc +++ b/tensorflow/lite/micro/tools/make/ext_libs/xtensa.inc @@ -1,33 +1,5 @@ -# Explicitly add kernel sources specific to the Xtensa optimized -# implementations. -MICROLITE_CC_KERNEL_SRCS += \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/add_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_common_xtensa.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_hifi.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_int16_reference.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_int8_int16.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_int8_reference.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/depthwise_conv_hifi.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/depthwise_conv_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/fully_connected_common_xtensa.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/fully_connected_int8.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/fully_connected_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/pad_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/pooling_int8.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/pooling_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/reduce_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/reshape_vision.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/softmax_int8_int16.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/softmax_vision.cc - ifeq ($(TARGET_ARCH), hifimini) - # hifimini optimizations are implemented in the TFLM repository itself. - THIRD_PARTY_KERNEL_CC_SRCS += \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/hifimini/svdf.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/hifimini/fully_connected.cc - FFT_PATH := $(MAKEFILE_DIR)/downloads/hifi_fft INCLUDES += -I$(FFT_PATH)/ diff --git a/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc b/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc index e9f940392b1..b05a0670248 100644 --- a/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc +++ b/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc @@ -91,20 +91,43 @@ EXCLUDED_EXAMPLE_TESTS := \ MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TESTS)) MICRO_LITE_EXAMPLE_TESTS += $(shell find $(TENSORFLOW_ROOT)third_party/xtensa/examples/ -name Makefile.inc) -# Needed for LSTM support. -MICROLITE_CC_KERNEL_SRCS := $(MICROLITE_CC_KERNEL_SRCS) \ -$(TENSORFLOW_ROOT)tensorflow/lite/kernels/internal/reference/portable_tensor_utils.cc \ -$(TENSORFLOW_ROOT)tensorflow/lite/kernels/kernel_util.cc - ifeq ($(OPTIMIZED_KERNEL_DIR), xtensa) - MICROLITE_CC_KERNEL_SRCS := $(MICROLITE_CC_KERNEL_SRCS) \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/lstm_eval.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/lstm_eval_hifi.cc \ - $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/unidirectional_sequence_lstm.cc + # Explicitly add kernel sources specific to the Xtensa optimized + # implementations. + # + # Do not include overlays for reference kernel files. + MICROLITE_CC_KERNEL_SRCS += \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/add_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_common_xtensa.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_hifi.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_int16_reference.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_int8_int16.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_int8_reference.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/conv_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/depthwise_conv_hifi.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/depthwise_conv_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/fully_connected_common_xtensa.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/fully_connected_int8.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/fully_connected_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/lstm_eval_hifi.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/pad_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/pooling_int8.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/pooling_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/reduce_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/reshape_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/softmax_int8_int16.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/softmax_vision.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc + + # Needed for LSTM support. + MICROLITE_CC_KERNEL_SRCS += \ + $(TENSORFLOW_ROOT)tensorflow/lite/kernels/internal/reference/portable_tensor_utils.cc \ + $(TENSORFLOW_ROOT)tensorflow/lite/kernels/kernel_util.cc +endif - # override KERNEL_OPTIMIZATION_LEVEL to enable higher performance - # Xtensa intrinsics. +# override KERNEL_OPTIMIZATION_LEVEL to enable higher performance +# Xtensa intrinsics. $(KERNEL_OBJDIR)$(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/decompress.o: $(TENSORFLOW_ROOT)tensorflow/lite/micro/kernels/xtensa/decompress.cc @mkdir -p $(dir $@) $(CXX) $(CXXFLAGS) -O3 -LNO:simd $(INCLUDES) -c $< -o $@ -endif From ad64f56d76c4efffff5da74d596c5ad24a9866d2 Mon Sep 17 00:00:00 2001 From: ddavis-2015 Date: Mon, 21 Jul 2025 12:41:24 -0700 Subject: [PATCH 2/3] Fix incorrect include path. Fix code style errors. --- .../lite/micro/kernels/xtensa/fully_connected_hifimini.cc | 2 +- tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc | 2 +- tensorflow/lite/micro/kernels/xtensa/xtensa.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc b/tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc index 6698b0f7191..8e36908f03b 100644 --- a/tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc +++ b/tensorflow/lite/micro/kernels/xtensa/fully_connected_hifimini.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #if defined(HIFIMINI) -#include "tensorflow/lite/micro/kernels/fully_connected.h" #include "tensorflow/lite/c/builtin_op_data.h" #include "tensorflow/lite/c/common.h" @@ -24,6 +23,7 @@ limitations under the License. #include "tensorflow/lite/kernels/internal/reference/integer_ops/fully_connected.h" #include "tensorflow/lite/kernels/internal/tensor_ctypes.h" #include "tensorflow/lite/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/fully_connected.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" #include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils_hifimini.h" #include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" diff --git a/tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc b/tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc index 056091b8490..a3da4e68a3c 100644 --- a/tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc +++ b/tensorflow/lite/micro/kernels/xtensa/svdf_hifimini.cc @@ -14,7 +14,6 @@ limitations under the License. ==============================================================================*/ #if defined(HIFIMINI) -#include "tensorflow/lite/micro/kernels/svdf.h" #include @@ -27,6 +26,7 @@ limitations under the License. #include "tensorflow/lite/kernels/op_macros.h" #include "tensorflow/lite/micro/kernels/activation_utils.h" #include "tensorflow/lite/micro/kernels/kernel_util.h" +#include "tensorflow/lite/micro/kernels/svdf.h" #include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils_hifimini.h" #include "tensorflow/lite/micro/kernels/xtensa/xtensa.h" #include "tensorflow/lite/micro/kernels/xtensa/xtensa_svdf.h" diff --git a/tensorflow/lite/micro/kernels/xtensa/xtensa.h b/tensorflow/lite/micro/kernels/xtensa/xtensa.h index 604736ddbd4..9a441f44096 100644 --- a/tensorflow/lite/micro/kernels/xtensa/xtensa.h +++ b/tensorflow/lite/micro/kernels/xtensa/xtensa.h @@ -19,7 +19,7 @@ limitations under the License. #if defined(HIFIMINI) #include -#include "tensorflow/lite/micro/kernels/xtensa/hifimini/fixedpoint_utils.h" +#include "tensorflow/lite/micro/kernels/xtensa/fixedpoint_utils_hifimini.h" #endif // defined(HIFMINI) #if defined(HIFI3) || defined(HIFI4) || defined(HIFI5) From 6622a28512a05ebdc2379dbe12b5bd4275ebf2b8 Mon Sep 17 00:00:00 2001 From: ddavis-2015 Date: Mon, 21 Jul 2025 13:36:01 -0700 Subject: [PATCH 3/3] fix copyright --- tensorflow/lite/micro/kernels/xtensa/xtensa.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tensorflow/lite/micro/kernels/xtensa/xtensa.h b/tensorflow/lite/micro/kernels/xtensa/xtensa.h index 9a441f44096..0e7e51b0cb6 100644 --- a/tensorflow/lite/micro/kernels/xtensa/xtensa.h +++ b/tensorflow/lite/micro/kernels/xtensa/xtensa.h @@ -1,4 +1,4 @@ -/* Copyright 2020 The TensorFlow Authors. All Rights Reserved. +/* Copyright 2025 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.