1 | /* |
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | |
20 | #ifndef TVM_RUNTIME_MINRPC_MINRPC_INTERFACES_H_ |
21 | #define TVM_RUNTIME_MINRPC_MINRPC_INTERFACES_H_ |
22 | |
23 | #include <tvm/runtime/c_runtime_api.h> |
24 | |
25 | #include "rpc_reference.h" |
26 | |
27 | namespace tvm { |
28 | namespace runtime { |
29 | |
30 | /*! |
31 | * \brief Return interface used in ExecInterface to generate and send the responses. |
32 | */ |
33 | class MinRPCReturnInterface { |
34 | public: |
35 | virtual ~MinRPCReturnInterface() {} |
36 | /*! * \brief sends a response to the client with kTVMNullptr in payload. */ |
37 | virtual void ReturnVoid() = 0; |
38 | |
39 | /*! * \brief sends a response to the client with one kTVMOpaqueHandle in payload. */ |
40 | virtual void ReturnHandle(void* handle) = 0; |
41 | |
42 | /*! * \brief sends an exception response to the client with a kTVMStr in payload. */ |
43 | virtual void ReturnException(const char* msg) = 0; |
44 | |
45 | /*! * \brief sends a packed argument sequnce to the client. */ |
46 | virtual void ReturnPackedSeq(const TVMValue* arg_values, const int* type_codes, int num_args) = 0; |
47 | |
48 | /*! * \brief sends a copy of the requested remote data to the client. */ |
49 | virtual void ReturnCopyFromRemote(uint8_t* data_ptr, uint64_t num_bytes) = 0; |
50 | |
51 | /*! * \brief sends an exception response to the client with the last TVM erros as the message. */ |
52 | virtual void ReturnLastTVMError() = 0; |
53 | |
54 | /*! * \brief internal error. */ |
55 | virtual void ThrowError(RPCServerStatus code, RPCCode info = RPCCode::kNone) = 0; |
56 | }; |
57 | |
58 | /*! |
59 | * \brief Execute interface used in MinRPCServer to process different received commands |
60 | */ |
61 | class MinRPCExecInterface { |
62 | public: |
63 | virtual ~MinRPCExecInterface() {} |
64 | |
65 | /*! * \brief Execute an Initilize server command. */ |
66 | virtual void InitServer(int num_args) = 0; |
67 | |
68 | /*! * \brief calls a function specified by the call_handle. */ |
69 | virtual void NormalCallFunc(uint64_t call_handle, TVMValue* values, int* tcodes, |
70 | int num_args) = 0; |
71 | |
72 | /*! * \brief Execute a copy from remote command by sending the data described in arr to the client |
73 | */ |
74 | virtual void CopyFromRemote(DLTensor* arr, uint64_t num_bytes, uint8_t* data_ptr) = 0; |
75 | |
76 | /*! * \brief Execute a copy to remote command by receiving the data described in arr from the |
77 | * client */ |
78 | virtual int CopyToRemote(DLTensor* arr, uint64_t num_bytes, uint8_t* data_ptr) = 0; |
79 | |
80 | /*! * \brief calls a system function specified by the code. */ |
81 | virtual void SysCallFunc(RPCCode code, TVMValue* values, int* tcodes, int num_args) = 0; |
82 | |
83 | /*! * \brief internal error. */ |
84 | virtual void ThrowError(RPCServerStatus code, RPCCode info = RPCCode::kNone) = 0; |
85 | |
86 | /*! * \brief return the ReturnInterface pointer that is used to generate and send the responses. |
87 | */ |
88 | virtual MinRPCReturnInterface* GetReturnInterface() = 0; |
89 | }; |
90 | |
91 | } // namespace runtime |
92 | } // namespace tvm |
93 | #endif // TVM_RUNTIME_MINRPC_MINRPC_INTERFACES_H_ |
94 | |