Home | History | Annotate | Download | only in eager
      1 /* Copyright 2018 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/eager/grpc_eager_service.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 namespace eager {
     29 
     30 namespace grpc {
     31 
     32 static const char* grpcEagerService_method_names[] = {
     33     "/tensorflow.eager.EagerService/CreateContext",
     34     "/tensorflow.eager.EagerService/Enqueue",
     35     "/tensorflow.eager.EagerService/WaitQueueDone",
     36     "/tensorflow.eager.EagerService/KeepAlive",
     37     "/tensorflow.eager.EagerService/CloseContext",
     38     "/tensorflow.eager.EagerService/RegisterFunction",
     39     "/tensorflow.eager.EagerService/SendTensor",
     40 };
     41 
     42 std::unique_ptr<EagerService::Stub> EagerService::NewStub(
     43     const std::shared_ptr< ::grpc::ChannelInterface>& channel,
     44     const ::grpc::StubOptions& options) {
     45   std::unique_ptr<EagerService::Stub> stub(new EagerService::Stub(channel));
     46   return stub;
     47 }
     48 
     49 EagerService::Stub::Stub(
     50     const std::shared_ptr< ::grpc::ChannelInterface>& channel)
     51     : channel_(channel),
     52       rpcmethod_CreateContext_(grpcEagerService_method_names[0],
     53                                ::grpc::internal::RpcMethod::NORMAL_RPC,
     54                                channel),
     55       rpcmethod_Enqueue_(grpcEagerService_method_names[1],
     56                          ::grpc::internal::RpcMethod::NORMAL_RPC, channel),
     57       rpcmethod_WaitQueueDone_(grpcEagerService_method_names[2],
     58                                ::grpc::internal::RpcMethod::NORMAL_RPC,
     59                                channel),
     60       rpcmethod_KeepAlive_(grpcEagerService_method_names[3],
     61                            ::grpc::internal::RpcMethod::NORMAL_RPC, channel),
     62       rpcmethod_CloseContext_(grpcEagerService_method_names[4],
     63                               ::grpc::internal::RpcMethod::NORMAL_RPC, channel),
     64       rpcmethod_RegisterFunction_(grpcEagerService_method_names[5],
     65                                   ::grpc::internal::RpcMethod::NORMAL_RPC,
     66                                   channel),
     67       rpcmethod_SendTensor_(grpcEagerService_method_names[6],
     68                             ::grpc::internal::RpcMethod::NORMAL_RPC, channel) {}
     69 
     70 ::grpc::Status EagerService::Stub::CreateContext(
     71     ::grpc::ClientContext* context, const CreateContextRequest& request,
     72     CreateContextResponse* response) {
     73   return ::grpc::internal::BlockingUnaryCall(
     74       channel_.get(), rpcmethod_CreateContext_, context, request, response);
     75 }
     76 
     77 ::grpc::Status EagerService::Stub::Enqueue(::grpc::ClientContext* context,
     78                                            const EnqueueRequest& request,
     79                                            EnqueueResponse* response) {
     80   return ::grpc::internal::BlockingUnaryCall(channel_.get(), rpcmethod_Enqueue_,
     81                                              context, request, response);
     82 }
     83 
     84 ::grpc::Status EagerService::Stub::WaitQueueDone(
     85     ::grpc::ClientContext* context, const WaitQueueDoneRequest& request,
     86     WaitQueueDoneResponse* response) {
     87   return ::grpc::internal::BlockingUnaryCall(
     88       channel_.get(), rpcmethod_WaitQueueDone_, context, request, response);
     89 }
     90 
     91 ::grpc::Status EagerService::Stub::KeepAlive(::grpc::ClientContext* context,
     92                                              const KeepAliveRequest& request,
     93                                              KeepAliveResponse* response) {
     94   return ::grpc::internal::BlockingUnaryCall(
     95       channel_.get(), rpcmethod_KeepAlive_, context, request, response);
     96 }
     97 
     98 ::grpc::Status EagerService::Stub::CloseContext(
     99     ::grpc::ClientContext* context, const CloseContextRequest& request,
    100     CloseContextResponse* response) {
    101   return ::grpc::internal::BlockingUnaryCall(
    102       channel_.get(), rpcmethod_CloseContext_, context, request, response);
    103 }
    104 
    105 ::grpc::Status EagerService::Stub::RegisterFunction(
    106     ::grpc::ClientContext* context, const RegisterFunctionRequest& request,
    107     RegisterFunctionResponse* response) {
    108   return ::grpc::internal::BlockingUnaryCall(
    109       channel_.get(), rpcmethod_RegisterFunction_, context, request, response);
    110 }
    111 
    112 ::grpc::Status EagerService::Stub::SendTensor(::grpc::ClientContext* context,
    113                                               const SendTensorRequest& request,
    114                                               SendTensorResponse* response) {
    115   return ::grpc::internal::BlockingUnaryCall(
    116       channel_.get(), rpcmethod_SendTensor_, context, request, response);
    117 }
    118 
    119 EagerService::AsyncService::AsyncService() {
    120   for (int i = 0; i < 7; ++i) {
    121     AddMethod(new ::grpc::internal::RpcServiceMethod(
    122         grpcEagerService_method_names[i],
    123         ::grpc::internal::RpcMethod::NORMAL_RPC, nullptr));
    124     ::grpc::Service::MarkMethodAsync(i);
    125   }
    126 }
    127 
    128 EagerService::AsyncService::~AsyncService() {}
    129 
    130 }  // namespace grpc
    131 
    132 }  // namespace eager
    133 }  // namespace tensorflow
    134