Introduce BUILD_TFLITE_BENCHMARK_MODEL option (#2226)
author이상규/동작제어Lab(SR)/Principal Engineer/삼성전자 <sg5.lee@samsung.com>
Thu, 9 Aug 2018 01:21:39 +0000 (10:21 +0900)
committer박세희/동작제어Lab(SR)/Principal Engineer/삼성전자 <saehie.park@samsung.com>
Thu, 9 Aug 2018 01:21:39 +0000 (10:21 +0900)
Related Issue: #1760, #1696

`tflite_benchmark_model` is a tool for profiling a given model.
The tools is under development in tensorflow upstream.

It was not shipped in v1.9.0 release.
Thus I made `tflite_benchmark_model` work for tflite interpreter
by chery-picking needed patches. (#2212)

This patch is a part of full changes. It only introduces build option.

By default, tflite_benchmark_model will not be built.

To build tflite_benchmark_model tool, use

```
$ OPTIONS='-DBUILD_PURE_ARM_COMPUTE=ON -DBUILD_TFLITE_BENCHMARK_MODEL=ON' \
CROSS_BUILD=1 TARGET_ARCH=armv7l make all install
```

Signed-off-by: Sanggyu Lee <sg5.lee@samsung.com>
cmake/CfgOptionFlags.cmake
externals/CMakeLists.txt

index fa2f700..1a9d724 100644 (file)
@@ -10,6 +10,7 @@ option(BUILD_LABS "Build lab projects" ON)
 option(BUILD_ANDROID_NN_RUNTIME_TEST "Build Android NN Runtime Test" ON)
 option(BUILD_DETECTION_APP "Build detection example app" OFF)
 option(BUILD_NNAPI_QUICKCHECK "Build NN API Quickcheck tools" OFF)
+option(BUILD_TFLITE_BENCHMARK_MODEL "Build tflite benchmark model" OFF)
 
 if("${TARGET_ARCH}" STREQUAL "armv7l" AND NOT "${TARGET_OS}" STREQUAL "tizen")
   set(BUILD_PURE_ARM_COMPUTE ON)
index 9c99c01..26cc1b4 100644 (file)
@@ -39,6 +39,15 @@ list(APPEND TFLITE_SRCS ${TFLITE_KERNEL_SRCS})
 
 list(APPEND TFLITE_SRCS "${TFLITE_DEPEND_DIR}/farmhash/src/farmhash.cc")
 
+# Profiling
+if(BUILD_TFLITE_BENCHMARK_MODEL)
+  file(GLOB TFLITE_PROFILING_SRCS "${TENSORFLOW_LITE_BASE}/profiling/*.cc")
+  file(GLOB TFLITE_PROFILING_TESTS "${TENSORFLOW_LITE_BASE}/profiling/*test*.cc")
+  list(REMOVE_ITEM TFLITE_PROFILING_SRCS ${TFLITE_PROFILING_TESTS})
+  list(APPEND TFLITE_PROFILING_SRCS "${TENSORFLOW_BASE}/tensorflow/core/util/stats_calculator.cc")
+  list(APPEND TFLITE_SRCS ${TFLITE_PROFILING_SRCS})
+endif()
+
 list(APPEND TFLITE_INCLUDES "${TFLITE_DEPEND_DIR}/")
 list(APPEND TFLITE_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/tensorflow")
 list(APPEND TFLITE_INCLUDES "${TFLITE_DEPEND_DIR}/gemmlowp")
@@ -77,6 +86,9 @@ endif()
 add_library(tensorflow-lite ${TFLITE_SRCS})
 target_include_directories(tensorflow-lite PUBLIC ${TFLITE_INCLUDES})
 target_compile_definitions(tensorflow-lite PUBLIC "GEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK")
+if(BUILD_TFLITE_BENCHMARK_MODEL)
+  target_compile_definitions(tensorflow-lite PUBLIC "TFLITE_PROFILING_ENABLED")
+endif()
 target_link_libraries(tensorflow-lite eigen3 ${LIB_PTHREAD} dl)
 
 if("${TARGET_OS}" STREQUAL "android")