• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_impl.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)29 const 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   }
62   // Shouldn't be reached.
63   LOG(FATAL) << "Invalid id: this line shouldn't be reached.";
64   return "invalid id";
65 }
66 
67 namespace grpc {
68 
AsyncService()69 WorkerService::AsyncService::AsyncService() {
70   for (int i = 0; i < kGrpcNumWorkerMethods; ++i) {
71     AddMethod(new ::grpc::internal::RpcServiceMethod(
72         GrpcWorkerMethodName(static_cast<GrpcWorkerMethod>(i)),
73         ::grpc::internal::RpcMethod::NORMAL_RPC, nullptr));
74     ::grpc::Service::MarkMethodAsync(i);
75   }
76 }
77 
~AsyncService()78 WorkerService::AsyncService::~AsyncService() {}
79 
80 }  // namespace grpc
81 
82 }  // namespace tensorflow
83