Skip to content

Commit

Permalink
[tensorflow-lite] update to v2.18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luncliff committed Nov 9, 2024
1 parent e1e294e commit 39e483e
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 109 deletions.
11 changes: 8 additions & 3 deletions ports/tensorflow-lite/fix-cmake-c-api.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
index b646abf5..0e27bc00 100644
index c89653fa..42c8c22b 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -701,6 +701,34 @@ target_compile_definitions(tensorflow-lite
@@ -747,6 +747,39 @@ target_compile_definitions(tensorflow-lite
)
add_library(${PROJECT_NAME}::tensorflowlite ALIAS tensorflow-lite)

Expand All @@ -18,6 +18,11 @@ index b646abf5..0e27bc00 100644
+ c/c_api_internal.h
+ c/c_api_types.h
+ c/common.h
+ c/c_api_opaque_internal.cc
+ c/c_api_opaque_internal.h
+ c/c_api_opaque.h
+ c/common_internal.cc
+ c/common_internal.h
+)
+target_include_directories(tensorflow-lite PRIVATE c)
+# set_target_properties(tensorflow-lite PROPERTEIS
Expand All @@ -37,7 +42,7 @@ index b646abf5..0e27bc00 100644
# The install targets.
if(TFLITE_ENABLE_INSTALL)
install(
@@ -708,6 +736,7 @@ if(TFLITE_ENABLE_INSTALL)
@@ -754,6 +787,7 @@ if(TFLITE_ENABLE_INSTALL)
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
89 changes: 61 additions & 28 deletions ports/tensorflow-lite/fix-cmake-vcpkg.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/tensorflow/lite/CMakeLists.txt b/tensorflow/lite/CMakeLists.txt
index b79818f3..b646abf5 100644
index bce9627f..c89653fa 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -52,14 +52,6 @@ set(TF_SOURCE_DIR "${TENSORFLOW_SOURCE_DIR}/tensorflow")
Expand All @@ -17,17 +17,40 @@ index b79818f3..b646abf5 100644
include(GNUInstallDirs)
include(CMakeDependentOption)
option(TFLITE_ENABLE_INSTALL "Enable install rule" OFF)
@@ -84,7 +76,7 @@ if(TFLITE_KERNEL_TEST AND ${CMAKE_CROSSCOMPILING})
@@ -87,7 +79,7 @@ if(${CMAKE_CROSSCOMPILING})
set(FLATC_PATHS
${TFLITE_HOST_TOOLS_DIR}
${TFLITE_HOST_TOOLS_DIR}/bin
- ${TFLITE_HOST_TOOLS_DIR}/flatbuffers-flatc/bin
+ ${TFLITE_HOST_TOOLS_DIR}/flatbuffers
)
find_program(FLATC_BIN flatc PATHS ${FLATC_PATHS})
if(${FLATC_BIN} STREQUAL "FLATC_BIN-NOTFOUND")
@@ -97,11 +89,10 @@ if(${CMAKE_CROSSCOMPILING})
set(FLATBUFFERS_FLATC_EXECUTABLE "${FLATC_BIN}")
endif()
else()
- set(FLATBUFFERS_FLATC_EXECUTABLE "${CMAKE_BINARY_DIR}/flatbuffers-flatc/bin/flatc")
- set(FLATC_TARGET "flatbuffers-flatc")
+ find_program(FLATBUFFERS_FLATC_EXECUTABLE NAMES flatc PATHS ${FLATC_PATHS} REQUIRED)
endif()

-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(_TFLITE_ENABLE_RUY "${TFLITE_ENABLE_RUY}")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
@@ -243,6 +235,15 @@ if(CMAKE_SYSTEM_NAME MATCHES "Android")
${ANDROID_ANDROID_LIB}
@@ -204,7 +195,7 @@ if(TFLITE_ENABLE_XNNPACK)
"${PTHREADPOOL_SOURCE_DIR}"
"${CMAKE_BINARY_DIR}/pthreadpool")
endif()
- list(APPEND TFLITE_TARGET_DEPENDENCIES pthreadpool)
+ list(APPEND TFLITE_TARGET_DEPENDENCIES "${PTHREADPOOL_LIB}")
endif()
set(TF_TARGET_PRIVATE_OPTIONS "")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang$")
@@ -259,6 +250,15 @@ if(CMAKE_SYSTEM_NAME MATCHES "Android")
log
)
endif()
+if(CMAKE_SYSTEM_NAME MATCHES Windows) # Windows|WindowsStore
Expand All @@ -37,12 +60,12 @@ index b79818f3..b646abf5 100644
+ _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
+ _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
+ )
+ list(APPEND TFLITE_TARGET_PRIVATE_OPTIONS /Zc:__cplusplus)
+ list(APPEND TFLITE_TARGET_PRIVATE_OPTIONS "/Zc:__cplusplus")
+endif()
# Build a list of source files to compile into the TF Lite library.
populate_tflite_source_vars("." TFLITE_SRCS)
if(CMAKE_SYSTEM_NAME MATCHES "Windows" AND BUILD_SHARED_LIBS)
@@ -279,8 +280,15 @@ populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
@@ -289,8 +289,15 @@ populate_tflite_source_vars("core" TFLITE_CORE_SRCS)
populate_tflite_source_vars(
"core/acceleration/configuration" TFLITE_CORE_ACCELERATION_SRCS
FILTER "xnnpack_plugin.*"
Expand All @@ -58,9 +81,9 @@ index b79818f3..b646abf5 100644
populate_tflite_source_vars("core/api" TFLITE_CORE_API_SRCS)
populate_tflite_source_vars("core/async" TFLITE_CORE_ASYNC_SRCS)
populate_tflite_source_vars("core/async/c" TFLITE_CORE_ASYNC_C_SRCS)
@@ -296,13 +304,16 @@ populate_tflite_source_vars("core/async/interop/c" TFLITE_CORE_ASYNC_INTEROP_C_S
populate_tflite_source_vars("delegates/utils" TFLITE_DELEGATES_UTILS_SRCS)
populate_tflite_source_vars("async" TFLITE_ASYNC_SRCS)
@@ -303,13 +310,16 @@ populate_tflite_source_vars("core/tools" TFLITE_CORE_TOOLS_SRCS)
populate_tflite_source_vars("c" TFLITE_C_SRCS)
populate_tflite_source_vars("delegates" TFLITE_DELEGATES_SRCS)
if(TFLITE_ENABLE_GPU)
- find_package(opencl_headers REQUIRED)
- find_package(vulkan_headers REQUIRED)
Expand All @@ -80,7 +103,7 @@ index b79818f3..b646abf5 100644
endif()
populate_tflite_source_vars(
"delegates/gpu/cl" TFLITE_DELEGATES_GPU_CL_SRCS
@@ -388,6 +399,8 @@ if(TFLITE_ENABLE_GPU)
@@ -397,6 +407,8 @@ if(TFLITE_ENABLE_GPU)
# libmetal_delegate library
#
enable_language(OBJCXX)
Expand All @@ -89,7 +112,7 @@ index b79818f3..b646abf5 100644
list(APPEND TFLITE_DELEGATES_METAL_SRCS
${TFLITE_SOURCE_DIR}/delegates/gpu/metal_delegate.mm
${TFLITE_SOURCE_DIR}/delegates/gpu/metal/buffer.cc
@@ -402,11 +415,11 @@ if(TFLITE_ENABLE_GPU)
@@ -411,11 +423,11 @@ if(TFLITE_ENABLE_GPU)
add_library(metal_delegate STATIC
${TFLITE_DELEGATES_METAL_SRCS}
)
Expand All @@ -106,7 +129,7 @@ index b79818f3..b646abf5 100644
#
# generate flatbuffers header for inference_context
#
@@ -438,40 +451,36 @@ if(TFLITE_ENABLE_GPU)
@@ -447,40 +459,36 @@ if(TFLITE_ENABLE_GPU)
metal_device
metal_spatial_tensor
)
Expand Down Expand Up @@ -170,7 +193,7 @@ index b79818f3..b646abf5 100644
populate_tflite_source_vars("delegates/nnapi"
TFLITE_DELEGATES_NNAPI_SRCS
FILTER "(_test_list|_disabled)\\.(cc|h)$"
@@ -481,8 +493,18 @@ if(_TFLITE_ENABLE_NNAPI)
@@ -490,8 +498,18 @@ if(_TFLITE_ENABLE_NNAPI)
)

list(APPEND TFLITE_NNAPI_SRCS
Expand All @@ -189,25 +212,44 @@ index b79818f3..b646abf5 100644

if(${TFLITE_ENABLE_NNAPI_VERBOSE_VALIDATION})
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DNNAPI_VERBOSE_VALIDATION")
@@ -496,14 +518,14 @@ else()
@@ -505,24 +523,16 @@ else()
)
endif()
if(TFLITE_ENABLE_XNNPACK)
- find_package(fp16_headers REQUIRED)
- find_package(XNNPACK REQUIRED)
+ find_path(FP16_INCLUDE_DIRS "fp16.h" REQUIRED)
+ find_library(XNNPACK_LIBRARY NAMES xnnpack XNNPACK REQUIRED)
+ find_library(XNNPACK_LIBRARY NAMES XNNPACK REQUIRED)
populate_tflite_source_vars("delegates/xnnpack"
TFLITE_DELEGATES_XNNPACK_SRCS
FILTER ".*(_test|_tester)\\.(cc|h)"
)
- add_custom_command(
- OUTPUT "${PROJECT_BINARY_DIR}/tensorflow/lite/delegates/xnnpack/weight_cache_schema_generated.h"
- COMMAND "${FLATBUFFERS_FLATC_EXECUTABLE}" -c
- -o "${PROJECT_BINARY_DIR}/tensorflow/lite/delegates/xnnpack/"
- --gen-mutable --gen-object-api
- "${TFLITE_SOURCE_DIR}/delegates/xnnpack/weight_cache_schema.fbs"
- DEPENDS "${FLATC_TARGET}" "${TFLITE_SOURCE_DIR}/delegates/xnnpack/weight_cache_schema.fbs"
- )

add_library(xnnpack-delegate STATIC
"${TFLITE_DELEGATES_XNNPACK_SRCS}"
- "${PROJECT_BINARY_DIR}/tensorflow/lite/delegates/xnnpack/weight_cache_schema_generated.h"
+ "${TFLITE_SOURCE_DIR}/delegates/xnnpack/weight_cache_schema_generated.h"
)
target_include_directories(xnnpack-delegate
PUBLIC $<BUILD_INTERFACE:${TENSORFLOW_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
@@ -543,7 +553,7 @@ if(TFLITE_ENABLE_XNNPACK)

list(APPEND TFLITE_TARGET_DEPENDENCIES
xnnpack-delegate
- XNNPACK
+ ${XNNPACK_LIBRARY}
)
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DTFLITE_BUILD_WITH_XNNPACK_DELEGATE")
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DXNNPACK_DELEGATE_ENABLE_QS8")
@@ -647,7 +669,7 @@ target_include_directories(tensorflow-lite
@@ -706,7 +716,7 @@ target_include_directories(tensorflow-lite
PUBLIC $<BUILD_INTERFACE:${TENSORFLOW_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(tensorflow-lite
Expand All @@ -216,16 +258,7 @@ index b79818f3..b646abf5 100644
Eigen3::Eigen
absl::flags
absl::hash
@@ -661,7 +683,7 @@ target_link_libraries(tensorflow-lite
gemmlowp::gemmlowp
ml_dtypes
ruy::ruy
- pthreadpool
+ ${PTHREADPOOL_LIB}
${CMAKE_DL_LIBS}
${TFLITE_TARGET_DEPENDENCIES}
)
@@ -674,6 +696,9 @@ target_compile_options(tensorflow-lite
@@ -732,6 +742,9 @@ target_compile_options(tensorflow-lite
PUBLIC ${TFLITE_TARGET_PUBLIC_OPTIONS}
PRIVATE ${TFLITE_TARGET_PRIVATE_OPTIONS}
)
Expand All @@ -235,7 +268,7 @@ index b79818f3..b646abf5 100644
add_library(${PROJECT_NAME}::tensorflowlite ALIAS tensorflow-lite)

# The install targets.
@@ -693,6 +718,13 @@ if(TFLITE_ENABLE_INSTALL)
@@ -751,6 +764,13 @@ if(TFLITE_ENABLE_INSTALL)
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tensorflow/lite/${dir}"
)
endforeach()
Expand All @@ -249,7 +282,7 @@ index b79818f3..b646abf5 100644

install(
EXPORT ${PROJECT_NAME}Targets
@@ -715,6 +747,7 @@ if(TFLITE_ENABLE_INSTALL)
@@ -773,6 +793,7 @@ if(TFLITE_ENABLE_INSTALL)
)
endif()

Expand Down
Loading

0 comments on commit 39e483e

Please sign in to comment.