1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. |
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | |
16 | #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_REPLICATE_PER_REPLICA_NODES_H_ |
17 | #define TENSORFLOW_CORE_COMMON_RUNTIME_REPLICATE_PER_REPLICA_NODES_H_ |
18 | |
19 | #include "absl/container/flat_hash_map.h" |
20 | #include "tensorflow/core/graph/graph.h" |
21 | #include "tensorflow/core/lib/core/status.h" |
22 | |
23 | namespace tensorflow { |
24 | |
25 | // `composite_device` maps from a virtual device to a set of devices. |
26 | // In a function graph, for each node assigned to a composite device |
27 | // (representing N devices), replace it with N replicated nodes (one per |
28 | // device). |
29 | // REQUIREMENTS: |
30 | // 1) Each node has been assigned to a device (including composite device). |
31 | // 2) Each cluster of nodes assigned to a composite device should include at |
32 | // least one "_Arg" node. |
33 | // composite device. |
34 | // 3) Clusters assigned to different composite devices should have no data |
35 | // dependency. |
36 | // TODO(b/145922293): Register it as a POST_REWRITE_FOR_EXEC pass. |
37 | Status ReplicatePerReplicaNodesInFunctionGraph( |
38 | const absl::flat_hash_map<string, const std::vector<string>*>& |
39 | composite_devices, |
40 | Graph* graph); |
41 | |
42 | } // namespace tensorflow |
43 | |
44 | #endif // TENSORFLOW_CORE_COMMON_RUNTIME_REPLICATE_PER_REPLICA_NODES_H_ |
45 | |