| 842 | } |
| 843 | |
| 844 | void Graph::BackwardBFS(Graph* graph, std::vector<Node*>& starts, graph_visit_t func, bool input_ready) |
| 845 | { |
| 846 | int node_number = graph->seq_nodes.size(); |
| 847 | std::vector<int> visited(node_number, 0); |
| 848 | std::queue<Node*> visit_queue; |
| 849 | |
| 850 | std::set<Node*> in_graph; |
| 851 | |
| 852 | for(int i = 0; i < node_number; i++) |
| 853 | in_graph.insert(graph->seq_nodes[i]); |
| 854 | |
| 855 | /* inital the visit list */ |
| 856 | for(unsigned int i = 0; i < starts.size(); i++) |
| 857 | { |
| 858 | Node* node = starts[i]; |
| 859 | bool pure_output_node = true; |
| 860 | int output_num = node->GetOutputNum(); |
| 861 | |
| 862 | for(int i = 0; i < output_num; i++) |
| 863 | { |
| 864 | Tensor* tensor = node->GetOutputTensorSeq(i); |
| 865 | |
| 866 | for(unsigned int k = 0; k < tensor->consumer.size(); k++) |
| 867 | { |
| 868 | Node* child = tensor->consumer[k]->owner; |
| 869 | |
| 870 | if(in_graph.count(child)) |
| 871 | { |
| 872 | pure_output_node = false; |
| 873 | break; |
| 874 | } |
| 875 | } |
| 876 | } |
| 877 | |
| 878 | if(pure_output_node) |
| 879 | { |
| 880 | visit_queue.push(node); |
| 881 | visited[node->GetNodeIndex()] = 1; |
| 882 | func(graph, node); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | while(visit_queue.size()) |
| 887 | { |
| 888 | Node* node = visit_queue.front(); |
| 889 | visit_queue.pop(); |
| 890 | |
| 891 | int input_num = node->GetInputNum(); |
| 892 | |
| 893 | for(int i = 0; i < input_num; i++) |
| 894 | { |
| 895 | Node* parent = node->GetParentNode(i); |
| 896 | |
| 897 | if(in_graph.count(parent) && !visited[parent->GetNodeIndex()] && |
| 898 | (!input_ready || AllChildVisited(graph, parent, visited, in_graph))) |
| 899 | { |
| 900 | visit_queue.push(parent); |
| 901 | visited[parent->GetNodeIndex()] = 1; |
nothing calls this directly
no test coverage detected