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 // Rewrites ConfigureDistributedTPU Op into a graph that configures each host.
17 //
18 // See the comment at the top of
19 // third_party/tensorflow/core/ops/tpu_configuration_ops.cc to see the
20 // sequence of Ops used to configure a distributed TPU system.
21 
22 #ifndef TENSORFLOW_CORE_TPU_GRAPH_REWRITE_DISTRIBUTED_TPU_CONFIGURATION_REWRITE_PASS_H_
23 #define TENSORFLOW_CORE_TPU_GRAPH_REWRITE_DISTRIBUTED_TPU_CONFIGURATION_REWRITE_PASS_H_
24 
25 #include "tensorflow/core/common_runtime/optimization_registry.h"
26 #include "tensorflow/core/graph/graph.h"
27 #include "tensorflow/core/platform/env.h"
28 
29 namespace tensorflow {
30 
31 // Replaces dummy ConfigureDistributedTPU Ops assigned to TPU_SYSTEM
32 // devices with _ConfigureDistributedTPU and _WaitForDistributedTPU
33 // Ops on TPU_SYSTEM, and _InitializeHostForDistributedTPU on the CPU
34 // device of each host in the same job as the given TPU_SYSTEM device.
35 class DistributedTPUConfigurationRewritePass : public GraphOptimizationPass {
36  public:
37   Status Run(const GraphOptimizationPassOptions& options) override;
38 };
39 
40 // Replaces dummy ShutdownDistributedTPU Ops assigned to TPU_SYSTEM
41 // devices with _ShutdownDistributedTPU Ops on TPU_SYSTEM and
42 // _DisconnectHostFromDistributedTPUSystem on the CPU device of each
43 // host in the same job as the given TPU_SYSTEM device.
44 class DistributedTPUShutdownRewritePass : public GraphOptimizationPass {
45  public:
46   Status Run(const GraphOptimizationPassOptions& options) override;
47 };
48 
49 }  // namespace tensorflow
50 
51 #endif  // TENSORFLOW_CORE_TPU_GRAPH_REWRITE_DISTRIBUTED_TPU_CONFIGURATION_REWRITE_PASS_H_
52