Skip to content

Commit

Permalink
build: begin using -std=c++17 and c17 in Makefile builds (#2648)
Browse files Browse the repository at this point in the history
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=#2650
  • Loading branch information
rkuester authored Aug 1, 2024
1 parent f309046 commit 6c6e9b3
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion tensorflow/lite/micro/docs/new_platform_support.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hardware to run inference on TfLite models.
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
Expand Down
11 changes: 2 additions & 9 deletions tensorflow/lite/micro/tools/make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ifeq ($(TARGET), $(HOST_OS))
endif

CXXFLAGS := \
-std=c++11 \
-std=c++17 \
-fno-rtti \
-fno-exceptions \
-fno-threadsafe-statics \
Expand All @@ -191,7 +191,7 @@ CXXFLAGS := \

CCFLAGS := \
-Wimplicit-function-declaration \
-std=c11 \
-std=c17 \
$(COMMON_FLAGS)

ARFLAGS := -r
Expand Down Expand Up @@ -257,13 +257,6 @@ else ifeq ($(BUILD_TYPE), no_tf_lite_static_memory)
# 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

13 changes: 10 additions & 3 deletions tensorflow/lite/micro/tools/make/ext_libs/xtensa_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,17 @@ set -e
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"
Expand All @@ -51,6 +57,7 @@ elif [[ ${2} == "vision_p6" ]]; then
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
Expand Down Expand Up @@ -79,9 +86,9 @@ else

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

Expand Down
3 changes: 0 additions & 3 deletions tensorflow/lite/micro/tools/make/targets/arc/arc_common.inc
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ ifneq ($(LCF_FILE), )
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))

Expand Down
4 changes: 2 additions & 2 deletions tensorflow/lite/micro/tools/make/targets/ceva_makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ $(TARGET_ARCH_DEFINES) \
-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 += \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ endif
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) \
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/lite/micro/tools/project_generation/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ ifeq ($(BUILD_TYPE), cmsis_nn)
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
Expand Down

0 comments on commit 6c6e9b3

Please sign in to comment.