• 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_COPY_TO_DEVICE_NODE_H_
16 #define TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_COPY_TO_DEVICE_NODE_H_
17 
18 #include "tensorflow/core/common_runtime/device.h"
19 #include "tensorflow/core/common_runtime/eager/eager_executor.h"
20 #include "tensorflow/core/common_runtime/eager/tensor_handle.h"
21 #include "tensorflow/core/framework/allocator.h"
22 #include "tensorflow/core/framework/tensor.h"
23 #include "tensorflow/core/lib/core/status.h"
24 
25 namespace tensorflow {
26 
27 class CopyToDeviceNode : public EagerNode {
28  public:
CopyToDeviceNode(TensorHandle * src,TensorHandle * dst,Device * dstd,const EagerContext & ctx)29   CopyToDeviceNode(TensorHandle* src, TensorHandle* dst, Device* dstd,
30                    const EagerContext& ctx)
31       : EagerNode(), src_(src), dst_(dst), dstd_(dstd), ctx_(ctx) {
32     src_->Ref();
33     dst_->Ref();
34   }
35 
~CopyToDeviceNode()36   ~CopyToDeviceNode() override {
37     src_->Unref();
38     dst_->Unref();
39   }
40 
Run()41   Status Run() override {
42     tensorflow::Tensor tensor;
43     MEMDEBUG_CACHE_OP(MEMDEBUG_CACHE_VAL ? MEMDEBUG_CACHE_VAL
44                                          : "eager::CopyToDeviceNode");
45     TF_RETURN_IF_ERROR(src_->CopyToDevice(ctx_, dstd_, &tensor));
46     return dst_->SetTensor(std::move(tensor));
47   }
48 
Abort(Status status)49   void Abort(Status status) override { dst_->Poison(status); }
50 
DebugString()51   string DebugString() const override {
52     string out = "[CopyToDeviceNode]";
53     strings::StrAppend(&out, " src_tensor: ", src_->DebugString());
54     strings::StrAppend(&out, ", dst_tensor: ", dst_->DebugString());
55     strings::StrAppend(&out, ", dst_device: ", dstd_->name());
56     return out;
57   }
58 
dst()59   TensorHandle* dst() { return dst_; }
60 
61  private:
62   TensorHandle* src_;
63   TensorHandle* dst_;
64   Device* dstd_;
65   const EagerContext& ctx_;
66 };
67 
68 }  // namespace tensorflow
69 
70 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_COPY_TO_DEVICE_NODE_H_
71