build: begin using -std=c++17 and c17 in Makefile builds (#2648)
Begin using -std=c++17 and -std=c17 in Makefile builds on
all platforms. Bazel builds have been using C++17 since 52c9568.
Set `-stdlib=libc++ on xt-clang` on Xtensa to add C++17 library
support in addition to compiler support. From the xt-clang docs:
Starting with the RI-2019.1 release, XT-CLANG has included support
for C++14 and C++17 language features. The compiler support for
C++14 and C++17 is accompanied by the C++ library from the LLVM
project. This library can be selected with the -stdlib=libc++
option, and this is strongly recommended when compiling with
-std=c++14 or - std=c++17. Starting with the RI-2021.6 release, two
additional versions of this C++ library are provided— one that
excludes support for exception handling, and one that excludes both
exception handling and run-time type identification. These libraries
can be selected with -stdlib=libc ++-e and -stdlib=libc++-re options
respectively.
Based on the `docker run` command in
tflite-micro/.github/workflows/xtensa_presubmit.yml, our CI is
currently using RI-2020.4.
Refactor the make/ext_libs/xtensa_download.sh script to make it eaiser
to patch downloads for all Xtensa platforms. The old script made overly
strict assumptions about the name of the patch.
Patch the Xtensa vision_p6 platform download xi_tflmlib_vision_p6 for
compatibility with the C++ library standard. Use the header <climits> to
access constants such as INT_MAX.
BUG=#2650diff --git a/tensorflow/lite/micro/docs/new_platform_support.md b/tensorflow/lite/micro/docs/new_platform_support.md
index 452fe91..8752c8b 100644
--- a/tensorflow/lite/micro/docs/new_platform_support.md
+++ b/tensorflow/lite/micro/docs/new_platform_support.md
@@ -25,7 +25,7 @@
Prior to integrating TFLM with a specific hardware involves tasks that is
outside the scope of the TFLM project, including:
- * Toolchain setup - TFLM requires support for C++11
+ * Toolchain setup - TFLM requires support for C++17
* Set up and installation of board-specific SDKs and IDEs
* Compiler flags and Linker setup
* Integrating peripherals such as cameras, microphones and accelerometers to
diff --git a/tensorflow/lite/micro/tools/make/Makefile b/tensorflow/lite/micro/tools/make/Makefile
index 8217501..3bf2b54 100644
--- a/tensorflow/lite/micro/tools/make/Makefile
+++ b/tensorflow/lite/micro/tools/make/Makefile
@@ -182,7 +182,7 @@
endif
CXXFLAGS := \
- -std=c++11 \
+ -std=c++17 \
-fno-rtti \
-fno-exceptions \
-fno-threadsafe-statics \
@@ -191,7 +191,7 @@
CCFLAGS := \
-Wimplicit-function-declaration \
- -std=c11 \
+ -std=c17 \
$(COMMON_FLAGS)
ARFLAGS := -r
@@ -257,13 +257,6 @@
# https://github.com/tensorflow/tensorflow/issues/43076
CXXFLAGS := $(filter-out -DTF_LITE_STATIC_MEMORY, $(CXXFLAGS))
CCFLAGS := $(filter-out -DTF_LITE_STATIC_MEMORY, $(CCFLAGS))
-
- # We are using C++17 for the no_tf_lite_static_memory_build to make it close
- # to the TfLite bazel build.
- CXXFLAGS := $(filter-out -std=c++11, $(CXXFLAGS))
- CXXFLAGS += -std=c++17
- CCFLAGS := $(filter-out -std=c11, $(CCLAGS))
- CCFLAGS += -std=c17
endif
# This library is the main target for this makefile. It will contain a minimal
diff --git a/tensorflow/lite/micro/tools/make/ext_libs/xi_tflmlib_vision_p6.patch b/tensorflow/lite/micro/tools/make/ext_libs/xi_tflmlib_vision_p6.patch
new file mode 100644
index 0000000..d7df52f
--- /dev/null
+++ b/tensorflow/lite/micro/tools/make/ext_libs/xi_tflmlib_vision_p6.patch
@@ -0,0 +1,28 @@
+From ed92529a6be7a910462558edcf10070fbb0f2870 Mon Sep 17 00:00:00 2001
+From: Ryan Kuester <kuester@bdti.com>
+Date: Thu, 1 Aug 2024 12:48:12 -0500
+Subject: [PATCH] fix: use <climits> instead of <limits> to access INT_MAX and
+ friends
+
+For compatibility with the C++ library standard, use the header,
+<climits>, to access constants such as INT_MAX.
+---
+ runtime/include/cnnrt_xi.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/runtime/include/cnnrt_xi.h b/runtime/include/cnnrt_xi.h
+index f3a911e..00c74b8 100644
+--- a/runtime/include/cnnrt_xi.h
++++ b/runtime/include/cnnrt_xi.h
+@@ -25,7 +25,7 @@
+ # define INCLUDE_XI_CNN
+ #endif
+
+-#include <limits>
++#include <climits>
+ #include "xi_api.h"
+ #include "xi_cnn_api.h"
+ #include "xi_tile_manager.h"
+--
+2.43.0
+
diff --git a/tensorflow/lite/micro/tools/make/ext_libs/xtensa_download.sh b/tensorflow/lite/micro/tools/make/ext_libs/xtensa_download.sh
index 2c81710..9726980 100755
--- a/tensorflow/lite/micro/tools/make/ext_libs/xtensa_download.sh
+++ b/tensorflow/lite/micro/tools/make/ext_libs/xtensa_download.sh
@@ -38,11 +38,17 @@
source ${3}tensorflow/lite/micro/tools/make/bash_helpers.sh
DOWNLOADS_DIR=${1}
+PATCH=""
-if [[ ${2} == "hifi4" || ${2} == "hifi3" ]]; then
+if [[ ${2} == "hifi3" ]]; then
LIBRARY_URL="http://github.com/foss-xtensa/nnlib-hifi4/raw/master/archive/xa_nnlib_hifi4_09_05_2023.zip"
LIBRARY_DIRNAME="xa_nnlib_hifi4"
LIBRARY_MD5="2a54e056aef73a4fcffde4643998501a"
+elif [[ ${2} == "hifi4" ]]; then
+ LIBRARY_URL="http://github.com/foss-xtensa/nnlib-hifi4/raw/master/archive/xa_nnlib_hifi4_09_05_2023.zip"
+ LIBRARY_DIRNAME="xa_nnlib_hifi4"
+ LIBRARY_MD5="2a54e056aef73a4fcffde4643998501a"
+ PATCH="../../ext_libs/xa_nnlib_hifi4.patch"
elif [[ ${2} == "hifi5" ]]; then
LIBRARY_URL="http://github.com/foss-xtensa/nnlib-hifi5/raw/master/archive/xa_nnlib_hifi5_09_05_2023.zip"
LIBRARY_DIRNAME="xa_nnlib_hifi5"
@@ -51,6 +57,7 @@
LIBRARY_URL="https://github.com/foss-xtensa/tflmlib_vision/raw/main/archive/xi_tflmlib_vision_p6_22_06_29.zip"
LIBRARY_DIRNAME="xi_tflmlib_vision_p6"
LIBRARY_MD5="fea3720d76fdb3a5a337ace7b6081b56"
+ PATCH="../../ext_libs/xi_tflmlib_vision_p6.patch"
else
echo "Attempting to download an unsupported xtensa variant: ${2}"
exit 1
@@ -79,9 +86,9 @@
pushd "${LIBRARY_INSTALL_PATH}" > /dev/null
chmod -R +w ./
- if [[ -f "../../ext_libs/xa_nnlib_${2}.patch" ]]; then
+ if [ "${PATCH}" ]; then
create_git_repo ./
- apply_patch_to_folder ./ "../../ext_libs/xa_nnlib_${2}.patch" "TFLM patch"
+ apply_patch_to_folder ./ ${PATCH} "TFLM patch"
fi
fi
diff --git a/tensorflow/lite/micro/tools/make/targets/arc/arc_common.inc b/tensorflow/lite/micro/tools/make/targets/arc/arc_common.inc
index abc45c3..8809279 100644
--- a/tensorflow/lite/micro/tools/make/targets/arc/arc_common.inc
+++ b/tensorflow/lite/micro/tools/make/targets/arc/arc_common.inc
@@ -64,9 +64,6 @@
PLATFORM_LDFLAGS += $(notdir $(LCF_FILE))
endif
- CXXFLAGS := $(filter-out -std=c++11,$(CXXFLAGS))
- CCFLAGS := $(filter-out -std=c11,$(CCFLAGS))
-
ldflags_to_remove = -Wl,--fatal-warnings -Wl,--gc-sections
LDFLAGS := $(filter-out $(ldflags_to_remove),$(LDFLAGS))
diff --git a/tensorflow/lite/micro/tools/make/targets/ceva_makefile.inc b/tensorflow/lite/micro/tools/make/targets/ceva_makefile.inc
index 5cc8ad1..d0ddc98 100755
--- a/tensorflow/lite/micro/tools/make/targets/ceva_makefile.inc
+++ b/tensorflow/lite/micro/tools/make/targets/ceva_makefile.inc
@@ -33,8 +33,8 @@
-D_LIBCPP_EXTERN_TEMPLATE_INLINE_VISIBILITY=""
-CXXFLAGS := -std=c++11 -DTF_LITE_STATIC_MEMORY
-CCFLAGS := -std=c11 -DTF_LITE_STATIC_MEMORY
+CXXFLAGS := -std=c++17 -DTF_LITE_STATIC_MEMORY
+CCFLAGS := -std=c17 -DTF_LITE_STATIC_MEMORY
ifeq ($(TARGET_ARCH), CEVA_BX1)
PLATFORM_FLAGS += \
diff --git a/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc b/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc
index 0fba906..92527ad 100644
--- a/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc
+++ b/tensorflow/lite/micro/tools/make/targets/xtensa_makefile.inc
@@ -35,6 +35,7 @@
TARGET_ARCH_DEFINES := -D$(shell echo $(TARGET_ARCH) | tr [a-z] [A-Z])
PLATFORM_FLAGS = \
+ -stdlib=libc++ \
-DTF_LITE_MCU_DEBUG_LOG \
-DTF_LITE_USE_CTIME \
--xtensa-core=$(XTENSA_CORE) \
diff --git a/tensorflow/lite/micro/tools/project_generation/Makefile b/tensorflow/lite/micro/tools/project_generation/Makefile
index f14bd90..f73fbdb 100644
--- a/tensorflow/lite/micro/tools/project_generation/Makefile
+++ b/tensorflow/lite/micro/tools/project_generation/Makefile
@@ -72,14 +72,14 @@
endif
CXXFLAGS := \
- -std=c++11 \
+ -std=c++17 \
-fno-rtti \
-fno-exceptions \
-fno-threadsafe-statics \
$(COMMON_FLAGS)
CCFLAGS := \
- -std=c11 \
+ -std=c17 \
$(COMMON_FLAGS)
ARFLAGS := -r