Split out node_def_util, op_def_builder, op_def_util and attr_value_util targets in tensorflow/core/framework/BUILD. Split out

node_def_util.cc/.h into node_def_util.cc/.h and graph_node_util.cc/.h, where only the latter depends on graph.h.

PiperOrigin-RevId: 288340739
Change-Id: I66932bab042bda4bd707f866514b18b80efa805b
This commit is contained in:
Anna R 2020-01-06 11:30:32 -08:00 committed by TensorFlower Gardener
parent c6c81bc173
commit 31c3789692
24 changed files with 310 additions and 96 deletions

View File

@ -26,6 +26,7 @@ limitations under the License.
#include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor.pb.h"
#include "tensorflow/core/graph/algorithm.h" #include "tensorflow/core/graph/algorithm.h"
#include "tensorflow/core/graph/control_flow.h" #include "tensorflow/core/graph/control_flow.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/graph/tensor_id.h" #include "tensorflow/core/graph/tensor_id.h"
#include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/hash/hash.h"

View File

@ -24,6 +24,7 @@ limitations under the License.
#include "tensorflow/compiler/xla/status_macros.h" #include "tensorflow/compiler/xla/status_macros.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/lib/strings/proto_serialization.h" #include "tensorflow/core/lib/strings/proto_serialization.h"

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/compiler/jit/node_matchers.h" #include "tensorflow/compiler/jit/node_matchers.h"
#include <utility> #include <utility>
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
@ -24,6 +25,7 @@ limitations under the License.
#include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/attr_value_util.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor.pb.h"
#include "tensorflow/core/graph/graph_node_util.h"
namespace tensorflow { namespace tensorflow {
namespace testing { namespace testing {

View File

@ -27,6 +27,7 @@ limitations under the License.
#include "tensorflow/core/framework/memory_types.h" #include "tensorflow/core/framework/memory_types.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/public/version.h" #include "tensorflow/core/public/version.h"

View File

@ -16,6 +16,7 @@ limitations under the License.
#include "tensorflow/compiler/tf2xla/functionalize_control_flow_util.h" #include "tensorflow/compiler/tf2xla/functionalize_control_flow_util.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/graph/graph_node_util.h"
namespace tensorflow { namespace tensorflow {

View File

@ -1138,6 +1138,7 @@ tf_cuda_library(
"graph/graph_constructor.h", "graph/graph_constructor.h",
"graph/graph_def_builder.h", "graph/graph_def_builder.h",
"graph/graph_def_builder_util.h", "graph/graph_def_builder_util.h",
"graph/graph_node_util.h",
"graph/node_builder.h", "graph/node_builder.h",
"graph/validate.h", "graph/validate.h",
"graph/while_context.h", "graph/while_context.h",
@ -2384,6 +2385,7 @@ FRAMEWORK_INTERNAL_PRIVATE_HEADERS = [
"graph/edgeset.h", "graph/edgeset.h",
"graph/graph.h", "graph/graph.h",
"graph/graph_def_builder.h", "graph/graph_def_builder.h",
"graph/graph_node_util.h",
"graph/node_builder.h", "graph/node_builder.h",
"graph/tensor_id.h", "graph/tensor_id.h",
"//tensorflow/core/util/sparse:framework_internal_private_headers_group", "//tensorflow/core/util/sparse:framework_internal_private_headers_group",
@ -2477,6 +2479,7 @@ tf_cuda_library(
"graph/edgeset.cc", "graph/edgeset.cc",
"graph/graph.cc", "graph/graph.cc",
"graph/graph_def_builder.cc", "graph/graph_def_builder.cc",
"graph/graph_node_util.cc",
"graph/node_builder.cc", "graph/node_builder.cc",
"graph/tensor_id.cc", "graph/tensor_id.cc",
"graph/while_context.h", "graph/while_context.h",
@ -2520,8 +2523,12 @@ tf_cuda_library(
"//tensorflow/core/framework:allocator", "//tensorflow/core/framework:allocator",
"//tensorflow/core/framework:allocator_registry_impl", "//tensorflow/core/framework:allocator_registry_impl",
"//tensorflow/core/framework:attr_value_proto_text", "//tensorflow/core/framework:attr_value_proto_text",
"//tensorflow/core/framework:attr_value_util",
"//tensorflow/core/framework:bfloat16", "//tensorflow/core/framework:bfloat16",
"//tensorflow/core/framework:node_def_util",
"//tensorflow/core/framework:numeric_types", "//tensorflow/core/framework:numeric_types",
"//tensorflow/core/framework:op_def_builder",
"//tensorflow/core/framework:op_def_util",
"//tensorflow/core/framework:resource_handle", "//tensorflow/core/framework:resource_handle",
"//tensorflow/core/framework:tensor", "//tensorflow/core/framework:tensor",
"//tensorflow/core/framework:tensor_shape", "//tensorflow/core/framework:tensor_shape",
@ -2620,6 +2627,7 @@ GRAPH_HDRS = [
"graph/graph_constructor.h", # NOTE(mrry): Don't include the .cc since it depends on common_runtime. "graph/graph_constructor.h", # NOTE(mrry): Don't include the .cc since it depends on common_runtime.
"graph/graph_def_builder.h", "graph/graph_def_builder.h",
"graph/graph_def_builder_util.h", "graph/graph_def_builder_util.h",
"graph/graph_node_util.h",
"graph/graph_partition.h", "graph/graph_partition.h",
"graph/mkl_layout_pass.h", "graph/mkl_layout_pass.h",
"graph/mkl_tfconversion_pass.h", "graph/mkl_tfconversion_pass.h",

View File

@ -38,6 +38,7 @@ limitations under the License.
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/str_util.h"

View File

@ -45,6 +45,7 @@ limitations under the License.
#include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/graph/edgeset.h" #include "tensorflow/core/graph/edgeset.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/notification.h" #include "tensorflow/core/lib/core/notification.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"

View File

@ -26,6 +26,7 @@ limitations under the License.
#include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/function.h"
#include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
namespace tensorflow { namespace tensorflow {

View File

@ -18,7 +18,9 @@ limitations under the License.
#include "absl/algorithm/container.h" #include "absl/algorithm/container.h"
#include "tensorflow/core/common_runtime/function.h" #include "tensorflow/core/common_runtime/function.h"
#include "tensorflow/core/common_runtime/lower_functional_ops.h" #include "tensorflow/core/common_runtime/lower_functional_ops.h"
#include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_node_util.h"
namespace tensorflow { namespace tensorflow {
namespace { namespace {

View File

@ -20,7 +20,9 @@ limitations under the License.
#include "tensorflow/core/common_runtime/lower_function_call_op.h" #include "tensorflow/core/common_runtime/lower_function_call_op.h"
#include "tensorflow/core/common_runtime/lower_if_op.h" #include "tensorflow/core/common_runtime/lower_if_op.h"
#include "tensorflow/core/common_runtime/lower_while_op.h" #include "tensorflow/core/common_runtime/lower_while_op.h"
#include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/public/session_options.h" #include "tensorflow/core/public/session_options.h"
namespace tensorflow { namespace tensorflow {

View File

@ -24,9 +24,9 @@ limitations under the License.
#include "tensorflow/core/framework/device_attributes.pb.h" #include "tensorflow/core/framework/device_attributes.pb.h"
#include "tensorflow/core/framework/function.h" #include "tensorflow/core/framework/function.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/util/dump_graph.h" #include "tensorflow/core/util/dump_graph.h"
#include "tensorflow/core/util/port.h" #include "tensorflow/core/util/port.h"

View File

@ -35,6 +35,7 @@ limitations under the License.
#include "tensorflow/core/framework/types.pb.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/graph/graph_partition.h" #include "tensorflow/core/graph/graph_partition.h"
#include "tensorflow/core/lib/core/blocking_counter.h" #include "tensorflow/core/lib/core/blocking_counter.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"

View File

@ -28,7 +28,6 @@ package(
exports_files( exports_files(
srcs = [ srcs = [
"allocator_registry.h", "allocator_registry.h",
"attr_value_util.h",
"cancellation.h", "cancellation.h",
"collective.h", "collective.h",
"common_shape_fns.h", "common_shape_fns.h",
@ -47,11 +46,8 @@ exports_files(
"memory_types.h", "memory_types.h",
"model.h", "model.h",
"node_def_builder.h", "node_def_builder.h",
"node_def_util.h",
"numeric_op.h", "numeric_op.h",
"op.h", "op.h",
"op_def_builder.h",
"op_def_util.h",
"op_kernel.h", "op_kernel.h",
"op_segment.h", "op_segment.h",
"ops_util.h", "ops_util.h",
@ -212,7 +208,6 @@ filegroup(
filegroup( filegroup(
name = "framework_internal_impl_srcs", name = "framework_internal_impl_srcs",
srcs = [ srcs = [
"attr_value_util.cc",
"cancellation.cc", "cancellation.cc",
"collective.cc", "collective.cc",
"common_shape_fns.cc", "common_shape_fns.cc",
@ -231,10 +226,7 @@ filegroup(
"memory_types.cc", "memory_types.cc",
"model.cc", "model.cc",
"node_def_builder.cc", "node_def_builder.cc",
"node_def_util.cc",
"op.cc", "op.cc",
"op_def_builder.cc",
"op_def_util.cc",
"op_kernel.cc", "op_kernel.cc",
"op_segment.cc", "op_segment.cc",
"ops_util.cc", "ops_util.cc",
@ -611,7 +603,10 @@ cc_library(
cc_library( cc_library(
name = "tensor_shape", name = "tensor_shape",
srcs = ["tensor_shape.cc"], srcs = ["tensor_shape.cc"],
hdrs = ["tensor_shape.h"], hdrs = [
"partial_tensor_shape.h",
"tensor_shape.h",
],
visibility = ["//tensorflow/core:__pkg__"], visibility = ["//tensorflow/core:__pkg__"],
deps = [ deps = [
":bounds_check", ":bounds_check",
@ -736,6 +731,106 @@ tf_cuda_library(
alwayslink = 1, alwayslink = 1,
) )
cc_library(
name = "attr_value_util",
srcs = ["attr_value_util.cc"],
hdrs = ["attr_value_util.h"],
deps = [
":attr_value_proto_text",
":tensor",
":tensor_shape",
":tensor_shape_proto_cc",
"//tensorflow/core/lib/core:errors",
"//tensorflow/core/lib/core:status",
"//tensorflow/core/lib/core:stringpiece",
"//tensorflow/core/lib/gtl:array_slice",
"//tensorflow/core/lib/hash",
"//tensorflow/core/lib/strings:proto_serialization",
"//tensorflow/core/lib/strings:str_util",
"//tensorflow/core/platform:protobuf",
"@com_google_absl//absl/strings",
],
)
cc_library(
name = "op_def_util",
srcs = ["op_def_util.cc"],
hdrs = ["op_def_util.h"],
deps = [
":api_def_proto_cc",
":attr_value_proto_cc",
":attr_value_util",
":op_def_proto_cc",
":tensor",
"//tensorflow/core/lib/core:errors",
"//tensorflow/core/lib/core:status",
"//tensorflow/core/lib/core:stringpiece",
"//tensorflow/core/lib/gtl:map_util",
"//tensorflow/core/lib/hash",
"//tensorflow/core/lib/strings:proto_serialization",
"//tensorflow/core/lib/strings:scanner",
"//tensorflow/core/lib/strings:str_util",
"//tensorflow/core/lib/strings:strcat",
"//tensorflow/core/platform:mutex",
"//tensorflow/core/platform:protobuf",
"//tensorflow/core/platform:types",
],
)
cc_library(
name = "node_def_util",
srcs = ["node_def_util.cc"],
hdrs = ["node_def_util.h"],
deps = [
":attr_value_proto_cc",
":attr_value_util",
":node_def_proto_cc",
":op_def_proto_cc",
":op_def_util",
":tensor",
":tensor_proto_cc",
":tensor_shape",
":tensor_shape_proto_cc",
":types_proto_cc",
"//tensorflow/core/lib/core:stringpiece",
"//tensorflow/core/lib/gtl:array_slice",
"//tensorflow/core/lib/gtl:flatmap",
"//tensorflow/core/lib/gtl:map_util",
"//tensorflow/core/lib/hash",
"//tensorflow/core/platform:errors",
"//tensorflow/core/platform:hash",
"//tensorflow/core/platform:protobuf",
"//tensorflow/core/platform:scanner",
"//tensorflow/core/platform:status",
"//tensorflow/core/platform:strcat",
"//tensorflow/core/platform:stringpiece",
"//tensorflow/core/platform:types",
"@com_google_absl//absl/strings",
],
)
cc_library(
name = "op_def_builder",
srcs = ["op_def_builder.cc"],
hdrs = ["op_def_builder.h"],
deps = [
":attr_value_proto_cc",
":attr_value_util",
":op_def_proto_cc",
":op_def_util",
":tensor",
"//tensorflow/core/lib/core:errors",
"//tensorflow/core/lib/core:status",
"//tensorflow/core/lib/core:stringpiece",
"//tensorflow/core/lib/gtl:array_slice",
"//tensorflow/core/lib/strings:scanner",
"//tensorflow/core/lib/strings:str_util",
"//tensorflow/core/lib/strings:strcat",
"//tensorflow/core/platform:macros",
"@com_google_absl//absl/strings",
],
)
# Files whose users still need to be migrated from core:framework to the # Files whose users still need to be migrated from core:framework to the
# above targets. # above targets.
# TODO(gonnet): Remove these files once targets depending on them have # TODO(gonnet): Remove these files once targets depending on them have

View File

@ -24,6 +24,7 @@ limitations under the License.
#include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/graph/tensor_id.h" #include "tensorflow/core/graph/tensor_id.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <functional> #include <functional>
#include <vector> #include <vector>
#include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/attr_value_util.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/node_def_util.h"
@ -25,6 +26,7 @@ limitations under the License.
#include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/core/status.h" #include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/lib/gtl/array_slice.h" #include "tensorflow/core/lib/gtl/array_slice.h"
#include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/lib/strings/strcat.h"

View File

@ -23,19 +23,22 @@ limitations under the License.
#include "absl/strings/str_join.h" #include "absl/strings/str_join.h"
#include "tensorflow/core/framework/attr_value.pb.h" #include "tensorflow/core/framework/attr_value.pb.h"
#include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/attr_value_util.h"
#include "tensorflow/core/framework/graph.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_def.pb.h" #include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/framework/op_def_util.h" #include "tensorflow/core/framework/op_def_util.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor.pb.h" #include "tensorflow/core/framework/tensor.pb.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/tensor_shape.pb.h" #include "tensorflow/core/framework/tensor_shape.pb.h"
#include "tensorflow/core/graph/graph.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/gtl/map_util.h"
#include "tensorflow/core/lib/strings/scanner.h" #include "tensorflow/core/platform/errors.h"
#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/platform/scanner.h"
#include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/status.h"
#include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/strcat.h"
#include "tensorflow/core/platform/stringpiece.h"
#include "tensorflow/core/platform/types.h"
namespace tensorflow { namespace tensorflow {
@ -97,8 +100,6 @@ string AttrSlice::DebugString() const {
return absl::StrJoin(attr_key_vals, ", "); return absl::StrJoin(attr_key_vals, ", ");
} }
string SummarizeNode(const Node& node) { return SummarizeNodeDef(node.def()); }
string SummarizeNodeDef(const NodeDef& node_def) { string SummarizeNodeDef(const NodeDef& node_def) {
string ret = strings::StrCat(errors::FormatNodeNameForError(node_def.name()), string ret = strings::StrCat(errors::FormatNodeNameForError(node_def.name()),
" = ", node_def.op(), "["); " = ", node_def.op(), "[");
@ -120,57 +121,20 @@ string SummarizeAttrs(const NodeDef& node_def) {
return SummarizeAttrsHelper(node_def, node_def.device()); return SummarizeAttrsHelper(node_def, node_def.device());
} }
string FormatNodeForError(const NodeDebugInfo& debug_info) {
return debug_info.original_node_names.empty()
? errors::FormatNodeNameForError(debug_info.name)
: errors::FormatNodeNamesForError(debug_info.original_node_names);
}
string FormatNodeForError(const Node& node) {
return FormatNodeForError(NodeDebugInfo(node));
}
string FormatNodeDefForError(const NodeDef& node_def) {
return FormatNodeForError(NodeDebugInfo(node_def));
}
string FormatNodeDefForError( string FormatNodeDefForError(
StringPiece node_name, bool has_experimental_debug_info, StringPiece node_name, bool has_experimental_debug_info,
const NodeDef_ExperimentalDebugInfo& experimental_debug_info) { const NodeDef_ExperimentalDebugInfo& experimental_debug_info) {
return FormatNodeForError(NodeDebugInfo( return !has_experimental_debug_info ||
node_name, has_experimental_debug_info, experimental_debug_info)); experimental_debug_info.original_node_names().empty()
? errors::FormatNodeNameForError(string(node_name))
: errors::FormatNodeNamesForError(
experimental_debug_info.original_node_names());
} }
void GetMergedOriginalNodeNames(const NodeDebugInfo& from, string FormatNodeDefForError(const NodeDef& node_def) {
const NodeDebugInfo& to, return FormatNodeDefForError(node_def.name(),
std::set<string>* names) { node_def.has_experimental_debug_info(),
if (!from.original_node_names.empty()) { node_def.experimental_debug_info());
names->insert(from.original_node_names.begin(),
from.original_node_names.end());
} else {
names->insert(from.name);
}
names->insert(to.original_node_names.begin(), to.original_node_names.end());
}
void MergeDebugInfo(const NodeDebugInfo& from, Node* to) {
std::set<string> names;
GetMergedOriginalNodeNames(from, NodeDebugInfo(*to), &names);
to->set_original_node_names({names.begin(), names.end()});
}
void MergeDebugInfo(const NodeDebugInfo& from, NodeDef* to) {
std::set<string> names;
GetMergedOriginalNodeNames(from, NodeDebugInfo(*to), &names);
to->mutable_experimental_debug_info()->clear_original_node_names();
if (!names.empty()) {
*to->mutable_experimental_debug_info()->mutable_original_node_names() = {
names.begin(), names.end()};
}
}
void MergeDebugInfo(const NodeDef& from, NodeDef* to) {
MergeDebugInfo(NodeDebugInfo(from), to);
} }
const AttrValue* AttrSlice::Find(StringPiece attr_name) const { const AttrValue* AttrSlice::Find(StringPiece attr_name) const {
@ -727,11 +691,6 @@ Status NameRangesForNode(const AttrSlice& attrs, const OpDef& op_def,
return Status::OK(); return Status::OK();
} }
Status NameRangesForNode(const Node& node, const OpDef& op_def,
NameRangeMap* inputs, NameRangeMap* outputs) {
return NameRangesForNode(node.def(), op_def, inputs, outputs);
}
void AddDefaultsToNodeDef(const OpDef& op_def, NodeDef* node_def) { void AddDefaultsToNodeDef(const OpDef& op_def, NodeDef* node_def) {
for (const auto& attr_def : op_def.attr()) { for (const auto& attr_def : op_def.attr()) {
AttrSlice attrs(*node_def); AttrSlice attrs(*node_def);
@ -850,11 +809,6 @@ Status AttachDef(const Status& status, const NodeDef& node_def,
return ret; return ret;
} }
Status AttachDef(const Status& status, const Node& node,
bool allow_multiple_formatted_node) {
return AttachDef(status, node.def(), allow_multiple_formatted_node);
}
void AddNodeAttr(StringPiece name, const AttrValue& value, NodeDef* node_def) { void AddNodeAttr(StringPiece name, const AttrValue& value, NodeDef* node_def) {
node_def->mutable_attr()->insert( node_def->mutable_attr()->insert(
AttrValueMap::value_type(string(name), value)); AttrValueMap::value_type(string(name), value));

View File

@ -21,21 +21,29 @@ limitations under the License.
#include "tensorflow/core/framework/attr_value_util.h" #include "tensorflow/core/framework/attr_value_util.h"
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/tensor.h"
#include "tensorflow/core/framework/tensor_shape.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/types.pb.h"
#include "tensorflow/core/lib/core/stringpiece.h" #include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/lib/gtl/array_slice.h"
#include "tensorflow/core/lib/gtl/flatmap.h" #include "tensorflow/core/lib/gtl/flatmap.h"
#include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/platform/hash.h"
#include "tensorflow/core/platform/protobuf.h" #include "tensorflow/core/platform/protobuf.h"
#include "tensorflow/core/platform/status.h"
#include "tensorflow/core/platform/stringpiece.h"
#include "tensorflow/core/platform/types.h"
namespace tensorflow { namespace tensorflow {
class Node;
struct NodeDebugInfo;
// We forward declare protos so that kernels don't need to depend on them
class NodeDef;
class OpDef;
class AttrSlice; class AttrSlice;
// We forward declare protos so that kernels don't need to depend on them
class OpDef;
class AttrValue;
class NameAttrList;
class TensorProto;
class TensorShapeProto;
// Name of the attribute used to encode node colocation constraints. // Name of the attribute used to encode node colocation constraints.
// //
@ -49,7 +57,6 @@ extern const char* const kColocationGroupPrefix;
// Produce a human-readable version of a Node or NodeDef that is more concise // Produce a human-readable version of a Node or NodeDef that is more concise
// than a text-format proto. // than a text-format proto.
string SummarizeNode(const Node& node);
string SummarizeNodeDef(const NodeDef& node_def); string SummarizeNodeDef(const NodeDef& node_def);
string SummarizeAttrs(const NodeDef& node_def); string SummarizeAttrs(const NodeDef& node_def);
string SummarizeAttrsHelper(AttrSlice attrs, StringPiece device); string SummarizeAttrsHelper(AttrSlice attrs, StringPiece device);
@ -57,18 +64,11 @@ string SummarizeAttrsHelper(AttrSlice attrs, StringPiece device);
// Produces a formatted string pattern from the node which can uniquely identify // Produces a formatted string pattern from the node which can uniquely identify
// this node upstream to produce an informative error message. The pattern // this node upstream to produce an informative error message. The pattern
// followed is: {{node <node_name>}} // followed is: {{node <node_name>}}
string FormatNodeForError(const Node& node);
string FormatNodeDefForError(const NodeDef& node_def); string FormatNodeDefForError(const NodeDef& node_def);
string FormatNodeDefForError( string FormatNodeDefForError(
StringPiece node_name, bool has_experimental_debug_info, StringPiece node_name, bool has_experimental_debug_info,
const NodeDef_ExperimentalDebugInfo& experimental_debug_info); const NodeDef_ExperimentalDebugInfo& experimental_debug_info);
// Merges the original node names from the debug information of 'from' to the
// debug information of 'to'.
void MergeDebugInfo(const NodeDebugInfo& from, Node* to);
void MergeDebugInfo(const NodeDebugInfo& from, NodeDef* to);
void MergeDebugInfo(const NodeDef& from, NodeDef* to);
typedef protobuf::Map<string, AttrValue> AttrValueMap; typedef protobuf::Map<string, AttrValue> AttrValueMap;
// Adds an attr with name <name> and value <value> to *node_def. // Adds an attr with name <name> and value <value> to *node_def.
@ -351,9 +351,6 @@ typedef gtl::FlatMap<StringPiece, std::pair<int, int>, hash<StringPiece>>
NameRangeMap; NameRangeMap;
Status NameRangesForNode(const AttrSlice& attrs, const OpDef& op_def, Status NameRangesForNode(const AttrSlice& attrs, const OpDef& op_def,
NameRangeMap* inputs, NameRangeMap* outputs); NameRangeMap* inputs, NameRangeMap* outputs);
Status NameRangesForNode(const Node& node, const OpDef& op_def,
NameRangeMap* inputs, NameRangeMap* outputs);
// Adds default values to *node_def for unspecified attrs from op_def. // Adds default values to *node_def for unspecified attrs from op_def.
void AddDefaultsToNodeDef(const OpDef& op_def, NodeDef* node_def); void AddDefaultsToNodeDef(const OpDef& op_def, NodeDef* node_def);
@ -376,9 +373,6 @@ Status ValidateExternalNodeDefSyntax(const NodeDef& node_def);
// of the NodeDef instead of the formatted string. // of the NodeDef instead of the formatted string.
Status AttachDef(const Status& status, const NodeDef& node_def, Status AttachDef(const Status& status, const NodeDef& node_def,
bool allow_multiple_formatted_node = false); bool allow_multiple_formatted_node = false);
Status AttachDef(const Status& status, const Node& node,
bool allow_multiple_formatted_node = false);
// Appends the given prefix and suffix to the original node name in order to // Appends the given prefix and suffix to the original node name in order to
// make the name unique. If it's an "Enter" node and uniquify_frame_name is // make the name unique. If it's an "Enter" node and uniquify_frame_name is
// true, use the same way to reset attribute "frame_name". // true, use the same way to reset attribute "frame_name".

View File

@ -23,6 +23,7 @@ limitations under the License.
#include "tensorflow/core/framework/op_def_builder.h" #include "tensorflow/core/framework/op_def_builder.h"
#include "tensorflow/core/framework/op_kernel.h" #include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/versions.pb.h" #include "tensorflow/core/framework/versions.pb.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/graph/while_context.h" #include "tensorflow/core/graph/while_context.h"
#include "tensorflow/core/lib/core/errors.h" #include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/gtl/map_util.h"

View File

@ -0,0 +1,78 @@
/* Copyright 2020 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.
==============================================================================*/
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/core/stringpiece.h"
namespace tensorflow {
string SummarizeNode(const Node& node) { return SummarizeNodeDef(node.def()); }
string FormatNodeForError(const NodeDebugInfo& debug_info) {
return debug_info.original_node_names.empty()
? errors::FormatNodeNameForError(debug_info.name)
: errors::FormatNodeNamesForError(debug_info.original_node_names);
}
string FormatNodeForError(const Node& node) {
return FormatNodeForError(NodeDebugInfo(node));
}
Status NameRangesForNode(const Node& node, const OpDef& op_def,
NameRangeMap* inputs, NameRangeMap* outputs) {
return NameRangesForNode(node.def(), op_def, inputs, outputs);
}
Status AttachDef(const Status& status, const Node& node,
bool allow_multiple_formatted_node) {
return AttachDef(status, node.def(), allow_multiple_formatted_node);
}
void GetMergedOriginalNodeNames(const NodeDebugInfo& from,
const NodeDebugInfo& to,
std::set<string>* names) {
if (!from.original_node_names.empty()) {
names->insert(from.original_node_names.begin(),
from.original_node_names.end());
} else {
names->insert(from.name);
}
names->insert(to.original_node_names.begin(), to.original_node_names.end());
}
void MergeDebugInfo(const NodeDebugInfo& from, Node* to) {
std::set<string> names;
GetMergedOriginalNodeNames(from, NodeDebugInfo(*to), &names);
to->set_original_node_names({names.begin(), names.end()});
}
void MergeDebugInfo(const NodeDebugInfo& from, NodeDef* to) {
std::set<string> names;
GetMergedOriginalNodeNames(from, NodeDebugInfo(*to), &names);
to->mutable_experimental_debug_info()->clear_original_node_names();
if (!names.empty()) {
*to->mutable_experimental_debug_info()->mutable_original_node_names() = {
names.begin(), names.end()};
}
}
void MergeDebugInfo(const NodeDef& from, NodeDef* to) {
MergeDebugInfo(NodeDebugInfo(from), to);
}
} // namespace tensorflow

View File

@ -0,0 +1,64 @@
/* Copyright 2020 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_CORE_GRAPH_GRAPH_NODE_UTIL_H_
#define TENSORFLOW_CORE_GRAPH_GRAPH_NODE_UTIL_H_
#include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/lib/core/stringpiece.h"
#include "tensorflow/core/platform/status.h"
namespace tensorflow {
class Node;
struct NodeDebugInfo;
// We forward declare protos so that kernels don't need to depend on them
class NodeDef;
class OpDef;
// Produce a human-readable version of a Node or NodeDef that is more concise
// than a text-format proto.
string SummarizeNode(const Node& node);
// Produces a formatted string pattern from the node which can uniquely identify
// this node upstream to produce an informative error message. The pattern
// followed is: {{node <node_name>}}
string FormatNodeForError(const Node& node);
// Merges the original node names from the debug information of 'from' to the
// debug information of 'to'.
void MergeDebugInfo(const NodeDebugInfo& from, Node* to);
void MergeDebugInfo(const NodeDebugInfo& from, NodeDef* to);
void MergeDebugInfo(const NodeDef& from, NodeDef* to);
// Computes the mapping from input/output argument name to the
// corresponding input/output index range. For example,
// input "foo" corresponds to input indices
// [ (*inputs)["foo"].first, (*inputs)["foo"].second ).
// NOTE(mrry): To reduce allocations when the map is used and save
// space, the returned `NameRangeMap` objects borrow the input/output
// argument names from `op_def`. The `op_def` must outlive the
// returned `NameRangeMap` objects.
Status NameRangesForNode(const Node& node, const OpDef& op_def,
NameRangeMap* inputs, NameRangeMap* outputs);
// Returns "status" with formatted Node attached as additional text
// in the error message. If 'allow_multiple_formatted_node' is false and there
// is already a formatted Node present in 'status', we simply attach the name
// of the Node instead of the formatted string.
Status AttachDef(const Status& status, const Node& node,
bool allow_multiple_formatted_node = false);
} // namespace tensorflow
#endif // TENSORFLOW_CORE_GRAPH_GRAPH_NODE_UTIL_H_

View File

@ -45,6 +45,7 @@ limitations under the License.
#include "tensorflow/core/framework/node_def.pb.h" #include "tensorflow/core/framework/node_def.pb.h"
#include "tensorflow/core/framework/node_def_util.h" #include "tensorflow/core/framework/node_def_util.h"
#include "tensorflow/core/graph/algorithm.h" #include "tensorflow/core/graph/algorithm.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/lib/gtl/map_util.h" #include "tensorflow/core/lib/gtl/map_util.h"
#include "tensorflow/core/lib/hash/hash.h" #include "tensorflow/core/lib/hash/hash.h"
#include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/logging.h"

View File

@ -43,6 +43,7 @@ limitations under the License.
#include "tensorflow/core/graph/algorithm.h" #include "tensorflow/core/graph/algorithm.h"
#include "tensorflow/core/graph/control_flow.h" #include "tensorflow/core/graph/control_flow.h"
#include "tensorflow/core/graph/graph_constructor.h" #include "tensorflow/core/graph/graph_constructor.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/graph/tensor_id.h" #include "tensorflow/core/graph/tensor_id.h"
#include "tensorflow/core/grappler/graph_view.h" #include "tensorflow/core/grappler/graph_view.h"
#include "tensorflow/core/grappler/grappler_item.h" #include "tensorflow/core/grappler/grappler_item.h"

View File

@ -35,6 +35,7 @@ limitations under the License.
#include "tensorflow/core/framework/tensor_types.h" #include "tensorflow/core/framework/tensor_types.h"
#include "tensorflow/core/framework/types.h" #include "tensorflow/core/framework/types.h"
#include "tensorflow/core/framework/variant_op_registry.h" #include "tensorflow/core/framework/variant_op_registry.h"
#include "tensorflow/core/graph/graph_node_util.h"
#include "tensorflow/core/kernels/fill_functor.h" #include "tensorflow/core/kernels/fill_functor.h"
#include "tensorflow/core/platform/macros.h" #include "tensorflow/core/platform/macros.h"