1/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#include <string>
17#include <utility>
18#include <vector>
19
20#include "tensorflow/core/framework/common_shape_fns.h"
21#include "tensorflow/core/framework/op.h"
22#include "tensorflow/core/framework/shape_inference.h"
23#include "tensorflow/core/framework/tensor_shape.h"
24#include "tensorflow/core/framework/tensor_shape.pb.h"
25
26namespace tensorflow {
27namespace dtensor {
28
29using shape_inference::InferenceContext;
30using shape_inference::ShapeHandle;
31using shape_inference::UnchangedShape;
32
33// Initializes global TPU's for mutli-client execution.
34//
35// This op does the work of both ConfigureDistributedTpuOp and
36// InitializeHostForDistributedTpuOp, and outputs the latter's result.
37REGISTER_OP("ConfigureAndInitializeGlobalTPU")
38 .Output("output: int32")
39 .SetIsStateful()
40 .SetShapeFn([](InferenceContext* c) {
41 ShapeHandle input;
42 // Validate that all the inputs are scalars.
43 for (int i = 0; i < c->num_inputs(); ++i) {
44 TF_RETURN_IF_ERROR(c->WithRank(c->input(i), 0, &input));
45 }
46 c->set_output(0, c->Vector(c->UnknownDim()));
47 return OkStatus();
48 });
49
50REGISTER_OP("ShutdownTPUSystem")
51 .SetIsStateful()
52 .Output("success: bool")
53 .SetShapeFn(shape_inference::ScalarShape);
54
55REGISTER_OP("DTensorSetGlobalTPUArray")
56 .Input("topology: string")
57 .SetIsStateful()
58 .SetShapeFn([](InferenceContext* c) {
59 ShapeHandle input;
60 TF_RETURN_IF_ERROR(c->WithRank(c->input(0), 0, &input));
61 return OkStatus();
62 });
63
64} // namespace dtensor
65} // namespace tensorflow
66