• 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_DISTRIBUTED_RUNTIME_DEVICE_RESOLVER_DISTRIBUTED_H_
16 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_DEVICE_RESOLVER_DISTRIBUTED_H_
17 
18 #include <string>
19 #include <vector>
20 
21 #include "tensorflow/core/framework/collective.h"
22 #include "tensorflow/core/framework/device_attributes.pb.h"
23 #include "tensorflow/core/lib/gtl/flatmap.h"
24 
25 namespace tensorflow {
26 class DeviceMgr;
27 class WorkerCacheInterface;
28 
29 class DeviceResolverDistributed : public DeviceResolverInterface {
30  public:
31   DeviceResolverDistributed(const DeviceMgr* dev_mgr,
32                             WorkerCacheInterface* worker_cache,
33                             const string& task_name);
34 
~DeviceResolverDistributed()35   virtual ~DeviceResolverDistributed() {}
36 
37   void GetDeviceLocalitiesAsync(const CollInstanceParams& inst_params,
38                                 std::vector<DeviceLocality>* localities,
39                                 const StatusCallback& done) override;
40 
41   void GetLocalityAsync(const string& device, const string& task,
42                         DeviceLocality* locality,
43                         const StatusCallback& done) override;
44 
45   void ClearTask(const string& task) override;
46 
47  protected:
48   // Loads attr_table_ with device attributes retrieved from remote task.
49   void RefreshRemoteAttributes(const string& device, const string& task,
50                                const StatusCallback& done) LOCKS_EXCLUDED(mu_);
51 
52   // Subroutine used by GetDeviceLocalitiesAsync.  Recursively extends
53   // *localities with DeviceLocality of the corresponding device named
54   // by inst_params.instance.device_names.
55   void GetDeviceLocalitiesRecursive(const CollInstanceParams& inst_params,
56                                     std::vector<DeviceLocality>* localities,
57                                     const StatusCallback& done);
58 
59   const DeviceMgr* dev_mgr_;            // Not owned
60   WorkerCacheInterface* worker_cache_;  // Not owned
61   const string task_name_;
62   mutex mu_;
63   gtl::FlatMap<string, DeviceAttributes> attr_table_ GUARDED_BY(mu_);
64 };
65 
66 }  // namespace tensorflow
67 #endif  // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_DEVICE_RESOLVER_DISTRIBUTED_H_
68