Given a node requiring placer inspection and its IOColocationGroups, computes `group_nodes`. group_nodes[i] contains the nodes that are members of colocation group i. These nodes are inputs or outputs of `node`. group_nodes[i][j] is a pair containing a node and whether this node has a resource input from `node`. Note: The same node can be added multiple times to the same group. The same node can b
| 764 | // The same node can be added multiple times to the same group. |
| 765 | // The same node can be added to multiple groups. |
| 766 | Status GetGroupNodes(const IOColocationGroups& groups, const Node& node, |
| 767 | std::vector<std::vector<NodeAndBool>>* group_nodes) { |
| 768 | group_nodes->reserve(groups.group_devices.size()); |
| 769 | for (int arg_idx = 0; arg_idx < groups.input_groups.size(); ++arg_idx) { |
| 770 | const Node* src; |
| 771 | TF_RETURN_IF_ERROR(node.input_node(arg_idx, &src)); |
| 772 | int group_id = groups.input_groups[arg_idx]; |
| 773 | (*group_nodes)[group_id].emplace_back(src, false); |
| 774 | } |
| 775 | |
| 776 | for (const Edge* edge : node.out_edges()) { |
| 777 | if (edge->IsControlEdge()) { |
| 778 | continue; |
| 779 | } |
| 780 | |
| 781 | int group_id = groups.output_groups[edge->src_output()]; |
| 782 | (*group_nodes)[group_id].emplace_back( |
| 783 | edge->dst(), edge->dst()->input_type(edge->dst_input()) == DT_RESOURCE); |
| 784 | } |
| 785 | |
| 786 | if (VLOG_IS_ON(2)) { |
| 787 | VLOG(2) << "Colocated inputs/outputs of node: " << node.DebugString(); |
| 788 | for (const std::vector<NodeAndBool>& nodes : *group_nodes) { |
| 789 | VLOG(2) << "\t[" << absl::StrJoin(NodeAndBoolToString(nodes), "\t\n") |
| 790 | << "]"; |
| 791 | } |
| 792 | } |
| 793 | return Status::OK(); |
| 794 | } |
| 795 | |
| 796 | } // namespace |
| 797 |
no test coverage detected