PR #43509: Build benchmarks as part of make build
Imported from GitHub PR https://github.com/tensorflow/tensorflow/pull/43509 This should make it easier to ensure that benchmarks can be run on a variety of platforms. Note that in light of #43510 we may additionally want to build bluepill with TAGS=cmsis-nn but keeping that as a separate change in the interest of incrementally improving our CI coverage. Manually confirmed that `make build` now also builds the benchmarks. Copybara import of the project: -- c0052e8f095ebfe8996a192e39898e744cbd70bc by Advait Jain <advaitjain@users.noreply.github.com>: Build benchmarks as part of `make build` This should make it easier to ensure that benchmarks can be run on a variety of platforms. PiperOrigin-RevId: 335328522 Change-Id: I5420440e666ffa815729d5167ddc0ef9d3637474
This commit is contained in:
parent
edeb46930e
commit
f9071b3978
@ -27,8 +27,15 @@ tensorflow/lite/micro/examples/person_detection_experimental/person_detect_model
|
|||||||
$(eval $(call microlite_test,keyword_benchmark,\
|
$(eval $(call microlite_test,keyword_benchmark,\
|
||||||
$(KEYWORD_BENCHMARK_SRCS),$(KEYWORD_BENCHMARK_HDRS)))
|
$(KEYWORD_BENCHMARK_SRCS),$(KEYWORD_BENCHMARK_HDRS)))
|
||||||
|
|
||||||
|
# We can not build the person detection benchmarks for STM32F4 due to
|
||||||
|
# insufficient flash (see issue #43743 for more details). Currently disabling
|
||||||
|
# this benchmark for STM32F4 but we can revisit this later.
|
||||||
|
ifneq ($(TARGET), stm32f4)
|
||||||
|
|
||||||
$(eval $(call microlite_test,person_detection_benchmark,\
|
$(eval $(call microlite_test,person_detection_benchmark,\
|
||||||
$(PERSON_DETECTION_BENCHMARK_SRCS),$(PERSON_DETECTION_BENCHMARK_HDRS)))
|
$(PERSON_DETECTION_BENCHMARK_SRCS),$(PERSON_DETECTION_BENCHMARK_HDRS)))
|
||||||
|
|
||||||
$(eval $(call microlite_test,person_detection_experimental_benchmark,\
|
$(eval $(call microlite_test,person_detection_experimental_benchmark,\
|
||||||
$(PERSON_DETECTION_EXPERIMENTAL_BENCHMARK_SRCS),$(PERSON_DETECTION_EXPERIMENTAL_BENCHMARK_HDRS)))
|
$(PERSON_DETECTION_EXPERIMENTAL_BENCHMARK_SRCS),$(PERSON_DETECTION_EXPERIMENTAL_BENCHMARK_HDRS)))
|
||||||
|
|
||||||
|
endif
|
||||||
|
@ -43,22 +43,22 @@ extern tflite::ErrorReporter* reporter;
|
|||||||
return 0; \
|
return 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TF_LITE_MICRO_BENCHMARK(func) \
|
#define TF_LITE_MICRO_BENCHMARK(func) \
|
||||||
if (tflite::ticks_per_second() == 0) { \
|
if (tflite::ticks_per_second() == 0) { \
|
||||||
TF_LITE_REPORT_ERROR(micro_benchmark::reporter, \
|
TF_LITE_REPORT_ERROR(micro_benchmark::reporter, \
|
||||||
"no timer implementation found"); \
|
"no timer implementation found"); \
|
||||||
return 0; \
|
return 0; \
|
||||||
} \
|
} \
|
||||||
start_ticks = tflite::GetCurrentTimeTicks(); \
|
start_ticks = tflite::GetCurrentTimeTicks(); \
|
||||||
func; \
|
func; \
|
||||||
duration_ticks = tflite::GetCurrentTimeTicks() - start_ticks; \
|
duration_ticks = tflite::GetCurrentTimeTicks() - start_ticks; \
|
||||||
if (duration_ticks > INT_MAX / 1000) { \
|
if (duration_ticks > INT_MAX / 1000) { \
|
||||||
duration_ms = duration_ticks / (tflite::ticks_per_second() / 1000); \
|
duration_ms = duration_ticks / (tflite::ticks_per_second() / 1000); \
|
||||||
} else { \
|
} else { \
|
||||||
duration_ms = (duration_ticks * 1000) / tflite::ticks_per_second(); \
|
duration_ms = (duration_ticks * 1000) / tflite::ticks_per_second(); \
|
||||||
} \
|
} \
|
||||||
TF_LITE_REPORT_ERROR(micro_benchmark::reporter, "%s took %d ticks (%d ms)", \
|
micro_benchmark::reporter->Report("%s took %d ticks (%d ms)", #func, \
|
||||||
#func, duration_ticks, duration_ms);
|
duration_ticks, duration_ms);
|
||||||
|
|
||||||
template <typename inputT>
|
template <typename inputT>
|
||||||
class MicroBenchmarkRunner {
|
class MicroBenchmarkRunner {
|
||||||
|
@ -24,10 +24,13 @@ cd "${ROOT_DIR}"
|
|||||||
|
|
||||||
source tensorflow/lite/micro/tools/ci_build/helper_functions.sh
|
source tensorflow/lite/micro/tools/ci_build/helper_functions.sh
|
||||||
|
|
||||||
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
|
||||||
|
|
||||||
TARGET=sparkfun_edge
|
TARGET=sparkfun_edge
|
||||||
|
|
||||||
# TODO(b/143715361): downloading first to allow for parallel builds.
|
# 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 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} third_party_downloads
|
||||||
|
|
||||||
|
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
|
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} build
|
||||||
|
|
||||||
|
readable_run make -f tensorflow/lite/micro/tools/make/Makefile clean
|
||||||
|
readable_run make -j8 -f tensorflow/lite/micro/tools/make/Makefile TARGET=${TARGET} TAGS=cmsis-nn build
|
||||||
|
@ -459,6 +459,7 @@ define microlite_test
|
|||||||
ifeq (,$(findstring _test, $(1)))
|
ifeq (,$(findstring _test, $(1)))
|
||||||
$(eval $(call generate_project_third_party_parsing))
|
$(eval $(call generate_project_third_party_parsing))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(1)_LOCAL_SRCS := $(2)
|
$(1)_LOCAL_SRCS := $(2)
|
||||||
$(1)_LOCAL_SRCS := $$(call specialize,$$($(1)_LOCAL_SRCS))
|
$(1)_LOCAL_SRCS := $$(call specialize,$$($(1)_LOCAL_SRCS))
|
||||||
ALL_SRCS += $$($(1)_LOCAL_SRCS)
|
ALL_SRCS += $$($(1)_LOCAL_SRCS)
|
||||||
@ -476,10 +477,23 @@ $(1)_bin: $$($(1)_BINARY).bin
|
|||||||
test_$(1): $$($(1)_BINARY)
|
test_$(1): $$($(1)_BINARY)
|
||||||
@test -f $$(TEST_SCRIPT) || (echo 'Unable to find the test script. Is the software emulation available in $$(TARGET)?'; exit 1)
|
@test -f $$(TEST_SCRIPT) || (echo 'Unable to find the test script. Is the software emulation available in $$(TARGET)?'; exit 1)
|
||||||
$$(TEST_SCRIPT) $$($(1)_BINARY) '~~~ALL TESTS PASSED~~~'
|
$$(TEST_SCRIPT) $$($(1)_BINARY) '~~~ALL TESTS PASSED~~~'
|
||||||
|
|
||||||
ifneq (,$(findstring _test,$(1)))
|
ifneq (,$(findstring _test,$(1)))
|
||||||
MICROLITE_TEST_TARGETS += test_$(1)
|
MICROLITE_TEST_TARGETS += test_$(1)
|
||||||
MICROLITE_BUILD_TARGETS += $$($(1)_BINARY)
|
MICROLITE_BUILD_TARGETS += $$($(1)_BINARY)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# The ifneq can make is seem that the body of the if block is executed when
|
||||||
|
# _benchmark is not found in $(1). Actually, the check is saying that if
|
||||||
|
# findstring does not return empty, i.e. if _benchmark is found in $(1), we
|
||||||
|
# should add something to the MICROLITE_BUILD_TARGETS.
|
||||||
|
#
|
||||||
|
# This ensures that a `make build` command will builds all the tests and
|
||||||
|
# benchmarks, though `make test` will only run the tests.
|
||||||
|
ifneq (,$(findstring _benchmark,$(1)))
|
||||||
|
MICROLITE_BUILD_TARGETS += $$($(1)_BINARY)
|
||||||
|
endif
|
||||||
|
|
||||||
$(eval $(call generate_microlite_projects,$(1),$(call specialize,$(2)),$(3)))
|
$(eval $(call generate_microlite_projects,$(1),$(call specialize,$(2)),$(3)))
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user