| 84 | } |
| 85 | |
| 86 | void Partition(const GraphDef& graph_def, |
| 87 | std::unordered_map<string, GraphDef>* partitions) { |
| 88 | Graph g(OpRegistry::Global()); |
| 89 | GraphConstructorOptions opts; |
| 90 | TF_CHECK_OK(ConvertGraphDefToGraph(opts, graph_def, &g)); |
| 91 | |
| 92 | // Assigns devices to each node. Uses 1st letter of the node name as the |
| 93 | // device index if no device is specified. |
| 94 | for (Node* node : g.nodes()) { |
| 95 | string device_name = !node->requested_device().empty() |
| 96 | ? node->requested_device() |
| 97 | : DeviceName(node); |
| 98 | node->set_assigned_device_name(device_name); |
| 99 | } |
| 100 | |
| 101 | PartitionOptions popts; |
| 102 | popts.node_to_loc = SplitByDevice; |
| 103 | popts.new_name = [&g](const string& prefix) { return g.NewName(prefix); }; |
| 104 | popts.get_incarnation = [](const string& name) { |
| 105 | return (name[0] - 'A') + 100; |
| 106 | }; |
| 107 | Status s = Partition(popts, &g, partitions); |
| 108 | CHECK(s.ok()) << s; |
| 109 | |
| 110 | // Check versions. |
| 111 | EXPECT_EQ(graph_def.versions().producer(), TF_GRAPH_DEF_VERSION); |
| 112 | // Partitions must inherit the versions of the original graph. |
| 113 | for (auto& it : *partitions) { |
| 114 | EXPECT_EQ(graph_def.versions().producer(), it.second.versions().producer()); |
| 115 | EXPECT_EQ(graph_def.versions().min_consumer(), |
| 116 | it.second.versions().min_consumer()); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void CheckLoopConstruction(const GraphDef& graph_def) { |
| 121 | std::unordered_map<string, GraphDef> partitions; |
no test coverage detected