aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/cc/framework
diff options
context:
space:
mode:
authorGravatar Geoffrey Irving <geoffreyi@google.com>2017-05-16 16:08:20 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-05-16 16:12:05 -0700
commit749e5cc18381f7a5ec174673f76e20aead8529c6 (patch)
tree4b92d36c9e1d8e59e34fd8d08e7f11fbda1315d9 /tensorflow/cc/framework
parented5d05d8b53425ef98aad129a60143a5011a4288 (diff)
Reduce direct references to NodeDef in favor of Node and AttrSlice
This is one step towards replacing in-memory use of NodeDef with a customized NodeInfo class. There are still quite a few Node::def() references, but far fewer than before. Those remaining require more work, either because they are part of kernel registration (which is a bunch of functions), copy and modify the NodeDef, etc. Follow-on CLs will remove more. RELNOTES: n/a PiperOrigin-RevId: 156244933
Diffstat (limited to 'tensorflow/cc/framework')
-rw-r--r--tensorflow/cc/framework/cc_op_gen.cc9
-rw-r--r--tensorflow/cc/framework/cc_ops_test.cc17
-rw-r--r--tensorflow/cc/framework/scope.cc4
3 files changed, 14 insertions, 16 deletions
diff --git a/tensorflow/cc/framework/cc_op_gen.cc b/tensorflow/cc/framework/cc_op_gen.cc
index 799492a4eb..71aa986f91 100644
--- a/tensorflow/cc/framework/cc_op_gen.cc
+++ b/tensorflow/cc/framework/cc_op_gen.cc
@@ -740,11 +740,10 @@ void OpInfo::GetOutput(string* out) const {
return;
}
strings::StrAppend(out, " ::tensorflow::NameRangeMap _outputs_range;\n");
- strings::StrAppend(
- out,
- " ::tensorflow::Status _status_ = "
- "::tensorflow::NameRangesForNode(ret->def(), ret->op_def(), "
- "nullptr, &_outputs_range);\n");
+ strings::StrAppend(out,
+ " ::tensorflow::Status _status_ = "
+ "::tensorflow::NameRangesForNode(*ret, ret->op_def(), "
+ "nullptr, &_outputs_range);\n");
strings::StrAppend(out, " if (!_status_.ok()) {\n", " ", scope_str,
".UpdateStatus(_status_);\n", " return;\n");
strings::StrAppend(out, " }\n\n");
diff --git a/tensorflow/cc/framework/cc_ops_test.cc b/tensorflow/cc/framework/cc_ops_test.cc
index 92c97d107d..5da23036ea 100644
--- a/tensorflow/cc/framework/cc_ops_test.cc
+++ b/tensorflow/cc/framework/cc_ops_test.cc
@@ -35,8 +35,8 @@ Output Linear(const Scope& scope, Input x, Input w, Input b) {
void GetColocationConstraints(const Output& tensor,
std::vector<string>* constraints) {
constraints->clear();
- TF_EXPECT_OK(
- GetNodeAttr(tensor.op().node()->def(), kColocationAttrName, constraints));
+ TF_EXPECT_OK(GetNodeAttr(tensor.op().node()->attrs(), kColocationAttrName,
+ constraints));
}
} // namespace
@@ -159,11 +159,11 @@ TEST(CCOpTest, KernelLabel) {
Scope root = Scope::NewRootScope();
auto add = Add(root.WithKernelLabel("AddWithKernelLabel"), 1.0f, 2.0f);
TF_EXPECT_OK(root.status());
- const auto& attrs = add.z.op().node()->def().attr();
- ASSERT_TRUE(attrs.find("_kernel") != attrs.end());
- auto kernel_attr = attrs.find("_kernel")->second;
- TF_EXPECT_OK(AttrValueHasType(kernel_attr, "string"));
- EXPECT_EQ(kernel_attr.s(), "AddWithKernelLabel");
+ AttrSlice attrs = add.z.op().node()->attrs();
+ const auto* kernel_attr = attrs.Find("_kernel");
+ ASSERT_TRUE(kernel_attr);
+ TF_EXPECT_OK(AttrValueHasType(*kernel_attr, "string"));
+ EXPECT_EQ(kernel_attr->s(), "AddWithKernelLabel");
}
TEST(CCOpTest, ColocateWith) {
@@ -190,8 +190,7 @@ TEST(CCOpTest, ColocateWith) {
Scope with_colocate = root.ColocateWith(c3).ColocateWith(c4);
auto c6 = Const(with_colocate.WithOpName("c6").ClearColocation(), 7);
- const auto& attrs = c6.op().node()->def().attr();
- EXPECT_TRUE(attrs.find("_class") == attrs.end());
+ EXPECT_FALSE(c6.op().node()->attrs().Find("_class"));
}
TEST(CCOpTest, TemplatedConst) {
diff --git a/tensorflow/cc/framework/scope.cc b/tensorflow/cc/framework/scope.cc
index 8b7fc1406f..32c0822de6 100644
--- a/tensorflow/cc/framework/scope.cc
+++ b/tensorflow/cc/framework/scope.cc
@@ -271,9 +271,9 @@ Scope::Impl::Impl(const Scope& other, Tags::Colocate,
std::unordered_set<string> Scope::Impl::GetColocationConstraints(
const Operation& colocate_with_op) const {
std::unordered_set<string> current_constraints(colocation_constraints_);
- const NodeDef& node_def = colocate_with_op.node()->def();
+ const AttrSlice attrs = colocate_with_op.node()->attrs();
std::vector<string> node_constraints;
- if (GetNodeAttr(node_def, kColocationAttrName, &node_constraints).ok()) {
+ if (GetNodeAttr(attrs, kColocationAttrName, &node_constraints).ok()) {
for (const string& entry : node_constraints) {
StringPiece s(entry);
if (s.Consume(kColocationGroupPrefix)) {