aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Flynn <jim.flynn@arm.com>2021-09-23 12:16:53 +0100
committerKeithARM <keith.davis@arm.com>2021-09-23 15:21:28 +0000
commitfca233eed08f4ec3b793fe76abae540e391f8319 (patch)
tree92c91e0fa06c58d72514ae39fc452b89b9b4b559
parentce083d2ea1964411ce5d8f2ff05f6e0004978703 (diff)
downloadarmnn-fca233eed08f4ec3b793fe76abae540e391f8319.tar.gz
IVGCVSW-6181 patch to allow building against tflite > v2.3
Change-Id: I292add699b2af32fab87b98929fe6fee79fdf356 Signed-off-by: Jim Flynn <jim.flynn@arm.com>
-rw-r--r--CMakeLists.txt14
-rw-r--r--delegate/CMakeLists.txt7
-rw-r--r--delegate/cmake/Modules/FindTfLite.cmake20
-rw-r--r--delegate/cmake/Modules/FindTfLiteSrc.cmake28
-rwxr-xr-xsrc/armnnTfLiteParser/CMakeLists.txt28
-rw-r--r--src/armnnTfLiteParser/TfLiteParser.cpp18
6 files changed, 102 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8e6c1f3495..421afb6d18 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -21,6 +21,20 @@ endforeach()
cmake_policy(SET CMP0057 NEW)
+# If the root of the tensorflow source tree has not been specified
+# and we are trying to build the tensorflow lite parser make
+# our best guess as to where it will be i.e. one directory above
+# the one this CMakeLists.txt file lives in, in a subdirectory
+# called tensorflow
+if (BUILD_TF_LITE_PARSER AND "${TENSORFLOW_ROOT}" STREQUAL "")
+ set(TENSORFLOW_ROOT "${PROJECT_SOURCE_DIR}/../tensorflow" CACHE INTERNAL "")
+ message(STATUS "Set TENSORFLOW_ROOT: ${TENSORFLOW_ROOT}")
+else()
+ message(STATUS "TENSORFLOW_ROOT: ${TENSORFLOW_ROOT}")
+endif()
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/delegate/cmake/Modules/")
+
set(as_subproject Armnn)
macro(find_package)
diff --git a/delegate/CMakeLists.txt b/delegate/CMakeLists.txt
index aed77bf47e..9e4fdd9de3 100644
--- a/delegate/CMakeLists.txt
+++ b/delegate/CMakeLists.txt
@@ -68,6 +68,7 @@ endif()
target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
## Add TfLite v2.3.1 dependency
+find_package(TfLiteSrc REQUIRED MODULE)
find_package(TfLite REQUIRED MODULE)
target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
@@ -115,6 +116,11 @@ target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMN
target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
+add_library(profiling_library_headers INTERFACE)
+target_include_directories(profiling_library_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/profiling>
+ $<INSTALL_INTERFACE:include/profiling_library_headers>)
+
+
set_target_properties(armnnDelegate PROPERTIES VERSION ${DELEGATE_LIB_VERSION} SOVERSION ${DELEGATE_LIB_SOVERSION})
option(BUILD_UNIT_TESTS "Build unit tests" ON)
@@ -232,6 +238,7 @@ if(BUILD_UNIT_TESTS)
target_link_libraries(DelegateUnitTests PRIVATE tflite_headers)
target_link_libraries(DelegateUnitTests PRIVATE flatbuffer_headers)
+ target_link_libraries(DelegateUnitTests PRIVATE profiling_library_headers)
endif()
diff --git a/delegate/cmake/Modules/FindTfLite.cmake b/delegate/cmake/Modules/FindTfLite.cmake
index 7940e9cad7..907c3847cb 100644
--- a/delegate/cmake/Modules/FindTfLite.cmake
+++ b/delegate/cmake/Modules/FindTfLite.cmake
@@ -6,15 +6,19 @@
include(FindPackageHandleStandardArgs)
unset(TFLITE_FOUND)
+#
+# NOTE: this module is used to find the tensorflow lite binary libraries only
+# the FindTfLiteSrc.cmake module is used to find the tensorflow lite include directory.
+# This is to allow components like the Tensorflow lite parser that have a source dependency
+# on tensorflow lite headers but no need to link to the binary libraries to use only the sources
+# and not have an artificial dependency on the libraries.
+#
+
# First look for the static version of tensorflow lite
find_library(TfLite_LIB NAMES "libtensorflow-lite.a" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite)
# If not found then, look for the dynamic library of tensorflow lite
find_library(TfLite_LIB NAMES "libtensorflow_lite_all.so" "libtensorflowlite.so" HINTS ${TFLITE_LIB_ROOT} ${TFLITE_LIB_ROOT}/tensorflow/lite)
-# Set relevant paths
-find_path(TfLite_INCLUDE_DIR NAMES tensorflow/lite third_party HINTS ${TENSORFLOW_ROOT})
-find_path(TfLite_Schema_INCLUDE_PATH schema_generated.h HINTS ${TENSORFLOW_ROOT}/tensorflow/lite/schema)
-
# If the static library was found, gather all of its dependencies
if (TfLite_LIB MATCHES .a$)
message("-- Static tensorflow lite library found, using for ArmNN build")
@@ -32,21 +36,17 @@ if (TfLite_LIB MATCHES .a$)
PATH ${TFLITE_LIB_ROOT}/_deps/flatbuffers-build)
## Set TFLITE_FOUND if all libraries are satisfied for static lib
- find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_INCLUDE_DIR TfLite_LIB TfLite_abseilstrings_LIB TfLite_ruy_LIB TfLite_fftsg_LIB TfLite_fftsg2d_LIB TfLite_farmhash_LIB TfLite_flatbuffers_LIB TfLite_Schema_INCLUDE_PATH)
+ find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB TfLite_abseilstrings_LIB TfLite_ruy_LIB TfLite_fftsg_LIB TfLite_fftsg2d_LIB TfLite_farmhash_LIB TfLite_flatbuffers_LIB)
# Set external variables for usage in CMakeLists.txt
if (TFLITE_FOUND)
set(TfLite_LIB ${TfLite_LIB} ${TfLite_abseilstrings_LIB} ${TfLite_ruy_LIB} ${TfLite_fftsg_LIB} ${TfLite_fftsg2d_LIB} ${TfLite_farmhash_LIB} ${TfLite_flatbuffers_LIB})
- set(TfLite_INCLUDE_DIR ${TfLite_INCLUDE_DIR})
- set(TfLite_Schema_INCLUDE_PATH ${TfLite_Schema_INCLUDE_PATH})
endif ()
elseif (TfLite_LIB MATCHES .so$)
message("-- Dynamic tensorflow lite library found, using for ArmNN build")
- find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_INCLUDE_DIR TfLite_LIB TfLite_Schema_INCLUDE_PATH)
+ find_package_handle_standard_args(TfLite DEFAULT_MSG TfLite_LIB)
## Set external variables for usage in CMakeLists.txt
if (TFLITE_FOUND)
set(TfLite_LIB ${TfLite_LIB})
- set(TfLite_INCLUDE_DIR ${TfLite_INCLUDE_DIR})
- set(TfLite_Schema_INCLUDE_PATH ${TfLite_Schema_INCLUDE_PATH})
endif ()
else()
message(FATAL_ERROR "Could not find a tensorflow lite library to use")
diff --git a/delegate/cmake/Modules/FindTfLiteSrc.cmake b/delegate/cmake/Modules/FindTfLiteSrc.cmake
new file mode 100644
index 0000000000..91833c18e6
--- /dev/null
+++ b/delegate/cmake/Modules/FindTfLiteSrc.cmake
@@ -0,0 +1,28 @@
+#
+# Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+# SPDX-License-Identifier: MIT
+#
+
+include(FindPackageHandleStandardArgs)
+unset(TFLITE_SRC_FOUND)
+
+find_path(TfLite_INCLUDE_DIR
+ NAMES
+ tensorflow/lite
+ third_party
+ HINTS
+ ${TENSORFLOW_ROOT})
+
+find_path(TfLite_Schema_INCLUDE_PATH
+ schema_generated.h
+ HINTS
+ ${TENSORFLOW_ROOT}/tensorflow/lite/schema)
+
+## Set TFLITE_FOUND
+find_package_handle_standard_args(TfLiteSrc DEFAULT_MSG TfLite_INCLUDE_DIR TfLite_Schema_INCLUDE_PATH)
+
+## Set external variables for usage in CMakeLists.txt
+if(TFLITE_SRC_FOUND)
+ set(TfLite_INCLUDE_DIR ${TfLite_INCLUDE_DIR})
+ set(TfLite_Schema_INCLUDE_PATH ${TfLite_Schema_INCLUDE_PATH})
+endif()
diff --git a/src/armnnTfLiteParser/CMakeLists.txt b/src/armnnTfLiteParser/CMakeLists.txt
index 6a02c94b82..0988420dde 100755
--- a/src/armnnTfLiteParser/CMakeLists.txt
+++ b/src/armnnTfLiteParser/CMakeLists.txt
@@ -19,10 +19,30 @@ if(BUILD_TF_LITE_PARSER)
target_include_directories(armnnTfLiteParser PRIVATE ../armnnUtils)
target_include_directories(armnnTfLiteParser SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}")
+
+ # using the armnn/delegate/cmake/Modules/FindTfLiteSrc.cmake to find the TfLite sources
+ # so that we can use the tensorflow/lite/version.h to determine which version of
+ # tensorflow lite we are compiling against
+ find_package(TfLiteSrc REQUIRED MODULE)
+
+ # Various tflite header files are not warning clean
+ # We can't change compilation flags on header files directly, so we need to add them to an interface library first
+ add_library(tflite_version_headers INTERFACE)
+ target_include_directories(tflite_version_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
+ $<INSTALL_INTERFACE:include/tflite_version_headers>)
+
+ target_compile_options(tflite_version_headers INTERFACE -Wno-conversion
+ -Wno-sign-conversion
+ -Wno-unused-parameter
+ -Wno-unused-function)
+
# If user has explicitly specified flatbuffers lib then use that,
# otherwise search for it based on FLATBUFFERS_BUILD_DIR
if (FLATBUFFERS_LIBRARY)
- target_link_libraries(armnnTfLiteParser armnn ${FLATBUFFERS_LIBRARY})
+ target_link_libraries(armnnTfLiteParser
+ armnn
+ tflite_version_headers
+ ${FLATBUFFERS_LIBRARY})
else()
# Use PATH_SUFFIXES to help find separate libs for debug/release on Windows builds
find_library(FLATBUFFERS_LIBRARY_DEBUG NAMES flatbuffers
@@ -31,7 +51,11 @@ if(BUILD_TF_LITE_PARSER)
find_library(FLATBUFFERS_LIBRARY_RELEASE NAMES flatbuffers
HINTS ${FLATBUFFERS_BUILD_DIR}
PATH_SUFFIXES "Release")
- target_link_libraries(armnnTfLiteParser armnn debug ${FLATBUFFERS_LIBRARY_DEBUG} optimized ${FLATBUFFERS_LIBRARY_RELEASE})
+ target_link_libraries(armnnTfLiteParser
+ armnn
+ tflite_version_headers
+ debug ${FLATBUFFERS_LIBRARY_DEBUG}
+ optimized ${FLATBUFFERS_LIBRARY_RELEASE})
endif()
set_target_properties(armnnTfLiteParser PROPERTIES VERSION ${TFLITE_PARSER_LIB_VERSION} SOVERSION ${TFLITE_PARSER_LIB_SOVERSION} )
diff --git a/src/armnnTfLiteParser/TfLiteParser.cpp b/src/armnnTfLiteParser/TfLiteParser.cpp
index bedefdec2f..68dbbd120f 100644
--- a/src/armnnTfLiteParser/TfLiteParser.cpp
+++ b/src/armnnTfLiteParser/TfLiteParser.cpp
@@ -32,6 +32,8 @@
#include <fmt/format.h>
+#include <tensorflow/lite/version.h>
+
#include <algorithm>
#include <fstream>
#include <iostream>
@@ -767,7 +769,14 @@ INetworkPtr TfLiteParserImpl::CreateNetworkFromModel()
for (OperatorPtr const& op : subgraph->operators)
{
auto const& opCodePtr = m_Model->operator_codes[op->opcode_index];
+
+// work around the introduction of the deprecated_builtin_code introduced in 2.4 in a backwards compatible manner
+#if TF_MAJOR_VERSION > 2 || (TF_MAJOR_VERSION == 2 && TF_MINOR_VERSION > 3)
+ auto builtinCode = std::max(opCodePtr->builtin_code,
+ static_cast<tflite::BuiltinOperator>(opCodePtr->deprecated_builtin_code));
+#else
auto builtinCode = opCodePtr->builtin_code;
+#endif
if (builtinCode > tflite::BuiltinOperator_MAX)
{
@@ -887,7 +896,14 @@ void TfLiteParserImpl::ParseUnsupportedOperator(size_t subgraphIndex, size_t ope
const auto & operatorPtr = m_Model->subgraphs[subgraphIndex]->operators[operatorIndex];
auto opcodeIndex = operatorPtr->opcode_index;
+
+// work around the introduction of the deprecated_builtin_code introduced in 2.4 in a backwards compatible manner
+#if TF_MAJOR_VERSION > 2 || (TF_MAJOR_VERSION == 2 && TF_MINOR_VERSION > 3)
+ auto opcode = std::max(m_Model->operator_codes[opcodeIndex]->builtin_code,
+ static_cast<tflite::BuiltinOperator>(m_Model->operator_codes[opcodeIndex]->deprecated_builtin_code));
+#else
auto opcode = m_Model->operator_codes[opcodeIndex]->builtin_code;
+#endif
if (!m_Options || !m_Options.value().m_StandInLayerForUnsupported)
{
@@ -1601,7 +1617,7 @@ void TfLiteParserImpl::ParseSlice(size_t subgraphIndex, size_t operatorIndex)
for (unsigned int i = 0; i < signedSize.size(); ++i)
{
int signedValue = signedSize[i];
-
+
if (signedValue < -1 || signedValue > static_cast<int>(inputTensorInfo.GetShape()[i] - begin[i]))
{
throw ParseException(fmt::format("Invalid value for size {} size must be in range "