| 855 | } |
| 856 | |
| 857 | Status ColocationGraph::ColocateNodeToGroup( |
| 858 | std::unordered_map<StringPiece, const Node*, StringPieceHasher>* |
| 859 | colocation_group_root, |
| 860 | const Node* node, StringPiece colocation_group) { |
| 861 | const Node*& root_node = (*colocation_group_root)[colocation_group]; |
| 862 | if (root_node == nullptr) { |
| 863 | // This is the first node of the colocation group, so |
| 864 | // designate this node as the 'root' of that colocation group. |
| 865 | root_node = node; |
| 866 | } else { |
| 867 | // Try to colocate the node with the root. If there is an |
| 868 | // error, return it. |
| 869 | Status s = ColocateNodes(*node, *root_node); |
| 870 | if (!s.ok()) { |
| 871 | if (!allow_soft_placement_) { |
| 872 | return AttachDef(s, *node); |
| 873 | } |
| 874 | if (log_device_placement_) { |
| 875 | LOG(INFO) << "Ignoring request to colocate node '" << node->name() |
| 876 | << "' with nodes in colocation group '" << colocation_group |
| 877 | << "' because soft placement is on and an attempt at doing " |
| 878 | "so resulted in the following error: " |
| 879 | << AttachDef(s, *node).ToString(); |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | return Status::OK(); |
| 884 | } |
| 885 | |
| 886 | // Merge the (possibly disjoint) sets containing nodes "x" and |
| 887 | // "y". Returns OK if the all nodes in the union of these sets can |