Skip to content

Commit

Permalink
Refactor tensor dump print.
Browse files Browse the repository at this point in the history
Now a dedicated function.
  • Loading branch information
kraiskil committed Dec 10, 2023
1 parent dff37f0 commit e84e544
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
22 changes: 3 additions & 19 deletions src/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,19 +522,8 @@ void Graph::addTensor(Tensor *t)
}
else {
LOG(DEBUG) << "Updating existing tensor: " << t->name << std::endl;
LOG(TRACE) << " was: gen " << prev->generate
<< " init " << prev->initialize
<< " IO " << prev->isIO
<< " const " << prev->isConst
<< " recurs " << prev->isRecursive
<< std::endl;
LOG(TRACE) << " new: gen " << t->generate
<< " init " << t->initialize
<< " IO " << t->isIO
<< " const " << t->isConst
<< " recurs " << t->isRecursive
<< std::endl;

LOG(TRACE) << " was: " << prev->print_trace_dump() << std::endl;
LOG(TRACE) << " new: " << t->print_trace_dump() << std::endl;

// if updating an output to be recursive:
if( t->isRecursive ) {
Expand Down Expand Up @@ -567,12 +556,7 @@ void Graph::addTensor(Tensor *t)
if( t->isIO && prev->initialize == false)
prev->isIO=true;

LOG(TRACE) << " now: gen " << prev->generate
<< " init " << prev->initialize
<< " IO " << prev->isIO
<< " const " << prev->isConst
<< " recurs " << prev->isRecursive
<< std::endl;
LOG(TRACE) << " now: " << prev->print_trace_dump() << std::endl;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ class Graph {
* the existing tensor is updated */
void addTensor(Tensor *t);

void log_trace_all_tensors(void)
{
LOG(TRACE) << "All known tensors at this moment:" << std::endl;
for( auto t : tensors ) LOG(TRACE) << " " << t->print_trace_dump() << std::endl;
}

Tensor *findTensor(const std::string &name) const;

static int anonymous_nodes;
Expand Down
17 changes: 17 additions & 0 deletions src/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,20 @@ float Tensor::get_data_element_float(uint64_t i) const
return 0;
}

std::string Tensor::print_trace_dump(void) const
{
// TODO: there was some new pretty printing stuff in C++20?
std::stringstream rv;
rv << " " << name << ":" // "global", ONNX name
<< " gen " << generate
<< " init " << initialize
<< " IO " << isIO
<< " const " << isConst
<< " recurs " << isRecursive
<< " dims { " << str_dimensions() << "}"
<< " buffer " << data_buffer
;

return rv.str();
}

1 change: 1 addition & 0 deletions src/tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Tensor {
union_no = u;
}

std::string print_trace_dump(void) const;
};

}
Expand Down

0 comments on commit e84e544

Please sign in to comment.