• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_EXECUTE_NODE_H_
16 #define TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EXECUTE_NODE_H_
17 
18 #include "tensorflow/core/common_runtime/device.h"
19 #include "tensorflow/core/common_runtime/eager/context.h"
20 #include "tensorflow/core/common_runtime/eager/eager_executor.h"
21 #include "tensorflow/core/common_runtime/eager/execute.h"
22 #include "tensorflow/core/common_runtime/eager/kernel_and_device.h"
23 #include "tensorflow/core/common_runtime/eager/tensor_handle.h"
24 #include "tensorflow/core/framework/step_stats.pb.h"
25 #include "tensorflow/core/framework/tensor.h"
26 #include "tensorflow/core/framework/types.h"
27 #include "tensorflow/core/lib/core/status.h"
28 #include "tensorflow/core/lib/gtl/inlined_vector.h"
29 
30 namespace tensorflow {
31 
32 class ExecuteNode : public EagerNode {
33  public:
ExecuteNode(uint64 id,EagerContext * ctx,const tensorflow::gtl::InlinedVector<TensorHandle *,4> & inputs,KernelAndDevice * kernel,NodeExecStats * maybe_stats,StepStats * maybe_step_stats,GraphCollector * graph_collector,const DataTypeVector & output_dtypes,const tensorflow::gtl::InlinedVector<TensorHandle *,2> & retvals)34   ExecuteNode(uint64 id, EagerContext* ctx,
35               const tensorflow::gtl::InlinedVector<TensorHandle*, 4>& inputs,
36               KernelAndDevice* kernel, NodeExecStats* maybe_stats,
37               StepStats* maybe_step_stats, GraphCollector* graph_collector,
38               const DataTypeVector& output_dtypes,
39               const tensorflow::gtl::InlinedVector<TensorHandle*, 2>& retvals)
40       : EagerNode(id),
41         ctx_(ctx),
42         inputs_(inputs),
43         kernel_(kernel),
44         maybe_stats_(maybe_stats),
45         maybe_step_stats_(maybe_step_stats),
46         graph_collector_(graph_collector),
47         retvals_(retvals) {
48     for (auto handle : inputs_) {
49       handle->Ref();
50     }
51     for (auto handle : retvals_) {
52       handle->Ref();
53     }
54   }
55 
~ExecuteNode()56   ~ExecuteNode() override {
57     for (auto handle : inputs_) {
58       handle->Unref();
59     }
60     for (auto handle : retvals_) {
61       handle->Unref();
62     }
63   }
64 
Run()65   tensorflow::Status Run() override {
66     const Status status = EagerKernelExecute(
67         ctx_, inputs_, kernel_, maybe_stats_.get(), maybe_step_stats_,
68         graph_collector_, retvals_.begin(), retvals_.size());
69     if (status.ok()) {
70       return status;
71     } else {
72       return Status(status.code(),
73                     strings::StrCat("Got error, \"", status.error_message(),
74                                     "\" while executing kernel ",
75                                     kernel_->kernel()->def().DebugString()));
76     }
77   }
78 
79  private:
80   tensorflow::EagerContext* ctx_;
81   tensorflow::gtl::InlinedVector<TensorHandle*, 4> inputs_;
82   tensorflow::KernelAndDevice* kernel_;
83   std::unique_ptr<NodeExecStats> maybe_stats_;
84   StepStats* maybe_step_stats_;
85   tensorflow::GraphCollector* graph_collector_;
86   tensorflow::gtl::InlinedVector<TensorHandle*, 2> retvals_;
87 };
88 
89 }  // namespace tensorflow
90 
91 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_EXECUTE_NODE_H_
92