From 59b2a17c228be9cab5a8932417726e9afb931dc4 Mon Sep 17 00:00:00 2001 From: James Ring Date: Thu, 16 May 2019 16:15:11 -0700 Subject: [PATCH] Split TF_AttrType into its own header This will allow us to remove the c_api_headers target, which is necessary to be able to continue pruning dependencies on the c_api target. PiperOrigin-RevId: 248621032 --- tensorflow/c/BUILD | 24 +++++++----- tensorflow/c/c_api.h | 15 +------ tensorflow/c/tf_attrtype.h | 39 +++++++++++++++++++ tensorflow/core/common_runtime/eager/BUILD | 3 +- .../core/common_runtime/eager/attr_builder.h | 2 +- .../common_runtime/eager/attr_builder_test.cc | 1 + tensorflow/python/client/tf_session.i | 1 + 7 files changed, 60 insertions(+), 25 deletions(-) create mode 100644 tensorflow/c/tf_attrtype.h diff --git a/tensorflow/c/BUILD b/tensorflow/c/BUILD index 6928cf5d0ac..f2ca79f57fc 100644 --- a/tensorflow/c/BUILD +++ b/tensorflow/c/BUILD @@ -21,6 +21,7 @@ filegroup( srcs = [ "c_api.h", "c_api_experimental.h", + "tf_attrtype.h", ], visibility = ["//tensorflow:__subpackages__"], ) @@ -61,6 +62,7 @@ tf_cuda_library( "//tensorflow/core:android_tensorflow_lib_lite", ], "//conditions:default": [ + ":tf_attrtype", "//tensorflow/core:core_cpu", "//tensorflow/core:framework", "//tensorflow/core:lib", @@ -71,16 +73,24 @@ tf_cuda_library( }), ) +cc_library( + name = "tf_attrtype", + hdrs = ["tf_attrtype.h"], + visibility = ["//visibility:public"], +) + tf_cuda_library( name = "c_api", hdrs = [ "c_api.h", + "tf_attrtype.h", ], copts = tf_copts(), visibility = ["//visibility:public"], deps = [ ":c_api_no_xla", ":c_api_internal", + ":tf_attrtype", ] + select({ "//tensorflow:with_xla_support": [ "//tensorflow/compiler/tf2xla:xla_compiler", @@ -99,7 +109,10 @@ tf_cuda_library( hdrs = ["c_api.h"], copts = tf_copts(), visibility = ["//tensorflow/c:__subpackages__"], - deps = [":c_api_internal"] + select({ + deps = [ + ":c_api_internal", + ":tf_attrtype", + ] + select({ "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", ], @@ -151,15 +164,6 @@ tf_cuda_library( ], ) -cc_library( - name = "c_api_headers", - hdrs = [ - "c_api.h", - ], - copts = tf_copts(), - visibility = ["//tensorflow:__subpackages__"], -) - exports_files( [ "version_script.lds", diff --git a/tensorflow/c/c_api.h b/tensorflow/c/c_api.h index 051de3a7dc0..c074e5d3629 100644 --- a/tensorflow/c/c_api.h +++ b/tensorflow/c/c_api.h @@ -19,6 +19,8 @@ limitations under the License. #include #include +#include "tensorflow/c/tf_attrtype.h" + // -------------------------------------------------------------------------- // C API for TensorFlow. // @@ -686,19 +688,6 @@ TF_CAPI_EXPORT extern int TF_OperationGetControlOutputs( TF_Operation* oper, TF_Operation** control_outputs, int max_control_outputs); -// TF_AttrType describes the type of the value of an attribute on an operation. -typedef enum TF_AttrType { - TF_ATTR_STRING = 0, - TF_ATTR_INT = 1, - TF_ATTR_FLOAT = 2, - TF_ATTR_BOOL = 3, - TF_ATTR_TYPE = 4, - TF_ATTR_SHAPE = 5, - TF_ATTR_TENSOR = 6, - TF_ATTR_PLACEHOLDER = 7, - TF_ATTR_FUNC = 8, -} TF_AttrType; - // TF_AttrMetadata describes the value of an attribute on an operation. typedef struct TF_AttrMetadata { // A boolean: 1 if the attribute value is a list, 0 otherwise. diff --git a/tensorflow/c/tf_attrtype.h b/tensorflow/c/tf_attrtype.h new file mode 100644 index 00000000000..0c1545db232 --- /dev/null +++ b/tensorflow/c/tf_attrtype.h @@ -0,0 +1,39 @@ +/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#ifndef TENSORFLOW_C_TF_ATTRTYPE_H_ +#define TENSORFLOW_C_TF_ATTRTYPE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// TF_AttrType describes the type of the value of an attribute on an operation. +typedef enum TF_AttrType { + TF_ATTR_STRING = 0, + TF_ATTR_INT = 1, + TF_ATTR_FLOAT = 2, + TF_ATTR_BOOL = 3, + TF_ATTR_TYPE = 4, + TF_ATTR_SHAPE = 5, + TF_ATTR_TENSOR = 6, + TF_ATTR_PLACEHOLDER = 7, + TF_ATTR_FUNC = 8, +} TF_AttrType; + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif // TENSORFLOW_C_TF_ATTRTYPE_H_ diff --git a/tensorflow/core/common_runtime/eager/BUILD b/tensorflow/core/common_runtime/eager/BUILD index 25f55a0f0b5..2d06cfa1890 100644 --- a/tensorflow/core/common_runtime/eager/BUILD +++ b/tensorflow/core/common_runtime/eager/BUILD @@ -246,7 +246,7 @@ tf_cuda_library( "@farmhash_archive//:farmhash", # Only the TF_AttrType enum is required, so pull in just the C headers. # TODO(b/113535673): Break this dependency and avoid the C header completely. - "//tensorflow/c:c_api_headers", + "//tensorflow/c:tf_attrtype", ] + select({ "//tensorflow:android": [ "//tensorflow/core:android_tensorflow_lib_lite", @@ -268,6 +268,7 @@ tf_cc_test( srcs = ["attr_builder_test.cc"], deps = [ ":attr_builder", + "//tensorflow/c:c_api", "//tensorflow/cc:cc_ops", "//tensorflow/cc:client_session", "//tensorflow/cc:ops", diff --git a/tensorflow/core/common_runtime/eager/attr_builder.h b/tensorflow/core/common_runtime/eager/attr_builder.h index 232117a97f4..d359148ebb9 100644 --- a/tensorflow/core/common_runtime/eager/attr_builder.h +++ b/tensorflow/core/common_runtime/eager/attr_builder.h @@ -21,7 +21,7 @@ limitations under the License. #include #include -#include "tensorflow/c/c_api.h" +#include "tensorflow/c/tf_attrtype.h" #include "tensorflow/core/common_runtime/device.h" #include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/op_kernel.h" diff --git a/tensorflow/core/common_runtime/eager/attr_builder_test.cc b/tensorflow/core/common_runtime/eager/attr_builder_test.cc index 31c998a670a..ebe0779cd74 100644 --- a/tensorflow/core/common_runtime/eager/attr_builder_test.cc +++ b/tensorflow/core/common_runtime/eager/attr_builder_test.cc @@ -18,6 +18,7 @@ limitations under the License. #include #include +#include "tensorflow/c/c_api.h" #include "tensorflow/cc/client/client_session.h" #include "tensorflow/cc/framework/ops.h" #include "tensorflow/cc/framework/scope.h" diff --git a/tensorflow/python/client/tf_session.i b/tensorflow/python/client/tf_session.i index c066331172d..70de97835d3 100644 --- a/tensorflow/python/client/tf_session.i +++ b/tensorflow/python/client/tf_session.i @@ -516,6 +516,7 @@ TF_ImportGraphDefResultsMissingUnusedInputMappings_wrapper{ %rename("_TF_NewSessionOptions") TF_NewSessionOptions; %include "tensorflow/c/c_api.h" +%include "tensorflow/c/tf_attrtype.h" %include "tensorflow/c/python_api.h"