Skip to content

Commit

Permalink
[tensorflow-lite] fix TFLITE_ENABLE_MMAP option usage
Browse files Browse the repository at this point in the history
  • Loading branch information
luncliff committed Dec 29, 2023
1 parent 26f37cc commit c714cbd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 20 additions & 12 deletions ports/tensorflow-lite/fix-cmake-use-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 b7f24472..381eb4d9 100644
index b7f24472..ab25a8df 100644
--- a/tensorflow/lite/CMakeLists.txt
+++ b/tensorflow/lite/CMakeLists.txt
@@ -51,14 +51,6 @@ endif()
Expand All @@ -25,7 +25,15 @@ index b7f24472..381eb4d9 100644
find_package(absl REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(farmhash REQUIRED)
@@ -282,9 +275,11 @@ populate_tflite_source_vars("core/tools" TFLITE_CORE_TOOLS_SRCS)
@@ -256,6 +249,7 @@ if(_TFLITE_ENABLE_MMAP)
list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation_disabled\\.cc$")
else()
list(FILTER TFLITE_SRCS EXCLUDE REGEX ".*mmap_allocation\\.cc$")
+ list(APPEND TFLITE_TARGET_PRIVATE_DEFINITIONS "TFLITE_MMAP_DISABLED")
endif()

# Handle TFLite logging source.
@@ -282,9 +276,11 @@ 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)
Expand All @@ -36,11 +44,11 @@ index b7f24472..381eb4d9 100644
+ find_package(Vulkan COMPONENTS Headers) # Vulkan::Headers
+ if(Vulkan_FOUND)
+ list(APPEND TFLITE_TARGET_DEPENDENCIES Vulkan::Headers)
+ endif(Vulkan_FOUND)
+ endif()
# Android NDK already has OpenGL, EGL headers.
if(TFLITE_ENABLE_GLES3)
find_path(OPENGL_EGL_INCLUDE_DIRS "EGL/egl.h" REQUIRED)
@@ -296,9 +291,6 @@ if(TFLITE_ENABLE_GPU)
@@ -296,9 +292,6 @@ if(TFLITE_ENABLE_GPU)
# OpenGL::GLES3 requires CMake 3.27
find_package(OpenGL REQUIRED COMPONENTS GLES3)
list(APPEND TFLITE_TARGET_DEPENDENCIES OpenGL::GLES3 ${OPENGL_egl_LIBRARY})
Expand All @@ -50,7 +58,7 @@ index b7f24472..381eb4d9 100644
endif()
# see delegates/gpu/BUILD and search with //tensorflow:android
if(ANDROID)
@@ -332,7 +324,11 @@ if(TFLITE_ENABLE_GPU)
@@ -332,7 +325,11 @@ if(TFLITE_ENABLE_GPU)
COMMAND ${FLATC} --cpp --scoped-enums -I ${TENSORFLOW_SOURCE_DIR} workgroups.fbs
COMMAND ${FLATC} --cpp --scoped-enums -I ${TENSORFLOW_SOURCE_DIR} compiled_model.fbs
)
Expand All @@ -63,14 +71,14 @@ index b7f24472..381eb4d9 100644
populate_tflite_source_vars("delegates/gpu/gl/compiler" TFLITE_DELEGATES_GPU_GL_COMPILER_SRCS FILTER "(_test)\\.(cc|h)$")
populate_tflite_source_vars("delegates/gpu/gl/converters" TFLITE_DELEGATES_GPU_GL_CONVERTERS_SRCS FILTER "(_test)\\.(cc|h)$")
populate_tflite_source_vars("delegates/gpu/gl/kernels" TFLITE_DELEGATES_GPU_GL_KERNELS_SRCS FILTER "(_test)\\.(cc|h)$")
@@ -524,14 +520,16 @@ if(TFLITE_ENABLE_GPU)
@@ -524,14 +521,16 @@ if(TFLITE_ENABLE_GPU)
target_link_libraries(${lib_name})
endforeach()
endif()
- list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DCL_DELEGATE_NO_GL" "-DEGL_NO_X11")
- list(APPEND TFLITE_TARGET_DEPENDENCIES
+ list(APPEND TFLITE_TARGET_PRIVATE_DEFINITIONS "EGL_NO_X11")
+ message(STATUS "using CL_TARGET_OPENCL_VERSION: ${OpenCL_VERSION_MAJOR}${OpenCL_VERSION_MINOR}0")
+ message(STATUS "Using CL_TARGET_OPENCL_VERSION: ${OpenCL_VERSION_MAJOR}${OpenCL_VERSION_MINOR}0")
+ list(APPEND TFLITE_TARGET_PRIVATE_DEFINITIONS "CL_TARGET_OPENCL_VERSION=${OpenCL_VERSION_MAJOR}${OpenCL_VERSION_MINOR}0")
+ list(APPEND TFLITE_TARGET_DEPENDENCIES OpenCL::OpenCL
absl::any
Expand All @@ -83,7 +91,7 @@ index b7f24472..381eb4d9 100644
populate_tflite_source_vars("delegates/nnapi"
TFLITE_DELEGATES_NNAPI_SRCS
FILTER "(_test_list|_disabled)\\.(cc|h)$"
@@ -556,14 +554,14 @@ else()
@@ -556,14 +555,14 @@ else()
)
endif()
if(TFLITE_ENABLE_XNNPACK)
Expand All @@ -101,7 +109,7 @@ index b7f24472..381eb4d9 100644
)
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "-DTFLITE_BUILD_WITH_XNNPACK_DELEGATE")
endif()
@@ -697,9 +695,10 @@ set(_ALL_TFLITE_HDRS ${_ALL_TFLITE_SRCS})
@@ -697,9 +696,10 @@ set(_ALL_TFLITE_HDRS ${_ALL_TFLITE_SRCS})
list(FILTER _ALL_TFLITE_HDRS INCLUDE REGEX ".*\\.h$")
target_include_directories(tensorflow-lite
PUBLIC $<BUILD_INTERFACE:${TENSORFLOW_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
Expand All @@ -113,7 +121,7 @@ index b7f24472..381eb4d9 100644
Eigen3::Eigen
absl::flags
absl::hash
@@ -713,7 +712,7 @@ target_link_libraries(tensorflow-lite
@@ -713,7 +713,7 @@ target_link_libraries(tensorflow-lite
gemmlowp::gemmlowp
ml_dtypes
ruy::ruy
Expand All @@ -122,15 +130,15 @@ index b7f24472..381eb4d9 100644
${CMAKE_DL_LIBS}
${TFLITE_TARGET_DEPENDENCIES}
)
@@ -738,6 +737,7 @@ if(TFLITE_ENABLE_INSTALL)
@@ -738,6 +738,7 @@ if(TFLITE_ENABLE_INSTALL)
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

foreach(hdr ${_ALL_TFLITE_HDRS})
@@ -770,6 +770,7 @@ if(TFLITE_ENABLE_INSTALL)
@@ -770,6 +771,7 @@ if(TFLITE_ENABLE_INSTALL)
)
endif()

Expand Down
2 changes: 2 additions & 0 deletions ports/tensorflow-lite/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS

if(VCPKG_TARGET_IS_LINUX OR VCPKG_TARGET_IS_ANDROID)
list(APPEND FEATURE_OPTIONS -DTFLITE_ENABLE_MMAP=ON)
else()
list(APPEND FEATURE_OPTIONS -DTFLITE_ENABLE_MMAP=OFF)
endif()
if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS)
list(APPEND GENERATOR_OPTIONS GENERATOR Xcode)
Expand Down

0 comments on commit c714cbd

Please sign in to comment.