• 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_RENDEZVOUS_MGR_INTERFACE_H_
17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_RENDEZVOUS_MGR_INTERFACE_H_
18 
19 #include <string>
20 
21 #include "tensorflow/core/distributed_runtime/worker_env.h"
22 #include "tensorflow/core/framework/rendezvous.h"
23 #include "tensorflow/core/lib/core/status.h"
24 #include "tensorflow/core/platform/types.h"
25 
26 namespace tensorflow {
27 
28 struct WorkerSession;
29 
30 // RemoteRendezvous follow a 2-part initialization. First the objects are
31 // constructed. Eventually, they will be initialized. Clients of the
32 // RendezvousMgrInterface must guarantee to call Initialize on the returned
33 // RemoteRendezvous eventually.
34 //
35 // Partially initialized RemoteRendezvous must respect the Rendezvous interface
36 // (i.e. Send() must never block), however implementations are not expected to
37 // actually perform the underlying operations until after the RemoteRendezvous
38 // has been Initialize'd.
39 class RemoteRendezvous : public Rendezvous {
40  public:
41   // Fully construct the RemoteRendezvous.
42   virtual Status Initialize(WorkerSession* session) = 0;
43 };
44 
45 // RendezvousMgr keeps track of a set of local rendezvous instances.
46 // All tensors sent by this worker are buffered in a RendezvousMgr
47 // until the tensor is received.  Each global unique "step_id"
48 // corresponds to one local rendezvous instance managed by a
49 // RendezvousMgr.
50 //
51 // E.g.,
52 //   Rendezvous* rendez = worker_env->rendezvous_mgr->Find(0x8935);
53 //   fork execution of an graph executor using "rendez"  on thread 1;
54 //   fork execution of another graph executor using "rendez" on thread 2;
55 //   ...
56 //   join threads 1 and 2;
57 //
58 // In the example above, execution in thread 1 and 2 communicates with
59 // each other by send/recv operations through the "rend".
60 //
61 // Tensors sent and recved through rendezvous managed by this
62 // RendezvousMgr must have keys generated by Rendezvous::CreateKey.
63 class RendezvousMgrInterface {
64  public:
RendezvousMgrInterface()65   RendezvousMgrInterface() {}
~RendezvousMgrInterface()66   virtual ~RendezvousMgrInterface() {}
67 
68   // Returns Rendezvous supporting send and recv among workers in the
69   // "step_id".  The caller takes ownership of one reference on the
70   // returned Rendezvous instance.
71   //
72   // Note: the caller must guarantee to eventually call Initialize on the
73   // returned RemoteRendezvous
74   virtual RemoteRendezvous* Find(int64 step_id) = 0;
75 
76   // Finds the local rendezvous instance for the "step_id".  Runs
77   // "done" when the tensor for "key" is produced or an error occurs.
78   //
79   // This method is used by the rpc handler of RecvTensor.
80   virtual void RecvLocalAsync(int64 step_id,
81                               const Rendezvous::ParsedKey& parsed,
82                               Rendezvous::DoneCallback done) = 0;
83 
84   // Synchronous wrapper for RecvLocalAsync.
85   virtual Status RecvLocal(int64 step_id, const Rendezvous::ParsedKey& parsed,
86                            Tensor* val, bool* is_dead) = 0;
87 
88   // Removes rendezvous for "step_id".
89   //
90   // TODO(zhifengc): Have a background thread in worker that
91   // periodically calls CleanupAll().
92   virtual void Cleanup(int64 step_id) = 0;
93 
94   // Removes all rendezvous.
95   virtual void CleanupAll() = 0;
96 };
97 
98 }  // end namespace tensorflow
99 
100 #endif  // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_RENDEZVOUS_MGR_INTERFACE_H_
101