Skip to content

Commit ac80c6b

Browse files
trevor-mnluehr
authored andcommitted
[TF1] Port of dynamic pywrap - pywrap_tf_internal loads TF symbols from libtf_cc.so instead of duplicating them
1 parent 55be396 commit ac80c6b

File tree

21 files changed

+329
-96
lines changed

21 files changed

+329
-96
lines changed

.bazelrc

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ build --define=grpc_no_ares=true
195195
# Modular TF build options
196196
build:dynamic_kernels --define=dynamic_loaded_kernels=true
197197
build:dynamic_kernels --copt=-DAUTOLOAD_DYNAMIC_KERNELS
198+
build:dynamic_pywrap --define=dynamic_pywrap=true
198199

199200
# Build TF with C++ 17 features.
200201
build:c++17 --cxxopt=-std=c++1z
@@ -216,6 +217,9 @@ build:short_logs --output_filter=DONT_MATCH_ANYTHING
216217
build --cxxopt=-std=c++14
217218
build --host_cxxopt=-std=c++14
218219

220+
# Use dynamic pywrap by default
221+
build --config=dynamic_pywrap
222+
219223
# Instruction set optimizations
220224
# TODO(gunan): Create a feature in toolchains for avx/avx2 to
221225
# avoid having to define linux/win separately.

tensorflow/BUILD

+20-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ load(
3131
"//third_party/mkl:build_defs.bzl",
3232
"if_mkl_ml",
3333
)
34+
load("//tensorflow/core/platform:default/build_config_root.bzl", "if_dynamic_pywrap")
3435

3536
package(
3637
default_visibility = [":internal"],
@@ -464,6 +465,16 @@ config_setting(
464465
visibility = ["//visibility:public"],
465466
)
466467

468+
# Enables pywrap_tensorflow_internal to load TensorFlow symbols from libtensorflow_cc instead of duplicating them.
469+
config_setting(
470+
name = "dynamic_pywrap",
471+
define_values = {
472+
"dynamic_pywrap": "true",
473+
"framework_shared_object": "true",
474+
},
475+
visibility = ["//visibility:public"],
476+
)
477+
467478
# DO NOT ADD ANY NEW EXCEPTIONS TO THIS LIST!
468479
# Instead, please use public APIs or public build rules TF provides.
469480
# If you need functionality that is not exposed, we will work with you to expand our public APIs.
@@ -676,7 +687,15 @@ tf_cc_shared_object(
676687
"//tensorflow/contrib/tensor_forest:model_ops_lib",
677688
"//tensorflow/contrib/tensor_forest:forest_proto_impl",
678689
"//tensorflow/contrib/tensor_forest/kernels/v4:decision-tree-resource_impl",
679-
] + if_ngraph(["@ngraph_tf//:ngraph_tf"]),
690+
] + if_ngraph(["@ngraph_tf//:ngraph_tf"]) + if_dynamic_pywrap(["//tensorflow/python:tensorflow_impl"]),
691+
)
692+
693+
cc_import(
694+
name = "libtensorflow_cc_import_lib",
695+
shared_library = select({
696+
"//tensorflow:macos": ":libtensorflow_cc.dylib",
697+
"//conditions:default": ":libtensorflow_cc.so",
698+
}),
680699
)
681700

682701
# ** Targets for Windows build (start) **

tensorflow/c/BUILD

+21-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ filegroup(
3131
visibility = ["//tensorflow:__subpackages__"],
3232
)
3333

