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 #ifndef TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EAGER_OPERATION_H_ 16 #define TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EAGER_OPERATION_H_ 17 18 #include "tensorflow/core/common_runtime/eager/attr_builder.h" 19 #include "tensorflow/core/common_runtime/eager/context.h" 20 #include "tensorflow/core/common_runtime/eager/tensor_handle.h" 21 22 namespace tensorflow { 23 class EagerOperation { 24 public: EagerOperation(tensorflow::EagerContext * ctx,const char * op,bool is_function,const tensorflow::AttrTypeMap * t)25 EagerOperation(tensorflow::EagerContext* ctx, const char* op, 26 bool is_function, const tensorflow::AttrTypeMap* t) 27 : ctx_(ctx), 28 name_(op), 29 attrs_(op), 30 attr_types_(t), 31 device_(nullptr), 32 is_function_(is_function) {} 33 ~EagerOperation()34 ~EagerOperation() { 35 for (tensorflow::TensorHandle* h : inputs_) { 36 h->Unref(); 37 } 38 } 39 is_function()40 bool is_function() const { return is_function_; } 41 EagerContext()42 tensorflow::EagerContext* EagerContext() { return ctx_; } 43 MutableAttrs()44 tensorflow::AttrBuilder* MutableAttrs() { return &attrs_; } Attrs()45 const tensorflow::AttrBuilder& Attrs() const { return attrs_; } 46 Inputs()47 const tensorflow::gtl::InlinedVector<tensorflow::TensorHandle*, 4>& Inputs() 48 const { 49 return inputs_; 50 } 51 tensorflow::gtl::InlinedVector<tensorflow::TensorHandle*, 4>* MutableInputs()52 MutableInputs() { 53 return &inputs_; 54 } 55 void AddInput(tensorflow::TensorHandle* h); 56 void ConsumeInput(tensorflow::TensorHandle* h); 57 Name()58 const tensorflow::string& Name() const { return name_; } AttrTypes()59 const tensorflow::AttrTypeMap* AttrTypes() const { return attr_types_; } 60 Device()61 tensorflow::Device* Device() const { return device_; } 62 tensorflow::Status SetDevice(const char* device); SetDevice(tensorflow::Device * device)63 void SetDevice(tensorflow::Device* device) { device_ = device; } 64 SetUseXla(bool use_xla)65 void SetUseXla(bool use_xla) { use_xla_ = use_xla; } 66 67 string DebugString() const; 68 69 private: 70 tensorflow::EagerContext* ctx_; // Must outlive the EagerOperation. 71 const tensorflow::string name_; 72 tensorflow::AttrBuilder attrs_; 73 const tensorflow::AttrTypeMap* attr_types_; 74 tensorflow::gtl::InlinedVector<tensorflow::TensorHandle*, 4> inputs_; 75 tensorflow::Device* device_; 76 bool use_xla_ = false; 77 const bool is_function_; 78 }; 79 } // namespace tensorflow 80 81 #endif // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EAGER_OPERATION_H_ 82