Skip to content

Commit 4c8dd3b

Browse files
committed
build: replace android portable tensorflow shim
1 parent 9d2c49e commit 4c8dd3b

1 file changed

Lines changed: 43 additions & 90 deletions

File tree

scripts/patch_tfjava.py

Lines changed: 43 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def patch_build_sh(path: Path) -> None:
6161
printf 'INPUT(-lc)\\n' > "${TF_ANDROID_COMPAT_LIB_DIR}/librt.so"
6262
# tfjava builds TensorFlow as an external Bazel repository, so TensorFlow's
6363
# own .bazelrc does not inject framework_shared_object=true for us.
64-
export BUILD_FLAGS="--config=android_arm64 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=framework_shared_object=true --copt=-DANDROID --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --cxxopt=-include --cxxopt=cstdint --host_cxxopt=-include --host_cxxopt=cstdint --copt=-Wno-error=array-parameter --host_copt=-Wno-error=array-parameter --copt=-Wno-error=array-bounds --host_copt=-Wno-error=array-bounds --linkopt=-L${TF_ANDROID_COMPAT_LIB_DIR} --linkopt=-llog --linkopt=-Wl,--allow-multiple-definition"
64+
export BUILD_FLAGS="--config=android_arm64 --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --define=framework_shared_object=true --copt=-DANDROID --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --cxxopt=-include --cxxopt=cstdint --host_cxxopt=-include --host_cxxopt=cstdint --copt=-Wno-error=array-parameter --host_copt=-Wno-error=array-parameter --copt=-Wno-error=array-bounds --host_copt=-Wno-error=array-bounds --linkopt=-L${TF_ANDROID_COMPAT_LIB_DIR} --linkopt=-llog"
6565
export PYTHON_BIN_PATH=$(which python3)
6666
elif [[ -d $BAZEL_VC ]]; then
6767
# Work around compiler issues on Windows documented mainly in configure.py but also elsewhere
@@ -1337,24 +1337,13 @@ def patch_workspace(path: Path) -> None:
13371337

