Skip to content

Commit 78aa9d8

Browse files
committed
Fix build for flex ops delegate
1 parent 50b9680 commit 78aa9d8

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(TFLITE_TAG "v2.4.1" CACHE STRING "Version of TFLite to build")
2121
set(BAZEL_BINARY "/usr/bin/bazel" CACHE STRING "Location of bazel binary on host")
2222
option(TFLITE_BAZEL_BUILD "Build tflite bazel" OFF)
2323
option(TFLITE_ENABLE_RUY "Use RUY library in TFLite build" ON)
24+
option(TFLITE_ENABLE_XNNPACK "Build backend with xnnpack delgate support" ON)
2425
option(TFLITE_ENABLE_FLEX_OPS "Build tflite with flex ops support (must build with bazel)" OFF)
2526

2627
# ArmNN Options
@@ -132,8 +133,6 @@ set(TFLITE_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/external/tensorflow_lite)
132133

133134
if (TFLITE_BAZEL_BUILD)
134135
SET(BAZEL_BUILD_FLAGS
135-
"--define=tflite_with_xnnpack=true"
136-
"--define=with_select_tf_ops=true"
137136
"--config=monolithic"
138137
"-c" "opt"
139138
)
@@ -144,10 +143,16 @@ if (TFLITE_BAZEL_BUILD)
144143
LIST(APPEND BAZEL_BUILD_FLAGS "--define=tflite_with_ruy=false")
145144
endif()
146145

146+
if (TFLITE_ENABLE_XNNPACK)
147+
LIST(APPEND BAZEL_BUILD_FLAGS "--define=tflite_with_xnnpack=true")
148+
else()
149+
LIST(APPEND BAZEL_BUILD_FLAGS "--define=tflite_with_xnnpack=false")
150+
endif()
151+
147152
if (TFLITE_ENABLE_FLEX_OPS)
148-
LIST(APPEND BAZEL_BUILD_FLAGS "--define=with_select_tf_ops=true")
153+
SET(TFLITE_PATCH_COMMAND "git" "apply" "${CMAKE_CURRENT_SOURCE_DIR}/patches/tflite_bazel_build.patch" "||" "true")
149154
else()
150-
LIST(APPEND BAZEL_BUILD_FLAGS "--define=with_select_tf_ops=false")
155+
SET(TFLITE_PATCH_COMMAND "")
151156
endif()
152157

153158
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
@@ -163,7 +168,8 @@ if (TFLITE_BAZEL_BUILD)
163168
GIT_REPOSITORY https://github.com/tensorflow/tensorflow.git
164169
GIT_TAG ${TFLITE_TAG}
165170
GIT_SHALLOW ON
166-
PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/xnnpack_commit.patch || true # patch updates the commit hash for xnnpack for tensorflow v2.4.1
171+
PATCH_COMMAND git apply ${CMAKE_CURRENT_SOURCE_DIR}/patches/tflite.patch || true # patch updates the commit hash for xnnpack for tensorflow v2.4.1
172+
COMMAND ${TFLITE_PATCH_COMMAND}
167173
CONFIGURE_COMMAND ""
168174
BUILD_COMMAND ${BAZEL_BINARY} build ${BAZEL_BUILD_FLAGS} //tensorflow/lite:libtensorflowlite.so
169175
BUILD_IN_SOURCE ON

patches/tflite_bazel_build.patch

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/tensorflow/lite/BUILD b/tensorflow/lite/BUILD
2+
index 597f81194cd..81db9eafed5 100644
3+
--- a/tensorflow/lite/BUILD
4+
+++ b/tensorflow/lite/BUILD
5+
@@ -775,6 +775,7 @@ tflite_cc_shared_object(
6+
":tflite_exported_symbols.lds",
7+
":tflite_version_script.lds",
8+
"//tensorflow/lite/kernels:builtin_ops_all_linked",
9+
+ "//tensorflow/lite/delegates/flex:delegate",
10+
],
11+
)
12+

0 commit comments

Comments
 (0)