1 /* Copyright 2021 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_COORDINATION_COORDINATION_CLIENT_H_ 17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_CLIENT_H_ 18 19 #include <memory> 20 #include <string> 21 22 #include "tensorflow/core/distributed_runtime/call_options.h" 23 #include "tensorflow/core/lib/core/status.h" 24 #include "tensorflow/core/protobuf/coordination_service.pb.h" 25 26 namespace tensorflow { 27 28 // Base class of client interface for communicating with coordination service. 29 // Can be implemented by a variety of transports such as gRPC. 30 class CoordinationClient { 31 public: ~CoordinationClient()32 virtual ~CoordinationClient() {} 33 34 virtual void RegisterTaskAsync(CallOptions* call_opts, 35 const RegisterTaskRequest* request, 36 RegisterTaskResponse* response, 37 StatusCallback done) = 0; 38 39 virtual void HeartbeatAsync(CallOptions* call_opts, 40 const HeartbeatRequest* request, 41 HeartbeatResponse* response, 42 StatusCallback done) = 0; 43 44 virtual void WaitForAllTasksAsync(const WaitForAllTasksRequest* request, 45 WaitForAllTasksResponse* response, 46 StatusCallback done) = 0; 47 48 virtual void ShutdownTaskAsync(CallOptions* call_opts, 49 const ShutdownTaskRequest* request, 50 ShutdownTaskResponse* response, 51 StatusCallback done) = 0; 52 53 virtual void ResetTaskAsync(const ResetTaskRequest* request, 54 ResetTaskResponse* response, 55 StatusCallback done) = 0; 56 57 virtual void ReportErrorToTaskAsync(CallOptions* call_opts, 58 const ReportErrorToTaskRequest* request, 59 ReportErrorToTaskResponse* response, 60 StatusCallback done) = 0; 61 62 virtual void ReportErrorToServiceAsync( 63 const ReportErrorToServiceRequest* request, 64 ReportErrorToServiceResponse* response, StatusCallback done) = 0; 65 66 virtual void InsertKeyValueAsync(const InsertKeyValueRequest* request, 67 InsertKeyValueResponse* response, 68 StatusCallback done) = 0; 69 70 virtual void GetKeyValueAsync(CallOptions* call_opts, 71 const GetKeyValueRequest* request, 72 GetKeyValueResponse* response, 73 StatusCallback done) = 0; 74 75 virtual void TryGetKeyValueAsync(const TryGetKeyValueRequest* request, 76 TryGetKeyValueResponse* response, 77 StatusCallback done) = 0; 78 79 virtual void GetKeyValueDirAsync(const GetKeyValueDirRequest* request, 80 GetKeyValueDirResponse* response, 81 StatusCallback done) = 0; 82 83 virtual void DeleteKeyValueAsync(const DeleteKeyValueRequest* request, 84 DeleteKeyValueResponse* response, 85 StatusCallback done) = 0; 86 87 virtual void BarrierAsync(const BarrierRequest* request, 88 BarrierResponse* response, StatusCallback done) = 0; 89 90 virtual void CancelBarrierAsync(const CancelBarrierRequest* request, 91 CancelBarrierResponse* response, 92 StatusCallback done) = 0; 93 }; 94 95 // Simple wrapper class that can be used to retrieve CoordinationClients. 96 class CoordinationClientCache { 97 public: ~CoordinationClientCache()98 virtual ~CoordinationClientCache() {} 99 100 // If the `target` names a remote task, returns a pointer of the 101 // CoordinationClient object wrapping that channel to the remote task. 102 virtual CoordinationClient* GetClient(const std::string& target) = 0; 103 104 // If the `target` names a remote task, returns an owned pointer of the 105 // CoordinationClient object wrapping that channel to the remote task. 106 virtual std::unique_ptr<CoordinationClient> GetOwnedClient( 107 const std::string& target) = 0; 108 }; 109 110 } // namespace tensorflow 111 112 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_COORDINATION_COORDINATION_CLIENT_H_ 113