Skip to content

Commit

Permalink
Move DEBUG logs to TRACE
Browse files Browse the repository at this point in the history
This makes DEBUG at least a bit more useful.
  • Loading branch information
kraiskil committed Mar 9, 2024
1 parent 196f9f5 commit 3542d14
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ Onnx2c has a few optimization passes that modify the generated output:

`./onnx2c -h` prints out all available command line options.

onnx2c prints a log on stdout. Log level can be given with the `-l N` command line option.
Logging levels are
- 0 Fatal errors only
- 1 Warnings where onnx2c might not be correctly implemented
- 2 Generic info (default level in the Release build)
- 3 Debug: high level trace of what onnx2c does useful debugging the model
- 4 Trace: detailed info useful for debugging onnx2c

There is a [helper script](scripts/) to initially run any `.onnx` on a MCU development board. This is intended
as a tool when designing the network to see if it will fit the target, before starting training the network.
Expand Down
24 changes: 12 additions & 12 deletions src/graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ bool Graph::tryResolveNode(onnx::NodeProto &onnx_node)
if( new_node == "MatMul" )
new_node = "MatMulInteger";
}
LOG(DEBUG) << "Creating new node: " << onnx_node.name() << std::endl;
LOG(DEBUG) << " Operand type: " << new_node << std::endl;
LOG(TRACE) << "Creating new node: " << onnx_node.name() << std::endl;
LOG(TRACE) << " Operand type: " << new_node << std::endl;
Node *n = createNode(new_node);
if( getNodeInputTensors(onnx_node, n) == false ) {
LOG(DEBUG) << "getNodeInputTensors() failed. Not adding node!"<< std::endl;
LOG(TRACE) << "getNodeInputTensors() failed. Not adding node!"<< std::endl;
delete n;
return false;
}
Expand All @@ -296,29 +296,29 @@ bool Graph::tryResolveNode(onnx::NodeProto &onnx_node)
else
n->onnx_name = onnx_node.name();

LOG(DEBUG) << " Node name in C sources " << n->c_name() << std::endl;
LOG(DEBUG) << " inputs: " << std::endl;
LOG(TRACE) << " Node name in C sources " << n->c_name() << std::endl;
LOG(TRACE) << " inputs: " << std::endl;

// Record this node as the consumer of the the input tensors
for(unsigned iidx=0; iidx<(n->get_number_of_inputs()); iidx++) {
Tensor *i = n->get_input_tensor(iidx);
LOG(DEBUG) << " " << i->name << " - "<< i->data_type_str() << " { " << i->str_dimensions() << "}" << std::endl;
LOG(TRACE) << " " << i->name << " - "<< i->data_type_str() << " { " << i->str_dimensions() << "}" << std::endl;
const_cast<Tensor*>(i)->consumers.push_back(n);
i->print_trace_dump();
}
LOG(TRACE) << " (no more inputs)" << std::endl;
n->isResolved = false;
n->op_name = new_node;

LOG(DEBUG) << " Parsing node attributes" << std::endl;
LOG(TRACE) << " Parsing node attributes" << std::endl;
if( onnx_node.attribute_size() != 0 )
n->parseAttributes( onnx_node );
LOG(TRACE) << " (done parsing attributes)" << std::endl;

// Now loop over the node inputs, check that they are all added
// into the graph's known tensors - seems the ONNX graph does not keep track of
// vectors provided as nodes' attributes.
LOG(DEBUG) << " Making sure node attributes are in the graph" << std::endl;
LOG(TRACE) << " Making sure node attributes are in the graph" << std::endl;
for(unsigned nn = 0; nn<n->get_number_of_inputs(); nn++)
addTensor(n->get_input_tensor(nn));
LOG(TRACE) << " (end of attribute-input-vectors)" << std::endl;
Expand Down Expand Up @@ -354,7 +354,7 @@ bool Graph::tryResolveNode(onnx::NodeProto &onnx_node)
// the ONNX model.
// This will now contain all of the node's outputs, also such optional ones
// that are not used in the model.
LOG(DEBUG) << "Adding resolved node's output to graph's tensors" << std::endl;
LOG(TRACE) << "Adding resolved node's output to graph's tensors" << std::endl;
for( unsigned o=0; o<n->get_number_of_outputs(); o++) {
Tensor *t = n->get_output_tensor(o);

Expand All @@ -378,10 +378,10 @@ bool Graph::tryResolveNode(onnx::NodeProto &onnx_node)

addTensor(t);
}
LOG(DEBUG) << " (done) all outputs now:" << std::endl;
LOG(TRACE) << " (done) all outputs now:" << std::endl;
for( unsigned o=0; o<n->get_number_of_outputs(); o++) {
Tensor *t = n->get_output_tensor(o);
LOG(DEBUG) << " " << t->name << " - "<< t->data_type_str() << " { " << t->str_dimensions() << "}" << std::endl;
LOG(TRACE) << " " << t->name << " - "<< t->data_type_str() << " { " << t->str_dimensions() << "}" << std::endl;
}
LOG(TRACE) << " (no more outputs)" << std::endl;

Expand Down Expand Up @@ -579,7 +579,7 @@ void Graph::addTensor(Tensor *t)
// TODO return & remove else {}
}
else {
LOG(DEBUG) << "Updating existing tensor: " << t->name << std::endl;
LOG(TRACE) << "Updating existing tensor: " << t->name << std::endl;
LOG(TRACE) << " was: " << prev->print_trace_dump() << std::endl;
LOG(TRACE) << " new: " << t->print_trace_dump() << std::endl;

Expand Down

0 comments on commit 3542d14

Please sign in to comment.