From fae4d5afd4b3f727705470754cfeb0636f61b062 Mon Sep 17 00:00:00 2001 From: "Yunteng Luan (MSR Student-FA Talent)" Date: Fri, 20 Apr 2018 19:44:22 +0800 Subject: [PATCH 1/3] modified the code to dump the tensor shape --- tensorflow/core/common_runtime/executor.cc | 75 +++++++++++++++------- 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/tensorflow/core/common_runtime/executor.cc b/tensorflow/core/common_runtime/executor.cc index 3b521c0547a325..c8e430aae7dffd 100644 --- a/tensorflow/core/common_runtime/executor.cc +++ b/tensorflow/core/common_runtime/executor.cc @@ -2396,35 +2396,61 @@ void ExecutorState::FrameState::ActivateNodes(const NodeItem* item, } const Node *node = item->node; fprintf(dump_file_shape, "op[%s][%s][%s][%d]", node->type_string().data(), node->name().data(), node->assigned_device_name().data(), node->id()); - std::vector out_node_id_array; - for (Node *out: node->out_nodes()) { - fprintf(dump_file_shape, "\t%d", out->id()); - out_node_id_array.push_back(out->id()); - } + // std::vector out_node_id_array; + // for (Node *out: node->out_nodes()) { + // fprintf(dump_file_shape, "\t%d", out->id()); + // out_node_id_array.push_back(out->id()); + // } fprintf(dump_file_shape, "\n"); - const EdgeSet& out_edges = node->out_edges(); - fprintf(dump_file_shape, "edge"); - for (EdgeSet::const_iterator iter = out_edges.begin(); iter != out_edges.end(); iter++) { - fprintf(dump_file_shape, "\t%d", (*iter)->src_output()); - } - fprintf(dump_file_shape,"\n"); - for (int i = 0; i < item->num_outputs; ++i) { - const Entry& out = ((*outputs)[i]); - Tensor const * t; - if (!out.has_value) { + + //yunteng: get che output and their shape + const EdgeInfo* edges = item->output_edge_list(); + const size_t num_output_edges = item->num_output_edges; + for (size_t out_index = 0; out_index < num_output_edges; out_index++){ + const EdgeInfo& e = edges[out_index]; + const int dst_id = e.dst_id; + const int src_slot = e.output_slot; + fprintf(dump_file_shape, "edge: %d ", dst_id); + fprintf(dump_file_shape, "{"); + const Entry& out = (*output)[src_slot]; + const Tensor* t; + if(!out.has_value){ t = kEmptyTensor; - } else if (out.ref == nullptr) { - t = out.val.get(); - } else { + }else if(out.ref == nullptr){ + t =out.val.get(); + }else{ t = out.ref; } - // quanlu: dump shape - fprintf(dump_file_shape, "one_output"); - for (int j = 0; j < t->dims(); ++j) { + for(int j = 0; j < t->dims(); j++){ int64 ds = t->dim_size(j); - fprintf(dump_file_shape, "\t%lld", ds); + fprintf(dump_file_shape, "%d ", ds); } - fprintf(dump_file_shape, "\n"); + fprintf(dump_file_shape, "}\n"); + } + + // const EdgeSet& out_edges = node->out_edges(); + // fprintf(dump_file_shape, "edge"); + // for (EdgeSet::const_iterator iter = out_edges.begin(); iter != out_edges.end(); iter++) { + // fprintf(dump_file_shape, "\t%d", (*iter)->src_output()); + // } + // fprintf(dump_file_shape,"\n"); + // for (int i = 0; i < item->num_outputs; ++i) { + // const Entry& out = ((*outputs)[i]); + // Tensor const * t; + // if (!out.has_value) { + // t = kEmptyTensor; + // } else if (out.ref == nullptr) { + // t = out.val.get(); + // } else { + // t = out.ref; + // } + // // quanlu: dump shape + // fprintf(dump_file_shape, "one_output"); + // for (int j = 0; j < t->dims(); ++j) { + // int64 ds = t->dim_size(j); + // fprintf(dump_file_shape, "\t%lld", ds); + // } + // fprintf(dump_file_shape, "\n"); // quanlu: dump tensor content /*if (t == kEmptyTensor) { printf("empty tensor\n"); @@ -2467,7 +2493,7 @@ void ExecutorState::FrameState::ActivateNodes(const NodeItem* item, tmp_proto.SerializeToFileDescriptor(dump_file_tensor); }*/ // dump buf_ directly - if (t->IsInitialized() && t->NumElements() != 0) { +/* if (t->IsInitialized() && t->NumElements() != 0) { int src_id = node->id(); //int dst_id = out_node_id_array[i]; int output_index = i; @@ -2492,6 +2518,7 @@ void ExecutorState::FrameState::ActivateNodes(const NodeItem* item, ret = write(dump_file_tensor, ptr, len); if (ret != len) { printf("tensor content error, %d, %p, %d, %d\n", ret, ptr, len, errno); exit(-1); } } +*/ } fclose(dump_file_shape); close(dump_file_tensor); From eca4280c5dec0276bed7c1e3eec9c9ec77068bfc Mon Sep 17 00:00:00 2001 From: "Yunteng Luan (MSR Student-FA Talent)" Date: Fri, 20 Apr 2018 20:10:26 +0800 Subject: [PATCH 2/3] fix bugs --- tensorflow/core/common_runtime/executor.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tensorflow/core/common_runtime/executor.cc b/tensorflow/core/common_runtime/executor.cc index c8e430aae7dffd..5fa523726d894a 100644 --- a/tensorflow/core/common_runtime/executor.cc +++ b/tensorflow/core/common_runtime/executor.cc @@ -2412,7 +2412,7 @@ void ExecutorState::FrameState::ActivateNodes(const NodeItem* item, const int src_slot = e.output_slot; fprintf(dump_file_shape, "edge: %d ", dst_id); fprintf(dump_file_shape, "{"); - const Entry& out = (*output)[src_slot]; + const Entry& out = (*outputs)[src_slot]; const Tensor* t; if(!out.has_value){ t = kEmptyTensor; @@ -2519,7 +2519,6 @@ void ExecutorState::FrameState::ActivateNodes(const NodeItem* item, if (ret != len) { printf("tensor content error, %d, %p, %d, %d\n", ret, ptr, len, errno); exit(-1); } } */ - } fclose(dump_file_shape); close(dump_file_tensor); } From 0bc88b2744fc07bd42049d531c3db1f6d446af1f Mon Sep 17 00:00:00 2001 From: "Yunteng Luan (MSR Student-FA Talent)" Date: Sun, 22 Apr 2018 10:43:23 +0800 Subject: [PATCH 3/3] fix bugs --- tensorflow/core/common_runtime/executor.cc | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tensorflow/core/common_runtime/executor.cc b/tensorflow/core/common_runtime/executor.cc index 5fa523726d894a..78979b2833bf2e 100644 --- a/tensorflow/core/common_runtime/executor.cc +++ b/tensorflow/core/common_runtime/executor.cc @@ -2411,21 +2411,26 @@ void ExecutorState::FrameState::ActivateNodes(const NodeItem* item, const int dst_id = e.dst_id; const int src_slot = e.output_slot; fprintf(dump_file_shape, "edge: %d ", dst_id); - fprintf(dump_file_shape, "{"); - const Entry& out = (*outputs)[src_slot]; - const Tensor* t; - if(!out.has_value){ - t = kEmptyTensor; - }else if(out.ref == nullptr){ - t =out.val.get(); + if (src_slot == Graph::kControlSlot){//src_slot=-1, so that it is a control edge + fprintf(dump_file_shape, "{-1}\n"); }else{ - t = out.ref; - } - for(int j = 0; j < t->dims(); j++){ - int64 ds = t->dim_size(j); - fprintf(dump_file_shape, "%d ", ds); + fprintf(dump_file_shape, "{"); + const Entry& out = (*outputs)[src_slot]; + const Tensor* t; + if(!out.has_value){ + t = kEmptyTensor; + }else if(out.ref == nullptr){ + t =out.val.get(); + }else{ + t = out.ref; + } + for(int j = 0; j < t->dims(); j++){ + int64 ds = t->dim_size(j); + fprintf(dump_file_shape, "%d ", ds); + } + fprintf(dump_file_shape, "}\n"); } - fprintf(dump_file_shape, "}\n"); + } // const EdgeSet& out_edges = node->out_edges();