aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/graph/graph.cc
diff options
context:
space:
mode:
authorGravatar Igor Ganichev <iga@google.com>2017-08-16 15:54:35 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-08-16 16:02:00 -0700
commitf592a769bf1d3dabfc81a2b7add4d9eac297c30b (patch)
treef2260cc2274fedd8ba1381f13960c2c389181756 /tensorflow/core/graph/graph.cc
parent49267e1b0c16e321f772c70f48455dd57056b4dc (diff)
Add log messages to Graph::IsValidNode
Also, add Edge::DebugString() method. PiperOrigin-RevId: 165510102
Diffstat (limited to 'tensorflow/core/graph/graph.cc')
-rw-r--r--tensorflow/core/graph/graph.cc39
1 files changed, 29 insertions, 10 deletions
diff --git a/tensorflow/core/graph/graph.cc b/tensorflow/core/graph/graph.cc
index f6586f0519..07518ee341 100644
--- a/tensorflow/core/graph/graph.cc
+++ b/tensorflow/core/graph/graph.cc
@@ -24,6 +24,7 @@ limitations under the License.
#include "tensorflow/core/lib/core/errors.h"
#include "tensorflow/core/lib/gtl/map_util.h"
#include "tensorflow/core/lib/strings/strcat.h"
+#include "tensorflow/core/lib/strings/stringprintf.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/public/version.h"
@@ -352,7 +353,7 @@ Node* Graph::CopyNode(Node* node) {
}
void Graph::RemoveNode(Node* node) {
- DCHECK(IsValidNode(node)) << node->DebugString();
+ TF_DCHECK_OK(IsValidNode(node)) << node->DebugString();
DCHECK(!node->IsSource());
DCHECK(!node->IsSink());
@@ -367,8 +368,8 @@ void Graph::RemoveNode(Node* node) {
}
const Edge* Graph::AddEdge(Node* source, int x, Node* dest, int y) {
- DCHECK(IsValidNode(source)) << source->DebugString();
- DCHECK(IsValidNode(dest)) << dest->DebugString();
+ TF_DCHECK_OK(IsValidNode(source)) << source->DebugString();
+ TF_DCHECK_OK(IsValidNode(dest)) << dest->DebugString();
// source/sink must only be linked via control slots, and
// control slots must only be linked to control slots.
@@ -398,8 +399,8 @@ const Edge* Graph::AddEdge(Node* source, int x, Node* dest, int y) {
}
void Graph::RemoveEdge(const Edge* e) {
- DCHECK(IsValidNode(e->src_)) << e->src_->DebugString();
- DCHECK(IsValidNode(e->dst_)) << e->dst_->DebugString();
+ TF_DCHECK_OK(IsValidNode(e->src_)) << e->src_->DebugString();
+ TF_DCHECK_OK(IsValidNode(e->dst_)) << e->dst_->DebugString();
CHECK_EQ(e->src_->out_edges_.erase(e), size_t{1});
CHECK_EQ(e->dst_->in_edges_.erase(e), size_t{1});
CHECK_EQ(e, edges_[e->id_]);
@@ -497,11 +498,24 @@ string Graph::NewName(StringPiece prefix) {
return strings::StrCat(prefix, "/_", name_counter_++);
}
-bool Graph::IsValidNode(Node* node) const {
- if (node == nullptr) return false;
+Status Graph::IsValidNode(Node* node) const {
+ if (node == nullptr) {
+ return errors::InvalidArgument("Node is null");
+ }
const int id = node->id();
- if (id < 0 || static_cast<size_t>(id) >= nodes_.size()) return false;
- return nodes_[id] == node;
+ if (id < 0) {
+ return errors::InvalidArgument("node id ", id, "is less than zero");
+ }
+ if (static_cast<size_t>(id) >= nodes_.size()) {
+ return errors::InvalidArgument(
+ "node id ", id, "is >= than number of nodes in graph ", nodes_.size());
+ }
+ if (nodes_[id] != node) {
+ return errors::InvalidArgument("Node with id ", id,
+ " is different from the passed in node. "
+ "Does it belong to a different graph?");
+ }
+ return Status::OK();
}
Node* Graph::AllocateNode(std::shared_ptr<NodeProperties> props,
@@ -523,7 +537,7 @@ Node* Graph::AllocateNode(std::shared_ptr<NodeProperties> props,
}
void Graph::ReleaseNode(Node* node) {
- DCHECK(IsValidNode(node)) << node->DebugString();
+ TF_DCHECK_OK(IsValidNode(node)) << node->DebugString();
nodes_[node->id()] = nullptr;
free_nodes_.push_back(node);
--num_nodes_;
@@ -552,4 +566,9 @@ int Graph::InternDeviceName(const string& device_name) {
return index;
}
+string Edge::DebugString() const {
+ return strings::Printf("Edge %d %s:%d -> %s:%d", id_, src_->name().c_str(),
+ src_output_, dst_->name().c_str(), dst_input_);
+}
+
} // namespace tensorflow