Make custom_graph_optimizer_registry header-only (#18387)
authorAllen Lavoie <allenlavoie@gmail.com>
Tue, 10 Apr 2018 19:41:29 +0000 (12:41 -0700)
committerdrpngx <drpngx@users.noreply.github.com>
Tue, 10 Apr 2018 19:41:29 +0000 (12:41 -0700)
Adds it as a dependency to libtensorflow_framework.so so its symbols are
available to shared objects which want to register optimizers. No other rules
include it, so shared objects won't accidentally get their own version of the
registry.

tensorflow/BUILD
tensorflow/core/grappler/optimizers/BUILD

index cfafffd..f2ad16f 100644 (file)
@@ -450,11 +450,12 @@ tf_cc_shared_object(
     linkstatic = 1,
     visibility = ["//visibility:public"],
     deps = [
+        "//tensorflow/core:core_cpu_impl",
         "//tensorflow/core:framework_internal_impl",
+        "//tensorflow/core:gpu_runtime_impl",
+        "//tensorflow/core/grappler/optimizers:custom_graph_optimizer_registry_impl",
         "//tensorflow/core:lib_internal_impl",
-        "//tensorflow/core:core_cpu_impl",
         "//tensorflow/stream_executor:stream_executor_impl",
-        "//tensorflow/core:gpu_runtime_impl",
     ] + tf_additional_binary_deps(),
 )
 
index e4bc030..696cbd6 100644 (file)
@@ -11,6 +11,10 @@ load(
     "//tensorflow/core:platform/default/build_config.bzl",
     "tf_protos_grappler",
 )
+load(
+    "//tensorflow/core:platform/default/build_config_root.bzl",
+    "if_static",
+)
 
 cc_library(
     name = "static_schedule",
@@ -532,14 +536,31 @@ tf_cuda_cc_test(
     ],
 )
 
+# This rule is header-only unless the build is static (--config=monolithic). Its
+# implementation is included directly in the framework shared object.
 cc_library(
     name = "custom_graph_optimizer_registry",
-    srcs = ["custom_graph_optimizer_registry.cc"],
     hdrs = ["custom_graph_optimizer_registry.h"],
     visibility = ["//visibility:public"],
     deps = [
         ":custom_graph_optimizer",
         "//tensorflow/core:lib",
+    ] + if_static(
+        [":custom_graph_optimizer_registry_impl"],
+    ),
+)
+
+# This rule contains static variables for the optimizer registry. Do not depend
+# on it directly; use :custom_graph_optimizer_registry, and link against
+# libtensorflow_framework.so for the registry symbols.
+cc_library(
+    name = "custom_graph_optimizer_registry_impl",
+    srcs = ["custom_graph_optimizer_registry.cc"],
+    hdrs = ["custom_graph_optimizer_registry.h"],
+    visibility = ["//tensorflow:__subpackages__"],
+    deps = [
+        ":custom_graph_optimizer",
+        "//tensorflow/core:lib",
     ],
 )