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 #include "tensorflow/core/distributed_runtime/rpc/grpc_worker_service_impl.h" 17 18 #include "grpcpp/impl/codegen/async_stream.h" 19 #include "grpcpp/impl/codegen/async_unary_call.h" 20 #include "grpcpp/impl/codegen/channel_interface.h" 21 #include "grpcpp/impl/codegen/client_unary_call.h" 22 #include "grpcpp/impl/codegen/method_handler.h" 23 #include "grpcpp/impl/codegen/rpc_service_method.h" 24 #include "grpcpp/impl/codegen/service_type.h" 25 #include "grpcpp/impl/codegen/sync_stream.h" 26 27 namespace tensorflow { 28 GrpcWorkerMethodName(GrpcWorkerMethod id)29const char* GrpcWorkerMethodName(GrpcWorkerMethod id) { 30 switch (id) { 31 case GrpcWorkerMethod::kGetStatus: 32 return "/tensorflow.WorkerService/GetStatus"; 33 case GrpcWorkerMethod::kCreateWorkerSession: 34 return "/tensorflow.WorkerService/CreateWorkerSession"; 35 case GrpcWorkerMethod::kDeleteWorkerSession: 36 return "/tensorflow.WorkerService/DeleteWorkerSession"; 37 case GrpcWorkerMethod::kRegisterGraph: 38 return "/tensorflow.WorkerService/RegisterGraph"; 39 case GrpcWorkerMethod::kDeregisterGraph: 40 return "/tensorflow.WorkerService/DeregisterGraph"; 41 case GrpcWorkerMethod::kRunGraph: 42 return "/tensorflow.WorkerService/RunGraph"; 43 case GrpcWorkerMethod::kCleanupGraph: 44 return "/tensorflow.WorkerService/CleanupGraph"; 45 case GrpcWorkerMethod::kCleanupAll: 46 return "/tensorflow.WorkerService/CleanupAll"; 47 case GrpcWorkerMethod::kRecvTensor: 48 return "/tensorflow.WorkerService/RecvTensor"; 49 case GrpcWorkerMethod::kRecvBuf: 50 return "/tensorflow.WorkerService/RecvBuf"; 51 case GrpcWorkerMethod::kLogging: 52 return "/tensorflow.WorkerService/Logging"; 53 case GrpcWorkerMethod::kTracing: 54 return "/tensorflow.WorkerService/Tracing"; 55 case GrpcWorkerMethod::kCompleteGroup: 56 return "/tensorflow.WorkerService/CompleteGroup"; 57 case GrpcWorkerMethod::kCompleteInstance: 58 return "/tensorflow.WorkerService/CompleteInstance"; 59 case GrpcWorkerMethod::kGetStepSequence: 60 return "/tensorflow.WorkerService/GetStepSequence"; 61 case GrpcWorkerMethod::kMarkRecvFinished: 62 return "/tensorflow.WorkerService/MarkRecvFinished"; 63 } 64 // Shouldn't be reached. 65 LOG(FATAL) << "Invalid id: this line shouldn't be reached."; 66 return "invalid id"; 67 } 68 69 namespace grpc { 70 AsyncService()71WorkerService::AsyncService::AsyncService() { 72 for (int i = 0; i < kGrpcNumWorkerMethods; ++i) { 73 AddMethod(new ::grpc::internal::RpcServiceMethod( 74 GrpcWorkerMethodName(static_cast<GrpcWorkerMethod>(i)), 75 ::grpc::internal::RpcMethod::NORMAL_RPC, nullptr)); 76 ::grpc::Service::MarkMethodAsync(i); 77 } 78 } 79 ~AsyncService()80WorkerService::AsyncService::~AsyncService() {} 81 82 } // namespace grpc 83 84 } // namespace tensorflow 85