1 /* Copyright 2020 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_COMMON_RUNTIME_EAGER_CONTEXT_DISTRIBUTED_MANAGER_H_ 17 #define TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_CONTEXT_DISTRIBUTED_MANAGER_H_ 18 19 #include <memory> 20 #include <string> 21 #include <utility> 22 23 #include "tensorflow/c/eager/immediate_execution_context.h" 24 #include "tensorflow/c/eager/immediate_execution_distributed_manager.h" 25 #include "tensorflow/core/common_runtime/eager/context.h" 26 #include "tensorflow/core/platform/status.h" 27 28 #if !defined(IS_MOBILE_PLATFORM) 29 #include "tensorflow/core/distributed_runtime/coordination/coordination_service_agent.h" 30 #include "tensorflow/core/distributed_runtime/preemption/preemption_notifier.h" 31 #endif // !IS_MOBILE_PLATFORM 32 33 namespace tensorflow { 34 #if !defined(IS_MOBILE_PLATFORM) 35 class EagerContext; 36 class ServerDef; 37 38 class EagerContextDistributedManager 39 : public ImmediateExecutionDistributedManager { 40 public: EagerContextDistributedManager(EagerContext * context)41 explicit EagerContextDistributedManager(EagerContext* context) 42 : context_(context) {} 43 44 Status SetOrUpdateServerDef(const ServerDef& server_def, bool reset_context, 45 int keep_alive_secs) override; 46 47 Status EnableCollectiveOps(const ServerDef& server_def) override; 48 49 Status CheckRemoteAlive(const std::string& remote_task_name, 50 bool* is_alive) override; 51 GetCoordinationServiceAgent()52 CoordinationServiceAgent* GetCoordinationServiceAgent() override { 53 return coordination_service_agent_; 54 } SetCoordinationServiceAgent(CoordinationServiceAgent * agent)55 void SetCoordinationServiceAgent(CoordinationServiceAgent* agent) { 56 coordination_service_agent_ = agent; 57 } SetPreemptionNotifier(std::unique_ptr<PreemptionNotifier> notifier)58 void SetPreemptionNotifier(std::unique_ptr<PreemptionNotifier> notifier) { 59 preemption_notifier_ = std::move(notifier); 60 } 61 62 private: 63 EagerContext* context_; 64 // Owned by context_->GetServer()->worker_env()->session_mgr. 65 CoordinationServiceAgent* coordination_service_agent_ = nullptr; 66 std::unique_ptr<PreemptionNotifier> preemption_notifier_; 67 }; 68 #endif // !IS_MOBILE_PLATFORM 69 } // namespace tensorflow 70 71 #endif // TENSORFLOW_CORE_COMMON_RUNTIME_EAGER_CONTEXT_DISTRIBUTED_MANAGER_H_ 72