Do not specify -DNDEBUG by default and completely remove -DDEBUG.
Also added explanation for why this is needed and added a BUILD_TYPE=release_with_logs that may be used for benchmarking and profiling. PiperOrigin-RevId: 332589044 Change-Id: Ia7c5f8805a34c6685692081c3eafe600815e08df
This commit is contained in:
parent
877527646a
commit
d6138980ec
@ -15,12 +15,12 @@ limitations under the License.
|
||||
|
||||
#include "tensorflow/lite/micro/debug_log.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifndef TF_LITE_STRIP_ERROR_STRINGS
|
||||
#include <cstdio>
|
||||
#endif
|
||||
|
||||
extern "C" void DebugLog(const char* s) {
|
||||
#ifdef DEBUG
|
||||
#ifndef TF_LITE_STRIP_ERROR_STRINGS
|
||||
fprintf(stderr, "%s", s);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -32,7 +32,6 @@ constexpr int kSizeTensor = 1;
|
||||
constexpr int kOutputTensor = 0;
|
||||
|
||||
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
|
||||
#if defined(DEBUG)
|
||||
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
|
||||
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
|
||||
|
||||
@ -53,7 +52,6 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
|
||||
TF_LITE_KERNEL_LOG(context, "Dynamic tensors are unsupported in tfmicro.");
|
||||
return kTfLiteError;
|
||||
}
|
||||
#endif
|
||||
return kTfLiteOk;
|
||||
}
|
||||
|
||||
|
||||
@ -36,10 +36,8 @@ readable_run make -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET}
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} build BUILD_TYPE=release
|
||||
|
||||
# TODO(b/168334217): enable debug build once it does not fail.
|
||||
#readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
#readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} build BUILD_TYPE=debug
|
||||
|
||||
# Next, build w/o release so that we can run the tests and get additional
|
||||
# debugging info on failures.
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} build
|
||||
|
||||
|
||||
@ -30,6 +30,4 @@ TARGET=sparkfun_edge
|
||||
|
||||
# TODO(b/143715361): downloading first to allow for parallel builds.
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} third_party_downloads
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} micro_speech_bin
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} person_detection_bin
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} magic_wand_bin
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} build
|
||||
|
||||
@ -33,6 +33,7 @@ readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile TAGS=${TAGS} TARGET=${TARGET} third_party_downloads
|
||||
|
||||
# First make sure that the release build succeeds.
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile BUILD_TYPE=release TAGS=${TAGS} TARGET=${TARGET} build
|
||||
|
||||
# Next, build w/o release so that we can run the tests and get additional
|
||||
|
||||
@ -30,9 +30,11 @@ readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile third_party_downloads
|
||||
|
||||
# Next, build w/o TF_LITE_STATIC_MEMORY to catch additional build errors.
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile BUILD_TYPE=no_tf_lite_static_memory build
|
||||
|
||||
# First make sure that the release build succeeds.
|
||||
# Next, make sure that the release build succeeds.
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile BUILD_TYPE=release build
|
||||
|
||||
# Next, build w/o release so that we can run the tests and get additional
|
||||
@ -40,10 +42,6 @@ readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile BUILD_TYPE=re
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -s -j8 -f tensorflow/lite/micro/tools/make/Makefile test
|
||||
|
||||
# Also repeat for the debug build.
|
||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||
readable_run make -s -j8 -f tensorflow/lite/micro/tools/make/Makefile BUILD_TYPE=debug test
|
||||
|
||||
if [[ ${1} != "PRESUBMIT" ]]; then
|
||||
# Most of TFLM external contributors only use make. We are building a subset of
|
||||
# targets with bazel as part of this script to make it easier for external
|
||||
|
||||
@ -104,12 +104,41 @@ ARFLAGS := -r
|
||||
TARGET_TOOLCHAIN_PREFIX :=
|
||||
TARGET_TOOLCHAIN_ROOT :=
|
||||
|
||||
# Specifying BUILD_TYPE=<blah> as part of the make command gives us a few
|
||||
# options to choose from.
|
||||
#
|
||||
# If BUILD_TYPE is not specified, the default build (which should be suitable
|
||||
# most of the time) has all of the error checking logic at the expense of a
|
||||
# latency increase of ~5-10% relative to BUILD_TYPE=release_with_logs.
|
||||
#
|
||||
# This default build is most suited for usual development and testing as is
|
||||
# highlighted by the discussion on this github pull request:
|
||||
# https://github.com/tensorflow/tensorflow/pull/42314#issuecomment-694360567
|
||||
ifeq ($(BUILD_TYPE), debug)
|
||||
CXXFLAGS += -DDEBUG -g
|
||||
CCFLAGS += -DDEBUG -g
|
||||
# Specifying BUILD_TYPE=debug adds debug symbols to the binary (and makes it
|
||||
# larger) and should be used to run a binary with gdb.
|
||||
CXXFLAGS += -g
|
||||
CCFLAGS += -g
|
||||
else ifeq ($(BUILD_TYPE), release)
|
||||
# The 'release' build results in the smallest binary (by virtue of removing
|
||||
# strings from log messages, DCHECKs ...).
|
||||
#
|
||||
# The down-side is that we currently do not have a good mechanism to allow
|
||||
# for logging that is not related to errors (e.g. profiling information, or
|
||||
# logs that help determine if tests pass or fail). As a result, we are unable
|
||||
# to run tests or benchmarks with BUILD_TYPE=release (which is a bit
|
||||
# counter-intuitive). TODO(b/158205789): A global error reporter might help.
|
||||
#
|
||||
# For a close approximation of the release build use
|
||||
# BUILD_TYPE=release_with_logs.
|
||||
CXXFLAGS += -DNDEBUG -DTF_LITE_STRIP_ERROR_STRINGS
|
||||
CCFLAGS += -DNDEBUG -DTF_LITE_STRIP_ERROR_STRINGS
|
||||
else ifeq ($(BUILD_TYPE), release_with_logs)
|
||||
# The latency with BUILD_TYPE=release_with_logs will be close to the 'release'
|
||||
# build and there will still be error logs. This build type may be preferable
|
||||
# for profiling and benchmarking.
|
||||
CXXFLAGS += -DNDEBUG
|
||||
CCFLAGS += -DNDEBUG
|
||||
else ifeq ($(BUILD_TYPE), no_tf_lite_static_memory)
|
||||
# This build should not be used to run any binaries/tests since
|
||||
# TF_LITE_STATIC_MEMORY should be defined for all micro builds. However,
|
||||
@ -119,9 +148,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))
|
||||
else
|
||||
CXXFLAGS += -DNDEBUG
|
||||
CCFLAGS += -DNDEBUG
|
||||
endif
|
||||
|
||||
# This library is the main target for this makefile. It will contain a minimal
|
||||
|
||||
@ -8,8 +8,6 @@ ifeq ($(TARGET), bluepill)
|
||||
$(eval $(call add_third_party_download,$(CMSIS_URL),$(CMSIS_MD5),cmsis,patch_cmsis))
|
||||
$(eval $(call add_third_party_download,$(STM32_BARE_LIB_URL),$(STM32_BARE_LIB_MD5),stm32_bare_lib,))
|
||||
|
||||
# TODO(b/149943573): It may be worthwhile to remove -DNDEBUG if we can get the
|
||||
#bluepill target to compile without it.
|
||||
PLATFORM_FLAGS = \
|
||||
-DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK \
|
||||
-DTF_LITE_MCU_DEBUG_LOG \
|
||||
@ -34,6 +32,11 @@ ifeq ($(TARGET), bluepill)
|
||||
-nostdlib \
|
||||
-g \
|
||||
-Os
|
||||
|
||||
# TODO(b/168334217): Currently we always add -DNDEBUG because the build is
|
||||
# broken w/o it. Remove this workaround once the issue is resolved.
|
||||
PLATFORM_FLAGS += -DNDEBUG
|
||||
|
||||
CXXFLAGS += $(PLATFORM_FLAGS) -fno-rtti -fno-threadsafe-statics \
|
||||
-fno-use-cxa-atexit
|
||||
CCFLAGS += $(PLATFORM_FLAGS)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user