in src/core/scheduler/scheduler.cc [109:238]
void Graph::Debug() {
if (dirty_) Analyze();
int w = 0;
size_t max_in_num = 0, max_out_num = 0, max_next_num = 0, max_free_num = 0;
for (auto &it : nodes_) {
if (it->op_name_ == "Waiting") continue;
max_in_num = std::max(max_in_num, it->in_edges_.size());
max_out_num = std::max(max_out_num, it->out_edges_.size());
}
for (auto &it : next_nodes_) {
max_next_num = std::max(max_next_num, it.size());
}
for (auto &it : free_blocks_) {
max_free_num = std::max(max_free_num, it.size());
}
size_t max_size = std::max(nodes_.size(), blocks_.size());
for (size_t i = max_size; i > 0; i /= 10, ++w) {
}
std::stringstream ss;
ss << "begin nodes:[";
for (size_t i = 0; i < begin_nodes_.size(); ++i) {
ss << begin_nodes_[i]->id_ << " ";
}
ss << "]" << std::endl;
size_t size = 0;
for (size_t i = 0; i < nodes_.size(); ++i) {
ss << "OP[" << std::setw(w) << i;
auto node = nodes_[i];
string name;
if (node->op_name_.size() > 16) {
name = node->op_name_.substr(0, 13) + "...";
} else {
name = node->op_name_;
}
ss << "] Inputs:[";
size = node->in_edges_.size();
for (size_t j = 0; j < std::max(max_in_num, size); ++j) {
if (j < size)
ss << std::setw(w) << blocks_[node->in_edges_[j]->blk_]->id_ << " ";
else
ss << std::setw(w + 1) << " ";
}
ss << "] Outputs:[";
size = node->out_edges_.size();
for (size_t j = 0; j < std::max(max_out_num, size); ++j) {
if (j < size)
ss << std::setw(w) << blocks_[node->out_edges_[j]->blk_]->id_ << " ";
else
ss << std::setw(w + 1) << " ";
}
ss << "] Next nodes:[";
size = next_nodes_[i].size();
for (size_t j = 0; j < max_next_num; ++j) {
if (j < size)
ss << std::setw(w) << next_nodes_[i][j]->id_ << " ";
else
ss << std::setw(w + 1) << " ";
}
ss << "] Free blocks:[";
size = free_blocks_[i].size();
for (size_t j = 0; j < max_free_num; ++j) {
if (j < size)
ss << std::setw(w) << blocks_[free_blocks_[i][j]]->id_ << " ";
else
ss << std::setw(w + 1) << " ";
}
ss << "]" << std::endl;
}
size_t max_used_num = 0;
std::vector<BlkInfo *> blkInfos;
blkInfos.resize(blocks_.size());
for (auto it : blocks_) {
blkInfos[it.second->id_] = it.second;
max_used_num = std::max(max_used_num, it.second->used_nodes_.size());
}
for (auto it : blkInfos) {
auto blkInfo = it;
ss << "Block[" << std::setw(w) << blkInfo->id_ << "] addr[" << std::setw(10)
<< blkInfo->blk_ << "] size[" << std::setw(10) << blkInfo->blk_->size()
<< "] graph_ref[" << std::setw(w) << blkInfo->graph_ref_
<< "] ref_count[" << std::setw(w) << blkInfo->blk_->ref_count() << "] ";
switch (blkInfo->type_) {
case BlockType::kInput:
ss << "type[input] ";
break;
case BlockType::kParam:
ss << "type[param] ";
break;
case BlockType::kInter:
ss << "type[inter] ";
break;
case BlockType::kEnd:
ss << "type[_end_] ";
break;
default:
break;
}
int id = -1;
if (blkInfo->write_edge_) {
id = blkInfo->write_edge_->src_node_->id_;
}
ss << " write_node[" << std::setw(w) << id;
ss << "] used_nodes[";
size = blkInfo->used_nodes_.size();
for (size_t i = 0; i < max_used_num; ++i) {
if (i < size)
ss << std::setw(w) << blkInfo->used_nodes_[i]->id_ << " ";
else
ss << std::setw(w + 1) << " ";
}
ss << "]" << std::endl;
}
printf("%s", ss.str().c_str());
}