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

[async] [bug] Fix a bug in fusion and add some debug info #2002

Merged
merged 1 commit into from
Oct 27, 2020
Merged
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
25 changes: 23 additions & 2 deletions taichi/program/state_flow_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ std::unordered_set<int> StateFlowGraph::fuse_range(int begin, int end) {
auto update_list_i =
has_path_reverse[i].or_eq_get_update_list(has_path_reverse[a]);
for (auto j : update_list_i) {
has_path[i][j] = true;
has_path[j][i] = true;
}
}
};
Expand Down Expand Up @@ -878,7 +878,20 @@ void StateFlowGraph::topo_sort_nodes() {
nodes_.emplace_back(std::move(head));
}

TI_ASSERT(previous_size == nodes_.size());
if (previous_size != nodes_.size()) {
auto first_not_sorted = std::find_if_not(
degrees_in.begin(), degrees_in.end(), [](int x) { return x == 0; });
if (first_not_sorted != degrees_in.end()) {
TI_ERROR("SFG contains a cycle with node {}{}",
first_not_sorted - degrees_in.begin(),
pending_tasks[first_not_sorted - degrees_in.begin()]->string());
} else {
TI_ERROR(
"Topo sort changes the size of SFG ({} -> {}) "
"but no cycles are found",
previous_size, nodes_.size());
}
}
reid_nodes();
reid_pending_nodes();
}
Expand Down Expand Up @@ -909,6 +922,10 @@ void StateFlowGraph::replace_reference(StateFlowGraph::Node *node_a,
// Replace reference to A with B
const auto &ostate = edges.first;
auto &c_ins = get_or_insert(node_c->input_edges, ostate);
TI_ASSERT_INFO(node_c != node_b,
"Edge {} --({})-> {} will become a self-loop "
"after replacing reference",
node_a->string(), ostate.name(), node_b->string());
if (c_ins.find(node_a) != c_ins.end()) {
c_ins.erase(node_a);
c_ins.insert(node_b);
Expand All @@ -926,6 +943,10 @@ void StateFlowGraph::replace_reference(StateFlowGraph::Node *node_a,
// Replace reference to A with B
const auto &istate = edges.first;
auto &c_outs = get_or_insert(node_c->output_edges, istate);
TI_ASSERT_INFO(node_c != node_b,
"Edge {} <-({})-- {} will become a self-loop "
"after replacing reference",
node_a->string(), istate.name(), node_b->string());
if (c_outs.find(node_a) != c_outs.end()) {
c_outs.erase(node_a);
c_outs.insert(node_b);
Expand Down