• 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 #include "tensorflow/core/common_runtime/collective_executor_mgr.h"
16 
17 #include "tensorflow/core/common_runtime/base_collective_executor.h"
18 #include "tensorflow/core/common_runtime/build_graph_options.h"
19 #include "tensorflow/core/common_runtime/collective_rma_local.h"
20 #include "tensorflow/core/common_runtime/device_mgr.h"
21 #include "tensorflow/core/framework/collective.h"
22 #include "tensorflow/core/protobuf/config.pb.h"
23 
24 namespace tensorflow {
25 
CollectiveExecutorMgr(const ConfigProto & config,const DeviceMgr * dev_mgr,std::unique_ptr<DeviceResolverInterface> dev_resolver,std::unique_ptr<ParamResolverInterface> param_resolver)26 CollectiveExecutorMgr::CollectiveExecutorMgr(
27     const ConfigProto& config, const DeviceMgr* dev_mgr,
28     std::unique_ptr<DeviceResolverInterface> dev_resolver,
29     std::unique_ptr<ParamResolverInterface> param_resolver)
30     : dev_mgr_(dev_mgr),
31       dev_resolver_(std::move(dev_resolver)),
32       param_resolver_(std::move(param_resolver)),
33       gpu_ring_order_(
34           config.gpu_options().experimental().collective_ring_order()) {}
35 
~CollectiveExecutorMgr()36 CollectiveExecutorMgr::~CollectiveExecutorMgr() {
37   for (auto iter : executor_table_) {
38     iter.second->Unref();
39   }
40 }
41 
FindOrCreate(int64 step_id)42 CollectiveExecutor* CollectiveExecutorMgr::FindOrCreate(int64 step_id) {
43   CollectiveExecutor* ce = nullptr;
44   {
45     mutex_lock l(exec_mu_);
46     auto it = executor_table_.find(step_id);
47     if (it != executor_table_.end()) {
48       ce = it->second;
49     } else {
50       ce = Create(step_id);
51       executor_table_[step_id] = ce;
52     }
53     ce->Ref();
54   }
55   return ce;
56 }
57 
Create(int64 step_id)58 CollectiveExecutor* CollectiveExecutorMgr::Create(int64 step_id) {
59   CollectiveRemoteAccessLocal* rma =
60       new CollectiveRemoteAccessLocal(dev_mgr_, dev_resolver_.get(), step_id);
61   return new BaseCollectiveExecutor(this, rma, step_id, dev_mgr_,
62                                     &gpu_ring_order_);
63 }
64 
Cleanup(int64 step_id)65 void CollectiveExecutorMgr::Cleanup(int64 step_id) {
66   CollectiveExecutor* ce = nullptr;
67   {
68     mutex_lock l(exec_mu_);
69     auto it = executor_table_.find(step_id);
70     if (it != executor_table_.end()) {
71       ce = it->second;
72       executor_table_.erase(it);
73     }
74   }
75   if (ce) ce->Unref();
76 }
77 
GetStepSequenceAsync(const GetStepSequenceRequest * request,GetStepSequenceResponse * response,const StatusCallback & done)78 void CollectiveExecutorMgr::GetStepSequenceAsync(
79     const GetStepSequenceRequest* request, GetStepSequenceResponse* response,
80     const StatusCallback& done) {
81   done(errors::Internal(
82       "CollectiveExecutorMgr does not implement GetStepSequence."));
83 }
84 
RefreshStepIdSequenceAsync(int64 graph_key,const StatusCallback & done)85 void CollectiveExecutorMgr::RefreshStepIdSequenceAsync(
86     int64 graph_key, const StatusCallback& done) {
87   done(errors::Internal(
88       "CollectiveExecutorMgr does not implement RefreshStepIdSequence."));
89 }
90 
91 }  // namespace tensorflow
92