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_LOCAL_MASTER_H_ 17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_LOCAL_MASTER_H_ 18 19 #include <memory> 20 21 #include "tensorflow/core/distributed_runtime/master_interface.h" 22 23 namespace tensorflow { 24 25 class Master; 26 27 // An implementation of the TensorFlow master interface that enables direct 28 // intraprocess communication between the client and the master implementation. 29 // 30 // This master implementation is intended to provide more efficient access to 31 // a master service that has been created in the same process as the client. 32 // 33 // TODO(mrry): Add methods that avoid protobuf encoding the request/response 34 // objects where this affects performance. 35 // TODO(mrry): Avoid closure creation/context switch overhead for synchronous 36 // invocation of Master methods. 37 // TODO(mrry): Make all potentially blocking Master methods take CallOptions 38 // for cancellation. 39 class LocalMaster : public MasterInterface { 40 public: ~LocalMaster()41 ~LocalMaster() {} 42 43 Status CreateSession(CallOptions* call_options, 44 const CreateSessionRequest* request, 45 CreateSessionResponse* response) override; 46 47 Status ExtendSession(CallOptions* call_options, 48 const ExtendSessionRequest* request, 49 ExtendSessionResponse* response) override; 50 51 Status PartialRunSetup(CallOptions* call_options, 52 const PartialRunSetupRequest* request, 53 PartialRunSetupResponse* response) override; 54 55 Status RunStep(CallOptions* call_options, RunStepRequestWrapper* request, 56 MutableRunStepResponseWrapper* response) override; 57 58 MutableRunStepRequestWrapper* CreateRunStepRequest() override; 59 60 MutableRunStepResponseWrapper* CreateRunStepResponse() override; 61 62 Status CloseSession(CallOptions* call_options, 63 const CloseSessionRequest* request, 64 CloseSessionResponse* response) override; 65 66 Status ListDevices(CallOptions* call_options, 67 const ListDevicesRequest* request, 68 ListDevicesResponse* response) override; 69 70 // See tensorflow::Reset() and the comment on ResetRequest. 71 Status Reset(CallOptions* call_options, const ResetRequest* request, 72 ResetResponse* response) override; 73 74 Status MakeCallable(CallOptions* call_options, 75 const MakeCallableRequest* request, 76 MakeCallableResponse* response) override; 77 Status RunCallable(CallOptions* call_options, 78 const RunCallableRequest* request, 79 RunCallableResponse* response) override; 80 Status ReleaseCallable(CallOptions* call_options, 81 const ReleaseCallableRequest* request, 82 ReleaseCallableResponse* response) override; 83 84 // Registers the mapping from the given `target` to the given `master`. 85 // 86 // WARNING: The `master` pointer remains owned by the caller. It is 87 // the responsibility of the caller to ensure that `master` outlives 88 // any LocalMaster objects that may wrap this master. There is no 89 // corresponding deregister method, since clean server shutdown is 90 // not currently implemented for any server type. 91 static void Register(const string& target, Master* master, 92 int64 default_timeout_in_ms); 93 94 // Returns a pointer to the local master associated with the given 95 // `target`, or nullptr if none exists. 96 static std::unique_ptr<LocalMaster> Lookup(const string& target); 97 98 private: 99 Master* master_impl_; // Not owned. 100 const int64 default_timeout_in_ms_; 101 102 // See `LocalMaster::Lookup` for the factory function that creates 103 // objects of this type. 104 LocalMaster(Master* master_impl, const int64 default_timeout_in_ms); 105 106 TF_DISALLOW_COPY_AND_ASSIGN(LocalMaster); 107 }; 108 109 } // namespace tensorflow 110 111 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_LOCAL_MASTER_H_ 112