• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 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_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_UTIL_H_
17 #define TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_UTIL_H_
18 
19 #include "tensorflow/core/common_runtime/device.h"
20 #include "tensorflow/core/common_runtime/dma_helper.h"
21 #include "tensorflow/core/framework/tensor.h"
22 #include "tensorflow/core/lib/core/status.h"
23 #include "tensorflow/core/platform/stream_executor.h"
24 
25 namespace tensorflow {
26 
27 class RecvTensorResponse;
28 class TensorProto;
29 
30 class PluggableDeviceUtil {
31  public:
32   // Copies the data in 'device_tensor' into 'cpu_tensor'.
33   // 'device_tensor''s backing memory must be on 'device' and
34   // 'cpu_tensor' must be allocated to be of the same size as
35   // 'device_tensor'. Synchronous: may block.
36   static void CopyPluggableDeviceTensorToCPU(
37       Device* device, const DeviceContext* device_context,
38       const Tensor* device_tensor, Tensor* cpu_tensor, StatusCallback done);
39   // Blocks until all operations queued on the stream associated with
40   // 'device' at the time of the call have completed. Returns any
41   // error pending on the stream at completion.
42   static Status Sync(Device* device);
43 
44   // Blocks until all operations queued on all streams associated with the
45   // corresponding 'device' at the time of call have completed.
46   // Returns any error pending on the stream at completion.
47   static Status SyncAll(Device* device);
48 
49   static void CopyCPUTensorToPluggableDevice(
50       const Tensor* cpu_tensor, const DeviceContext* device_context,
51       Device* device, Tensor* device_tensor, StatusCallback done,
52       bool sync_dst_compute);
53 
54   static void DeviceToDeviceCopy(
55       DeviceContext* send_dev_context, DeviceContext* recv_dev_context,
56       Device* src, Device* dst, AllocatorAttributes src_alloc_attr,
57       AllocatorAttributes dst_alloc_attr, const Tensor* input, Tensor* output,
58       int dev_to_dev_stream_index, StatusCallback done);
59 
60   // Deep-copying of PluggableDevice tensor on the same device.
61   // 'src_device_tensor''s and 'dst_device_tensor''s backing memory must be on
62   // 'device' and 'dst_cpu_tensor' must be allocated to be of the same
63   // size as 'src_device_tensor'.
64   static void CopyPluggableDeviceTensorToSameDevice(
65       Device* device, const DeviceContext* device_context,
66       const Tensor* src_device_tensor, Tensor* dst_device_tensor,
67       StatusCallback done);
68 };
69 
70 }  // namespace tensorflow
71 
72 #endif  // TENSORFLOW_CORE_COMMON_RUNTIME_PLUGGABLE_DEVICE_PLUGGABLE_DEVICE_UTIL_H_
73