Skip to content

Commit 1f618cf

Browse files
committed
Implemented rpc logging
1 parent f841b63 commit 1f618cf

File tree

11 files changed

+1345
-264
lines changed

11 files changed

+1345
-264
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ list(APPEND COMPILER_SRCS "src/target/datatype/myfloat/myfloat.cc")
317317
tvm_file_glob(GLOB RUNTIME_SRCS
318318
src/runtime/*.cc
319319
src/runtime/vm/*.cc
320+
src/runtime/minrpc/*.cc
320321
)
321322

322323
if(BUILD_FOR_HEXAGON)

python/tvm/rpc/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def request_and_run(self, key, func, priority=1, session_timeout=0, max_retry=2)
459459
)
460460

461461

462-
def connect(url, port, key="", session_timeout=0, session_constructor_args=None):
462+
def connect(url, port, key="", session_timeout=0, session_constructor_args=None, **kwargs):
463463
"""Connect to RPC Server
464464
465465
Parameters
@@ -483,6 +483,9 @@ def connect(url, port, key="", session_timeout=0, session_constructor_args=None)
483483
The first element of the list is always a string specifying the name of
484484
the session constructor, the following args are the positional args to that function.
485485
486+
**kwargs: optional
487+
enable_logging flag to enable/disable logging. Logging is disabled by default.
488+
486489
Returns
487490
-------
488491
sess : RPCSession
@@ -505,7 +508,7 @@ def connect(url, port, key="", session_timeout=0, session_constructor_args=None)
505508
client_via_proxy = rpc.connect(
506509
proxy_server_url, proxy_server_port, proxy_server_key,
507510
session_constructor_args=[
508-
"rpc.Connect", internal_url, internal_port, internal_key])
511+
"rpc.Connect", internal_url, internal_port, internal_key, enable_logging])
509512
510513
"""
511514
try:
@@ -514,7 +517,10 @@ def connect(url, port, key="", session_timeout=0, session_constructor_args=None)
514517
session_constructor_args = session_constructor_args if session_constructor_args else []
515518
if not isinstance(session_constructor_args, (list, tuple)):
516519
raise TypeError("Expect the session constructor to be a list or tuple")
517-
sess = _ffi_api.Connect(url, port, key, *session_constructor_args)
520+
enable_logging = False
521+
if kwargs is not None and "enable_logging" in kwargs:
522+
enable_logging = kwargs["enable_logging"]
523+
sess = _ffi_api.Connect(url, port, key, enable_logging, *session_constructor_args)
518524
except NameError:
519525
raise RuntimeError("Please compile with USE_RPC=1")
520526
return RPCSession(sess)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 sent the responses.
32+
*/
33+
class ReturnInterface {
34+
public:
35+
virtual ~ReturnInterface() {}
36+
virtual void ReturnVoid() = 0;
37+
virtual void ReturnHandle(void* handle) = 0;
38+
virtual void ReturnException(const char* msg) = 0;
39+
virtual void ReturnPackedSeq(const TVMValue* arg_values, const int* type_codes, int num_args) = 0;
40+
virtual void ReturnCopyAck(uint64_t* num_bytes, uint8_t** data_ptr) = 0;
41+
virtual void ReturnLastTVMError() = 0;
42+
virtual void ThrowError(RPCServerStatus code, RPCCode info = RPCCode::kNone) = 0;
43+
};
44+
45+
/*!
46+
* \brief Execute interface used in MinRPCServer to process different received commands
47+
*/
48+
class ExecInterface {
49+
public:
50+
virtual ~ExecInterface() {}
51+
virtual void ExecInitServer(int* num_args) = 0;
52+
virtual void ExecNormalCallFunc(uint64_t* call_handle, TVMValue** values, int** tcodes,
53+
int* num_args) = 0;
54+
virtual void ExecCopyFromRemote(DLTensor** arr, uint64_t* num_bytes, uint8_t** data_ptr) = 0;
55+
virtual int ExecCopyToRemote(DLTensor** arr, uint64_t* num_bytes, uint8_t** data_ptr) = 0;
56+
virtual void ExecSyscallFunc(RPCCode* code, TVMValue** values, int** tcodes, int* num_args) = 0;
57+
virtual void ThrowError(RPCServerStatus code, RPCCode info = RPCCode::kNone) = 0;
58+
virtual ReturnInterface* GetReturnInterface() = 0;
59+
};
60+
61+
} // namespace runtime
62+
} // namespace tvm
63+
#endif // TVM_RUNTIME_MINRPC_MINRPC_INTERFACES_H_

0 commit comments

Comments
 (0)