Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modified the code to dump the tensor shape #1

Open
wants to merge 3 commits into
base: r1.3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 60 additions & 29 deletions tensorflow/core/common_runtime/executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2396,35 +2396,66 @@ 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<int> 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<int> 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) {
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);

//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);
if (src_slot == Graph::kControlSlot){//src_slot=-1, so that it is a control edge
fprintf(dump_file_shape, "{-1}\n");
}else{
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();
// 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");
Expand Down Expand Up @@ -2467,7 +2498,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;
Expand All @@ -2492,7 +2523,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);
}
Expand Down