1 | /* Copyright 2022 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 | #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 | |
26 | namespace tensorflow { |
27 | namespace dtensor { |
28 | |
29 | using shape_inference::InferenceContext; |
30 | using shape_inference::ShapeHandle; |
31 | using 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. |
37 | REGISTER_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 | |
50 | REGISTER_OP("ShutdownTPUSystem" ) |
51 | .SetIsStateful() |
52 | .Output("success: bool" ) |
53 | .SetShapeFn(shape_inference::ScalarShape); |
54 | |
55 | REGISTER_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 | |