• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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 #include "tensorflow/core/tpu/kernels/tpu_compilation_cache_grpc.h"
16 
17 #include <functional>
18 
19 #include "grpcpp/impl/codegen/async_stream.h"
20 #include "grpcpp/impl/codegen/async_unary_call.h"
21 #include "grpcpp/impl/codegen/channel_interface.h"
22 #include "grpcpp/impl/codegen/client_callback.h"
23 #include "grpcpp/impl/codegen/client_unary_call.h"
24 #include "grpcpp/impl/codegen/method_handler.h"
25 #include "grpcpp/impl/codegen/rpc_service_method.h"
26 #include "grpcpp/impl/codegen/server_callback.h"
27 #include "grpcpp/impl/codegen/service_type.h"
28 #include "grpcpp/impl/codegen/sync_stream.h"
29 
30 namespace tensorflow {
31 namespace tpu {
32 
33 static const char* grpcTpuCompilationCacheService_method_names[] = {
34 #if defined(LIBTPU_ON_GCE)
35     "/tensorflow.tpu.TpuCompilationCacheServiceExternal/GetTpuProgram",
36 #else  // LIBTPU_ON_GCE
37     "/tensorflow.tpu.TpuCompilationCacheService/GetTpuProgram",
38 #endif  // LIBTPU_ON_GCE
39 };
40 
41 std::unique_ptr<grpc::TpuCompilationCacheService::Stub>
NewStub(const std::shared_ptr<::grpc::ChannelInterface> & channel,const::grpc::StubOptions & options)42 grpc::TpuCompilationCacheService::NewStub(
43     const std::shared_ptr< ::grpc::ChannelInterface>& channel,
44     const ::grpc::StubOptions& options) {
45   (void)options;
46   std::unique_ptr<grpc::TpuCompilationCacheService::Stub> stub(
47       new grpc::TpuCompilationCacheService::Stub(channel));
48   return stub;
49 }
50 
Stub(const std::shared_ptr<::grpc::ChannelInterface> & channel)51 grpc::TpuCompilationCacheService::Stub::Stub(
52     const std::shared_ptr< ::grpc::ChannelInterface>& channel)
53     : channel_(channel),
54       rpcmethod_get_tpu_program_(grpcTpuCompilationCacheService_method_names[0],
55                                  ::grpc::internal::RpcMethod::NORMAL_RPC,
56                                  channel) {}
57 
GetTpuProgram(::grpc::ClientContext * context,const RequestType & request,ResponseType * response)58 ::grpc::Status grpc::TpuCompilationCacheService::Stub::GetTpuProgram(
59     ::grpc::ClientContext* context, const RequestType& request,
60     ResponseType* response) {
61   return ::grpc::internal::BlockingUnaryCall(
62       channel_.get(), rpcmethod_get_tpu_program_, context, request, response);
63 }
64 
65 ::grpc::ClientAsyncResponseReader<
66     grpc::TpuCompilationCacheService::ResponseType>*
AsyncGetTpuProgramRaw(::grpc::ClientContext * context,const RequestType & request,::grpc::CompletionQueue * cq)67 grpc::TpuCompilationCacheService::Stub::AsyncGetTpuProgramRaw(
68     ::grpc::ClientContext* context, const RequestType& request,
69     ::grpc::CompletionQueue* cq) {
70   return ::grpc::internal::ClientAsyncResponseReaderFactory<
71       ResponseType>::Create(channel_.get(), cq, rpcmethod_get_tpu_program_,
72                             context, request, true);
73 }
74 
75 ::grpc::ClientAsyncResponseReader<
76     grpc::TpuCompilationCacheService::ResponseType>*
PrepareAsyncGetTpuProgramRaw(::grpc::ClientContext * context,const RequestType & request,::grpc::CompletionQueue * cq)77 grpc::TpuCompilationCacheService::Stub::PrepareAsyncGetTpuProgramRaw(
78     ::grpc::ClientContext* context, const RequestType& request,
79     ::grpc::CompletionQueue* cq) {
80   return ::grpc::internal::ClientAsyncResponseReaderFactory<
81       ResponseType>::Create(channel_.get(), cq, rpcmethod_get_tpu_program_,
82                             context, request, false);
83 }
84 
Service()85 grpc::TpuCompilationCacheService::Service::Service() {
86   AddMethod(new ::grpc::internal::RpcServiceMethod(
87       grpcTpuCompilationCacheService_method_names[0],
88       ::grpc::internal::RpcMethod::NORMAL_RPC,
89       new ::grpc::internal::RpcMethodHandler<
90           grpc::TpuCompilationCacheService::Service, RequestType, ResponseType>(
91           std::mem_fn(
92               &grpc::TpuCompilationCacheService::Service::GetTpuProgram),
93           this)));
94 }
95 
~Service()96 grpc::TpuCompilationCacheService::Service::~Service() {}
97 
GetTpuProgram(::grpc::ServerContext * context,const RequestType * request,ResponseType * response)98 ::grpc::Status grpc::TpuCompilationCacheService::Service::GetTpuProgram(
99     ::grpc::ServerContext* context, const RequestType* request,
100     ResponseType* response) {
101   (void)context;
102   (void)request;
103   (void)response;
104   return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
105 }
106 
107 }  // namespace tpu
108 }  // namespace tensorflow
109