xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/rpc/grpc_service.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
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 #ifndef TENSORFLOW_COMPILER_XLA_RPC_GRPC_SERVICE_H_
17 #define TENSORFLOW_COMPILER_XLA_RPC_GRPC_SERVICE_H_
18 
19 #include "grpcpp/server_context.h"
20 #include "tensorflow/compiler/xla/rpc/xla_service.grpc.pb.h"
21 #include "tensorflow/compiler/xla/service/service.h"
22 
23 namespace xla {
24 
25 // Service implementation which wraps a XLA Service with a GRPC interface.
26 class GRPCService : public grpc::XlaService::Service {
27  public:
28   // Factory for creating a RPCService. The parameter platform is the platform
29   // that the service should target. If platform is null then the default
30   // platform is used.
31   static StatusOr<std::unique_ptr<GRPCService>> NewService(
32       se::Platform* platform = nullptr);
33 
34   ::grpc::Status Unregister(::grpc::ServerContext* context,
35                             const UnregisterRequest* arg,
36                             UnregisterResponse* result) override;
37 
38   ::grpc::Status DeconstructTuple(::grpc::ServerContext* context,
39                                   const DeconstructTupleRequest* arg,
40                                   DeconstructTupleResponse* result) override;
41 
42   ::grpc::Status GetDeviceHandles(::grpc::ServerContext* context,
43                                   const GetDeviceHandlesRequest* arg,
44                                   GetDeviceHandlesResponse* result) override;
45 
46   ::grpc::Status Compile(::grpc::ServerContext* context,
47                          const CompileRequest* arg,
48                          CompileResponse* result) override;
49 
50   ::grpc::Status Execute(::grpc::ServerContext* context,
51                          const ExecuteRequest* arg,
52                          ExecuteResponse* result) override;
53   ::grpc::Status ExecuteGraphParallel(::grpc::ServerContext* context,
54                                       const ExecuteGraphParallelRequest* arg,
55                                       ExecuteParallelResponse* result) override;
56 
57   ::grpc::Status WaitForExecution(::grpc::ServerContext* context,
58                                   const WaitForExecutionRequest* arg,
59                                   WaitForExecutionResponse* result) override;
60 
61   ::grpc::Status TransferToClient(::grpc::ServerContext* context,
62                                   const TransferToClientRequest* arg,
63                                   TransferToClientResponse* result) override;
64 
65   ::grpc::Status TransferToServer(::grpc::ServerContext* context,
66                                   const TransferToServerRequest* arg,
67                                   TransferToServerResponse* result) override;
68 
69   ::grpc::Status TransferToInfeed(::grpc::ServerContext* context,
70                                   const TransferToInfeedRequest* arg,
71                                   TransferToInfeedResponse* result) override;
72 
73   ::grpc::Status TransferFromOutfeed(
74       ::grpc::ServerContext* context, const TransferFromOutfeedRequest* arg,
75       TransferFromOutfeedResponse* result) override;
76 
77   ::grpc::Status ResetDevice(::grpc::ServerContext* context,
78                              const ResetDeviceRequest* arg,
79                              ResetDeviceResponse* result) override;
80 
81   ::grpc::Status GetShape(::grpc::ServerContext* context,
82                           const GetShapeRequest* arg,
83                           GetShapeResponse* result) override;
84 
85  private:
86   std::unique_ptr<::xla::Service> service_;
87 
GRPCService()88   GRPCService() {}
89   GRPCService(const GRPCService&) = delete;
90   void operator=(const GRPCService&) = delete;
91 };
92 }  // namespace xla
93 
94 #endif  // TENSORFLOW_COMPILER_XLA_RPC_GRPC_SERVICE_H_
95