1 /* Copyright 2017 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_CONTRIB_VERBS_GRPC_VERBS_SERVICE_H_ 17 #define TENSORFLOW_CONTRIB_VERBS_GRPC_VERBS_SERVICE_H_ 18 19 #ifdef TENSORFLOW_USE_VERBS 20 21 #include "tensorflow/contrib/verbs/grpc_verbs_service_impl.h" 22 #include "tensorflow/contrib/verbs/rdma_mgr.h" 23 #include "tensorflow/contrib/verbs/verbs_service.pb.h" 24 #include "tensorflow/core/distributed_runtime/rpc/async_service_interface.h" 25 #include "tensorflow/core/distributed_runtime/rpc/grpc_call.h" 26 #include "tensorflow/core/lib/core/refcount.h" 27 28 namespace grpc { 29 class ServerBuilder; 30 class ServerCompletionQueue; 31 class Alarm; 32 } // namespace grpc 33 34 namespace tensorflow { 35 36 class GrpcVerbsService : public AsyncServiceInterface { 37 public: 38 GrpcVerbsService(const WorkerEnv* worker_env, ::grpc::ServerBuilder* builder); 39 ~GrpcVerbsService(); 40 void HandleRPCsLoop() override; 41 void Shutdown() override; 42 void SetRdmaMgr(RdmaMgr* rdma_mgr) { rdma_mgr_ = rdma_mgr; } 43 44 private: 45 template <class RequestMessage, class ResponseMessage> 46 using WorkerCall = Call<GrpcVerbsService, grpc::VerbsService::AsyncService, 47 RequestMessage, ResponseMessage>; 48 void GetRemoteAddressHandler( 49 WorkerCall<GetRemoteAddressRequest, GetRemoteAddressResponse>* call); 50 Status GetRemoteAddressSync(const GetRemoteAddressRequest* request, 51 GetRemoteAddressResponse* response); 52 53 ::grpc::ServerCompletionQueue* cq_; 54 grpc::VerbsService::AsyncService verbs_service_; 55 mutex shutdown_mu_; 56 bool is_shutdown_ GUARDED_BY(shutdown_mu_); 57 ::grpc::Alarm* shutdown_alarm_; 58 // not owned 59 RdmaMgr* rdma_mgr_; 60 const WorkerEnv* const worker_env_; 61 62 TF_DISALLOW_COPY_AND_ASSIGN(GrpcVerbsService); 63 }; 64 65 // Create a GrpcVerbsService, then assign it to a given handle. 66 void SetNewVerbsService(GrpcVerbsService** handle, const WorkerEnv* worker_env, 67 ::grpc::ServerBuilder* builder); 68 69 } // namespace tensorflow 70 71 #endif // TENSORFLOW_USE_VERBS 72 #endif // TENSORFLOW_CONTRIB_VERBS_GRPC_VERBS_SERVICE_H_ 73