34+
filegroup(
35+
name = "pywrap_required_hdrs",
36+
srcs = [
37+
"c_api_internal.h",
38+
"checkpoint_reader.h",
39+
"tf_status_helper.h",
40+
"tf_status_internal.h",
41+
"tf_tensor_internal.h",
42+
],
43+
visibility = ["//tensorflow/python:__subpackages__"],
44+
)
45+
3446
filegroup(
3547
name = "srcs",
3648
srcs = glob(
@@ -629,11 +641,17 @@ tf_cc_test(
629641
tf_cuda_library(
630642
name = "python_api",
631643
srcs = ["python_api.cc"],
632-
hdrs = ["python_api.h"],
644+
hdrs = [
645+
"python_api.h",
646+
":headers",
647+
":pywrap_required_hdrs",
648+
"//tensorflow/core:protos_all_proto_text_hdrs",
649+
"//tensorflow/core:pywrap_required_hdrs",
650+
],
633651
visibility = ["//tensorflow/python:__pkg__"],
634652
deps = [
635-
":c_api",
636-
":c_api_internal",
653+
"//tensorflow/core:framework",
654+
"//tensorflow/core:lib",
637655
# TODO(b/74620627): remove when _USE_C_SHAPES is removed
638656
"//tensorflow/python:cpp_shape_inference_proto_cc",
639657
],

tensorflow/c/eager/BUILD

+12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ package(
2121
licenses = ["notice"], # Apache 2.0
2222
)
2323

24+
filegroup(
25+
name = "pywrap_required_hdrs",
26+
srcs = [
27+
"c_api_internal.h",
28+
"c_api_experimental.h",
29+
"tape.h",
30+
],
31+
visibility = [
32+
"//tensorflow/python:__subpackages__",
33+
],
34+
)
35+
2436
tf_cuda_library(
2537
name = "c_api",
2638
srcs = [

tensorflow/contrib/tensor_forest/BUILD

+9-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ tf_custom_op_library(
8181
] + if_static(
8282
extra_deps = [],
8383
otherwise = [
84-
":libforestprotos.so",
84+
# Proto implementations are already in libtensorflow_cc.so due to Triton
85+
# ":libforestprotos.so",
86+
"//tensorflow:libtensorflow_cc.so.1",
8587
],
8688
),
8789
deps = [
@@ -235,7 +237,9 @@ tf_custom_op_library(
235237
] + if_static(
236238
extra_deps = [],
237239
otherwise = [
238-
":libforestprotos.so",
240+
# Proto implementations are already in libtensorflow_cc.so due to Triton
241+
# ":libforestprotos.so",
242+
"//tensorflow:libtensorflow_cc.so.1",
239243
],
240244
),
241245
deps = [":model_ops_lib"],
@@ -330,7 +334,9 @@ tf_custom_op_library(
330334
] + if_static(
331335
extra_deps = [],
332336
otherwise = [
333-
":libforestprotos.so",
337+
# Proto implementations are already in libtensorflow_cc.so due to Triton
338+
# ":libforestprotos.so",
339+
"//tensorflow:libtensorflow_cc.so.1",
334340
],
335341
),
336342
deps = [":stats_ops_lib"],

tensorflow/core/BUILD

+14
Original file line numberDiff line numberDiff line change
@@ -3199,6 +3199,20 @@ CORE_CPU_LIB_HEADERS = CORE_CPU_BASE_HDRS + [
31993199
"graph/quantize_training.h",
32003200
] + if_mkl(["graph/mkl_graph_util.h"])
32013201

3202+
filegroup(
3203+
name = "pywrap_required_hdrs",
3204+
srcs = CORE_CPU_LIB_HEADERS + [
3205+
"common_runtime/gpu/gpu_id.h",
3206+
"framework/op_gen_lib.h",
3207+
"public/session.h",
3208+
"public/session_options.h",
3209+
],
3210+
visibility = [
3211+
"//tensorflow/c:__pkg__",
3212+
"//tensorflow/python:__subpackages__",
3213+
],
3214+
)
3215+
32023216
tf_cuda_library(
32033217
name = "core_cpu_impl",
32043218
srcs = [

tensorflow/core/common_runtime/eager/BUILD

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ package(
1717
licenses = ["notice"], # Apache 2.0
1818
)
1919

20+
filegroup(
21+
name = "pywrap_required_hdrs",
22+
srcs = [
23+
"attr_builder.h",
24+
"context.h",
25+
"eager_executor.h",
26+
"eager_operation.h",
27+
"kernel_and_device.h",
28+
"tensor_handle.h",
29+
"tensor_handle_data.h",
30+
],
31+
visibility = [
32+
"//tensorflow/python:__subpackages__",
33+
],
34+
)
35+
2036
tf_cuda_library(
2137
name = "eager_executor",
2238
srcs = [

tensorflow/core/distributed_runtime/BUILD

+16
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ filegroup(
3131
]),
3232
)
3333

34+
filegroup(
35+
name = "pywrap_required_hdrs",
36+
srcs = [
37+
"call_options.h",
38+
"message_wrappers.h",
39+
"rendezvous_mgr_interface.h",
40+
"server_lib.h",
41+
"worker_cache.h",
42+
"worker_env.h",
43+
"worker_interface.h",
44+
],
45+
visibility = [
46+
"//tensorflow/python:__subpackages__",
47+
],
48+
)
49+
3450
cc_library(
3551
name = "partial_run_mgr",
3652
srcs = ["partial_run_mgr.cc"],

tensorflow/core/distributed_runtime/eager/BUILD

+12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ package(
1212

1313
exports_files(["LICENSE"])
1414

15+
filegroup(
16+
name = "pywrap_required_hdrs",
17+
srcs = [
18+
"eager_client.h",
19+
"remote_tensor_handle.h",
20+
"remote_tensor_handle_data.h",
21+
],
22+
visibility = [
23+
"//tensorflow/python:__subpackages__",
24+
],
25+
)
26+
1527
cc_library(
1628
name = "remote_tensor_handle",
1729
hdrs = ["remote_tensor_handle.h"],

tensorflow/core/grappler/BUILD

+13
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ package(
44
licenses = ["notice"], # Apache 2.0
55
)
66

7+
exports_files(["grappler_item_builder.h"])
8+
9+
filegroup(
10+
name = "pywrap_required_hdrs",
11+
srcs = [
12+
"devices.h",
13+
"grappler_item.h",
14+
"grappler_item_builder.h",
15+
"utils.h",
16+
],
17+
visibility = ["//tensorflow/python:__subpackages__"],
18+
)
19+
720
cc_library(
821
name = "op_types",
922
srcs = ["op_types.cc"],

tensorflow/core/grappler/clusters/BUILD

+11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ package(
1010
licenses = ["notice"], # Apache 2.0
1111
)
1212

13+
filegroup(
14+
name = "pywrap_required_hdrs",
15+
srcs = [
16+
"cluster.h",
17+
"single_machine.h",
18+
"virtual_cluster.h",
19+
"utils.h",
20+
],
21+
visibility = ["//tensorflow/python:__subpackages__"],
22+
)
23+
1324
config_setting(
1425
name = "xsmm",
1526
licenses = ["notice"],

tensorflow/core/grappler/costs/BUILD

+17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ package(
1111
licenses = ["notice"], # Apache 2.0
1212
)
1313

14+
filegroup(
15+
name = "pywrap_required_hdrs",
16+
srcs = [
17+
"analytical_cost_estimator.h",
18+
"cost_estimator.h",
19+
"graph_properties.h",
20+
"measuring_cost_estimator.h",
21+
"op_level_cost_estimator.h",
22+
"op_context.h",
23+
"virtual_scheduler.h",
24+
"virtual_placer.h",
25+
"graph_memory.h",
26+
"utils.h",
27+
],
28+
visibility = ["//tensorflow/python:__subpackages__"],
29+
)
30+
1431
filegroup(
1532
name = "graph_properties_testdata",
1633
srcs = glob([

tensorflow/core/grappler/graph_analyzer/BUILD

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ package(
44
licenses = ["notice"], # Apache 2.0
55
)
66

7+
exports_files(
8+
["graph_analyzer_tool.h"],
9+
visibility = ["//visibility:public"],
10+
)
11+
712
cc_library(
813
name = "graph_analyzer_lib",
914
srcs = [

tensorflow/core/grappler/optimizers/BUILD

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ package(
1111
licenses = ["notice"], # Apache 2.0
1212
)
1313

14+
filegroup(
15+
name = "pywrap_required_hdrs",
16+
srcs = [
17+
"meta_optimizer.h",
18+
"graph_optimizer.h",
19+
],
20+
visibility = ["//tensorflow/python:__subpackages__"],
21+
)
22+
1423
cc_library(
1524
name = "static_schedule",
1625
srcs = ["static_schedule.cc"],

tensorflow/core/grappler/utils/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ package(
88
licenses = ["notice"], # Apache 2.0
99
)
1010

11+
exports_files(["topological_sort.h"])
12+
1113
cc_library(
1214
name = "scc",
1315
srcs = ["scc.cc"],

tensorflow/core/grappler/verifiers/BUILD

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package(
44
licenses = ["notice"], # Apache 2.0
55
)
66

7+
exports_files(["graph_verifier.h"])
8+
79
cc_library(
810
name = "graph_verifier",
911
hdrs = [

tensorflow/core/platform/default/build_config_root.bzl

+6
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ def if_dynamic_kernels(extra_deps, otherwise = []):
9595
str(Label("//tensorflow:dynamic_loaded_kernels")): extra_deps,
9696
"//conditions:default": otherwise,
9797
})
98+
99+
def if_dynamic_pywrap(extra_deps, otherwise = []):
100+
return select({
101+
str(Label("//tensorflow:dynamic_pywrap")): extra_deps,
102+
"//conditions:default": otherwise,
103+
})

0 commit comments

Comments
 (0)