• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 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_DISTRIBUTED_RUNTIME_REMOTE_DEVICE_H_
17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_REMOTE_DEVICE_H_
18 
19 #include <functional>
20 #include <string>
21 #include <vector>
22 
23 #include "tensorflow/core/lib/core/status.h"
24 #include "tensorflow/core/platform/protobuf.h"
25 
26 namespace tensorflow {
27 class DeviceAttributes;
28 class Device;
29 class Env;
30 class WorkerCacheInterface;
31 
32 // This callback should have the same definition as DeviceMgr::LookupDevice
33 // It assigns *device with pointer to Device of the given 'name', where 'name'
34 // is either a full device name, or just the replica-local suffix.
35 typedef std::function<Status(StringPiece name, Device** device)>
36     LookupLocalDevice;
37 
38 // Creates Remote Devices for the provided device attributes. Helpful when the
39 // list of attributes is known, and doesn't need to be discovered via RPC.
40 void AsRemoteDevices(
41     Env* env,
42     const protobuf::RepeatedPtrField<DeviceAttributes>& device_attributes,
43     LookupLocalDevice lookup_local_device,
44     std::vector<std::unique_ptr<Device>>* remote_devices);
45 
46 // NewRemoteDevices discovers available devices on the
47 // 'worker_name'.  The implementation uses 'channel_cache' to
48 // discover how to communicate with the 'worker_name' (via gRPC, for
49 // example).
50 //
51 // NewRemoteDevices does not block.
52 //
53 // On success, the 'done' callback is given the OK status and a vector
54 // of Device*. The caller should take ownership of these devices.
55 //
56 // Otherwise, the 'done' callback is given an error status and the
57 // vector is empty.
58 typedef std::function<void(const Status&, std::vector<Device*>*)>
59     NewRemoteDevicesDone;
60 void NewRemoteDevices(Env* env, WorkerCacheInterface* worker_cache,
61                       const string& worker_name, NewRemoteDevicesDone done);
62 
63 // Create Remote Device based on the given attributes.
64 std::unique_ptr<Device> NewRemoteDevice(Env* env,
65                                         DeviceAttributes device_attribute);
66 }  // namespace tensorflow
67 
68 #endif  // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_REMOTE_DEVICE_H_
69