| 776 | } |
| 777 | |
| 778 | void Graph::ForwardBFS(Graph* graph, std::vector<Node*>& starts, graph_visit_t func, bool input_ready) |
| 779 | { |
| 780 | int node_number = graph->seq_nodes.size(); |
| 781 | std::vector<int> visited(node_number, 0); |
| 782 | std::set<Node*> in_graph; |
| 783 | |
| 784 | for(int i = 0; i < node_number; i++) |
| 785 | in_graph.insert(graph->seq_nodes[i]); |
| 786 | |
| 787 | std::queue<Node*> visit_queue; |
| 788 | |
| 789 | /* inital the visit list */ |
| 790 | for(unsigned int i = 0; i < starts.size(); i++) |
| 791 | { |
| 792 | Node* node = starts[i]; |
| 793 | |
| 794 | bool pure_input_node = true; |
| 795 | |
| 796 | // only if all input tensors are out-side graph |
| 797 | |
| 798 | for(int i = 0; i < node->GetParentNum(); i++) |
| 799 | { |
| 800 | Node* pnode = node->GetParentNode(i); |
| 801 | |
| 802 | if(in_graph.count(pnode)) |
| 803 | { |
| 804 | pure_input_node = false; |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | if(pure_input_node) |
| 810 | { |
| 811 | visit_queue.push(node); |
| 812 | visited[node->GetNodeIndex()] = 1; |
| 813 | func(graph, node); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | while(visit_queue.size()) |
| 818 | { |
| 819 | Node* node = visit_queue.front(); |
| 820 | visit_queue.pop(); |
| 821 | |
| 822 | int output_num = node->GetOutputNum(); |
| 823 | |
| 824 | for(int i = 0; i < output_num; i++) |
| 825 | { |
| 826 | Tensor* tensor = node->GetOutputTensorSeq(i); |
| 827 | |
| 828 | for(unsigned int k = 0; k < tensor->consumer.size(); k++) |
| 829 | { |
| 830 | Node* child = tensor->consumer[k]->owner; |
| 831 | |
| 832 | if(in_graph.count(child) && !visited[child->GetNodeIndex()] && |
| 833 | (!input_ready || AllInputVisited(graph, child, visited, in_graph))) |
| 834 | { |
| 835 | visit_queue.push(child); |
nothing calls this directly
no test coverage detected