xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/client/xla_computation.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2018 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_COMPILER_XLA_CLIENT_XLA_COMPUTATION_H_
17 #define TENSORFLOW_COMPILER_XLA_CLIENT_XLA_COMPUTATION_H_
18 
19 #include <utility>
20 
21 #include "tensorflow/compiler/xla/service/hlo.pb.h"
22 #include "tensorflow/compiler/xla/shape.h"
23 #include "tensorflow/compiler/xla/status_macros.h"
24 #include "tensorflow/compiler/xla/xla_data.pb.h"
25 
26 namespace xla {
27 
28 // The computation graph that the user builds up with the XlaBuilder.
29 class XlaComputation {
30  public:
XlaComputation()31   XlaComputation() : unique_id_(-1) {}
XlaComputation(HloModuleProto proto)32   XlaComputation(HloModuleProto proto)
33       : unique_id_(proto.id()), proto_(std::move(proto)) {}
34 
~XlaComputation()35   ~XlaComputation() {}
36 
37   XlaComputation(const XlaComputation&) = delete;
38   XlaComputation& operator=(const XlaComputation&) = delete;
39 
40   XlaComputation(XlaComputation&& from) = default;
41 
42   XlaComputation& operator=(XlaComputation&& from) = default;
43 
44   // Returns the "program shape" (parameter and return shapes) for this
45   // computation.
46   StatusOr<ProgramShape> GetProgramShape() const;
47 
name()48   const std::string& name() const { return proto().name(); }
49 
proto()50   const HloModuleProto& proto() const { return proto_; }
mutable_proto()51   HloModuleProto* mutable_proto() { return &proto_; }
52 
53   // Requests that we snapshot the computation into a serializable protocol
54   // buffer form.
55   StatusOr<std::unique_ptr<HloSnapshot>> Snapshot() const;
56 
57   // Returns true if this object is a null Computation.
IsNull()58   bool IsNull() const { return unique_id_ == -1; }
59 
60  private:
XlaComputation(const int64_t unique_id)61   XlaComputation(const int64_t unique_id) : unique_id_(unique_id) {}
62   friend class XlaBuilder;
63 
64   int64_t unique_id_;
65   HloModuleProto proto_;
66 };
67 
68 }  // namespace xla
69 
70 #endif  // TENSORFLOW_COMPILER_XLA_CLIENT_XLA_COMPUTATION_H_
71