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(const HloModuleProto & proto)32 XlaComputation(const HloModuleProto& proto) 33 : unique_id_(proto.id()), proto_(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 proto()48 const HloModuleProto& proto() const { return proto_; } 49 50 // Requests that we snapshot the computation into a serializable protocol 51 // buffer form. 52 StatusOr<std::unique_ptr<HloSnapshot>> Snapshot() const; 53 54 // Returns true if this object is a null Computation. IsNull()55 bool IsNull() const { return unique_id_ == -1; } 56 57 private: XlaComputation(const int64 unique_id)58 XlaComputation(const int64 unique_id) : unique_id_(unique_id) {} mutable_proto()59 HloModuleProto* mutable_proto() { return &proto_; } 60 friend class XlaBuilder; 61 62 int64 unique_id_; 63 HloModuleProto proto_; 64 }; 65 66 } // namespace xla 67 68 #endif // TENSORFLOW_COMPILER_XLA_CLIENT_XLA_COMPUTATION_H_ 69