13381338
ANDROID_PORTABLE_LIB_SHIM_PATCH = """--- a/tensorflow/core/BUILD
13391339
+++ b/tensorflow/core/BUILD
1340-
@@ -1378,7 +1378,7 @@
1341-
# --host_crosstool_top=@bazel_tools//tools/cpp:toolchain
1342-
cc_library(
1343-
name = "portable_tensorflow_lib_lite",
1344-
- srcs = if_mobile([":mobile_srcs"]),
1345-
+ srcs = if_ios([":mobile_srcs"]),
1346-
copts = tf_copts(android_optimization_level_override = None) + tf_opts_nortti_if_lite_protos() + if_ios(["-Os"]),
1347-
defines = ["SUPPORT_SELECTIVE_REGISTRATION"] + tf_portable_full_lite_protos(
1348-
full = [],
1349-
@@ -1390,9 +1390,21 @@
1350-
"notap",
1351-
],
1352-
visibility = ["//visibility:public"],
1353-
- deps = [
1354-
- ":protos_all_cc_impl",
1355-
- "//tensorflow/core/util:stats_calculator_portable",
1356-
- "//tensorflow/core:mobile_additional_lib_deps",
1357-
- ] + tf_portable_deps_no_runtime(),
1340+
@@ -1399,18 +1399,34 @@
1341+
)
1342+
1343+
-alias(
1344+
+cc_library(
1345+
name = "android_tensorflow_lib_lite",
1346+
- actual = ":portable_tensorflow_lib_lite",
13581347
+ deps = if_android([
13591348
+ ":core_cpu",
13601349
+ ":core_cpu_internal",
@@ -1366,85 +1355,50 @@ def patch_workspace(path: Path) -> None:
13661355
+ ]) + select({
13671356
+ "//tensorflow:android": [],
13681357
+ "//conditions:default": [
1369-
+ ":protos_all_cc_impl",
1370-
+ "//tensorflow/core/util:stats_calculator_portable",
1371-
+ "//tensorflow/core:mobile_additional_lib_deps",
1358+
+ ":portable_tensorflow_lib_lite",
13721359
+ ],
1373-
+ }) + tf_portable_deps_no_runtime(),
1374-
alwayslink = 1,
1360+
+ }),
1361+
visibility = ["//visibility:public"],
1362+
+ alwayslink = 1,
13751363
)
13761364
1377-
@@ -1485,7 +1497,7 @@
1365+
alias(
1366+
name = "android_tensorflow_lib_lite_nortti",
1367+
- actual = ":portable_tensorflow_lib_lite",
1368+
+ actual = ":android_tensorflow_lib_lite",
1369+
visibility = ["//visibility:public"],
1370+
)
13781371
1379-
cc_library(
1380-
name = "portable_tensorflow_lib",
1381-
- srcs = if_mobile([":portable_op_registrations_and_gradients"]),
1382-
+ srcs = if_ios([":portable_op_registrations_and_gradients"]),
1383-
copts = tf_copts() + tf_opts_nortti_if_lite_protos(),
1384-
features = tf_features_nomodules_if_mobile(),
1385-
tags = [
1386-
@@ -1493,12 +1505,21 @@
1387-
"notap",
1388-
],
1372+
alias(
1373+
name = "android_tensorflow_lib_lite_nortti_lite_protos",
1374+
- actual = ":portable_tensorflow_lib_lite",
1375+
+ actual = ":android_tensorflow_lib_lite",
13891376
visibility = ["//visibility:public"],
1390-
- deps = [
1391-
- ":portable_tensorflow_lib_lite",
1392-
- ":protos_all_cc_impl",
1393-
- "//tensorflow/core/kernels:portable_tensorflow_kernels",
1394-
- "//third_party/eigen3",
1395-
- "@com_google_protobuf//:protobuf",
1396-
- ],
1397-
+ deps = [
1398-
+ ":portable_tensorflow_lib_lite",
1399-
+ ] + select({
1400-
+ "//tensorflow:android": [
1401-
+ ":protos_all_cc_impl",
1402-
+ "//tensorflow/core/kernels:portable_tensorflow_kernels",
1403-
+ "//third_party/eigen3",
1404-
+ "@com_google_protobuf//:protobuf",
1405-
+ ],
1377+
)
1378+
@@ -1478,9 +1494,22 @@
1379+
# Full TensorFlow library with operator support. Use this unless reducing
1380+
# binary size (by packaging a reduced operator set) is a concern.
1381+
-alias(
1382+
+cc_library(
1383+
name = "android_tensorflow_lib",
1384+
- actual = ":portable_tensorflow_lib",
1385+
+ deps = if_android([
1386+
+ ":core_cpu",
1387+
+ ":core_cpu_internal",
1388+
+ ":framework",
1389+
+ ":framework_internal",
1390+
+ ":lib",
1391+
+ ":lib_internal",
1392+
+ ":protos_all_cc",
1393+
+ ]) + select({
1394+
+ "//tensorflow:android": [],
14061395
+ "//conditions:default": [
1407-
+ ":protos_all_cc_impl",
1408-
+ "//tensorflow/core/kernels:portable_tensorflow_kernels",
1409-
+ "//third_party/eigen3",
1410-
+ "@com_google_protobuf//:protobuf",
1396+
+ ":portable_tensorflow_lib",
14111397
+ ],
14121398
+ }),
1413-
alwayslink = 1,
1414-
)
1415-
"""
1416-
1417-
1418-
PORTABLE_KERNELS_QUEUE_DEPS_PATCH = """--- a/tensorflow/core/kernels/BUILD
1419-
+++ b/tensorflow/core/kernels/BUILD
1420-
@@ -6947,13 +6947,27 @@
1421-
],
14221399
visibility = ["//visibility:public"],
1423-
deps = [
1424-
"//tensorflow/core:portable_tensorflow_lib_lite",
1425-
"//tensorflow/core:protos_all_cc_impl",
1426-
+ ":eigen_helpers",
1427-
+ ":image_resizer_state",
1428-
+ ":ops_util",
1429-
+ ":padding_fifo_queue",
1430-
+ ":quantization_utils",
1431-
+ "//tensorflow/core/profiler/lib:traceme",
1432-
+ "//tensorflow/c:kernels",
1433-
+ "//tensorflow/c:ops",
1434-
+ "//tensorflow/c:tf_datatype",
1435-
+ "//tensorflow/c:tf_status",
1436-
+ "//tensorflow/c:tf_tensor",
1437-
+ "//tensorflow/core/util/tensor_bundle",
1438-
+ "//tensorflow/core/util/ctc:ctc_beam_search_lib",
1439-
+ "//tensorflow/core/util/ctc:ctc_loss_calculator_lib",
1440-
"//third_party/eigen3",
1441-
"//third_party/fft2d:fft2d_headers",
1442-
"@com_google_absl//absl/base",
1443-
"@com_google_protobuf//:protobuf",
1444-
"@fft2d",
1445-
"@gemmlowp",
1446-
],
1447-
alwayslink = 1,
1400+
+ alwayslink = 1,
1401+
)
14481402
"""
14491403

14501404
HUNK_HEADER_RE = re.compile(
@@ -1533,7 +1487,6 @@ def write_tensorflow_android_absl_patch(path: Path) -> None:
15331487
text += SAVED_MODEL_ANDROID_LOADER_PATCH
15341488
text += TENSORFLOW_FRAMEWORK_ANDROID_PATCH
15351489
text += normalize_unified_diff_hunk_counts(ANDROID_PORTABLE_LIB_SHIM_PATCH)
1536-
text += PORTABLE_KERNELS_QUEUE_DEPS_PATCH
15371490
if not text.endswith("\n"):
15381491
text += "\n"
15391492
path.write_text(text, encoding="utf-8")

0 commit comments

Comments
 (0)