From: Nattapat Chaimanowong Date: Thu, 31 Jan 2019 15:36:39 +0000 (+0000) Subject: IVGCVSW-2580 Integrate serialization schema code generation to build process X-Git-Tag: submit/tizen/20200316.035456~896 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=949f1255a247f3a1a7eabe8c8f96087d02da1d5a;p=platform%2Fupstream%2Farmnn.git IVGCVSW-2580 Integrate serialization schema code generation to build process Change-Id: I092df948346281878be7e0a1d31b0748d99a99b2 Signed-off-by: Nattapat Chaimanowong --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 1bec6d1..edf8ee6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,11 +143,35 @@ if(BUILD_TF_LITE_PARSER) target_include_directories(armnnTfLiteParser PRIVATE src/armnn) target_include_directories(armnnTfLiteParser PRIVATE src/armnnUtils) + target_include_directories(armnnTfLiteParser SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}") target_link_libraries(armnnTfLiteParser ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY}) target_link_libraries(armnnTfLiteParser armnn ${FLATBUFFERS_LIBRARY}) endif() +if(BUILD_ARMNN_SERIALIZER) + add_custom_command ( + OUTPUT src/armnnSerializer/Schema_generated.h + COMMAND ${FLATC_DIR}/flatc -o ${CMAKE_CURRENT_BINARY_DIR}/src/armnnSerializer --cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/Schema.fbs + ) + + set(armnn_serializer_sources) + list(APPEND armnn_serializer_sources + src/armnnSerializer/Schema_generated.h + ) + + add_library_ex(armnnSerializer SHARED ${armnn_serializer_sources}) + + target_include_directories(armnnSerializer PRIVATE src/armnn) + target_include_directories(armnnSerializer PRIVATE src/armnnUtils) + + # System include to suppress warnings for flatbuffers generated files + target_include_directories(armnnSerializer SYSTEM PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/src/armnnSerializer) + + target_link_libraries(armnnSerializer armnn ${FLATBUFFERS_LIBRARY}) +endif() + list(APPEND armnn_sources include/armnn/ArmNN.hpp include/armnn/BackendId.hpp @@ -362,6 +386,9 @@ endif() if(BUILD_TF_LITE_PARSER) install(TARGETS armnnTfLiteParser DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) endif() +if(BUILD_ARMNN_SERIALIZER) + install(TARGETS armnnSerializer DESTINATION ${CMAKE_INSTALL_PREFIX}/lib) +endif() install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include) target_link_libraries(armnn ${Boost_LOG_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY}) @@ -533,6 +560,10 @@ if(BUILD_UNIT_TESTS) target_include_directories(UnitTests PRIVATE src/armnnUtils) target_include_directories(UnitTests PRIVATE src/backends) + if(BUILD_TF_LITE_PARSER) + target_include_directories(UnitTests SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}") + endif() + if(VALGRIND_FOUND) if(HEAP_PROFILING OR LEAK_CHECKING) message("Valgrind is disabled for heap profiling and leak checking builds.") diff --git a/cmake/GlobalConfig.cmake b/cmake/GlobalConfig.cmake index 969b234..7c56ca9 100644 --- a/cmake/GlobalConfig.cmake +++ b/cmake/GlobalConfig.cmake @@ -13,6 +13,8 @@ option(LEAK_CHECKING "Build with leak checking enabled" OFF) option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off) # options used for tensorflow lite support option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF) +option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF) +option(FLATC_DIR "Path to Flatbuffers compiler" OFF) option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF) option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off) @@ -163,29 +165,18 @@ if(BUILD_ONNX_PARSER) include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}") endif() - -# Flatbuffers support for TF Lite -if(BUILD_TF_LITE_PARSER) - find_path(TF_LITE_SCHEMA_INCLUDE_PATH - schema_generated.h - HINTS ${TF_LITE_GENERATED_PATH}) - - if(NOT TF_LITE_SCHEMA_INCLUDE_PATH) - message(WARNING - "Couldn't find 'schema_generated.h' at ${TF_LITE_GENERATED_PATH}. Disabling Tf Lite support") - set(BUILD_TF_LITE_PARSER Off) - else() - message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}") - endif() - +# Flatbuffers support for TF Lite and Armnn Serializer +if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER) # verify we have a valid flatbuffers include path find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include) if(NOT FLATBUFFERS_INCLUDE_PATH) message(WARNING - "Couldn't find 'flatbuffers/flatbuffers.h' at ${FLATBUFFERS_ROOT}/include. Disabling Tf Lite support") + "Couldn't find 'flatbuffers/flatbuffers.h' at ${FLATBUFFERS_ROOT}/include. \ + Disabling Tf Lite and Armnn Serializer support") set(BUILD_TF_LITE_PARSER Off) + set(BUILD_ARMNN_SERIALIZER Off) else() message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}") endif() @@ -196,16 +187,35 @@ if(BUILD_TF_LITE_PARSER) if(NOT FLATBUFFERS_LIBRARY) message(WARNING - "Couldn't find flatbuffers library. Disabling Tf Lite support") + "Couldn't find flatbuffers library. Disabling Tf Lite and Armnn Serializer support") set(BUILD_TF_LITE_PARSER Off) + set(BUILD_ARMNN_SERIALIZER Off) else() message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}") endif() + # Setup includes and libs only if we still want Tf Lite or Armnn Serializer + if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER) + include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}") + endif() +endif() + +# Flatbuffers schema support for TF Lite +if(BUILD_TF_LITE_PARSER) + find_path(TF_LITE_SCHEMA_INCLUDE_PATH + schema_generated.h + HINTS ${TF_LITE_GENERATED_PATH}) + + if(NOT TF_LITE_SCHEMA_INCLUDE_PATH) + message(WARNING + "Couldn't find 'schema_generated.h' at ${TF_LITE_GENERATED_PATH}. Disabling Tf Lite support") + set(BUILD_TF_LITE_PARSER Off) + else() + message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}") + endif() + # Setup includes and libs only if we still want Tf Lite if(BUILD_TF_LITE_PARSER) - include_directories(SYSTEM "${TF_LITE_SCHEMA_INCLUDE_PATH}") - include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}") add_definitions(-DARMNN_TF_LITE_PARSER) add_definitions(-DARMNN_TF_LITE_SCHEMA_PATH="${TF_LITE_SCHEMA_INCLUDE_PATH}/schema.fbs") endif() @@ -346,5 +356,9 @@ if(NOT BUILD_TF_LITE_PARSER) message(STATUS "Tensorflow Lite parser support is disabled") endif() +if(NOT BUILD_ARMNN_SERIALIZER) + message(STATUS "Armnn Serializer support is disabled") +endif() + # ArmNN source files required for all build options include_directories(SYSTEM third-party)