Skip to content

Commit 111e6ff

Browse files
committed
Implemented rpc logging
1 parent f841b63 commit 111e6ff

File tree

14 files changed

+1474
-275
lines changed

14 files changed

+1474
-275
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/micro/session.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def __enter__(self):
133133
int(timeouts.session_start_timeout_sec * 1e6),
134134
int(timeouts.session_established_timeout_sec * 1e6),
135135
self._cleanup,
136+
False,
136137
)
137138
)
138139
self.device = self._rpc.cpu(0)

python/tvm/rpc/client.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ 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(
463+
url, port, key="", session_timeout=0, session_constructor_args=None, enable_logging=False
464+
):
463465
"""Connect to RPC Server
464466
465467
Parameters
@@ -483,6 +485,9 @@ def connect(url, port, key="", session_timeout=0, session_constructor_args=None)
483485
The first element of the list is always a string specifying the name of
484486
the session constructor, the following args are the positional args to that function.
485487
488+
enable_logging: boolean
489+
flag to enable/disable logging. Logging is disabled by default.
490+
486491
Returns
487492
-------
488493
sess : RPCSession
@@ -503,9 +508,9 @@ def connect(url, port, key="", session_timeout=0, session_constructor_args=None)
503508
.. code-block:: python
504509
505510
client_via_proxy = rpc.connect(
506-
proxy_server_url, proxy_server_port, proxy_server_key,
511+
proxy_server_url, proxy_server_port, proxy_server_key, enable_logging
507512
session_constructor_args=[
508-
"rpc.Connect", internal_url, internal_port, internal_key])
513+
"rpc.Connect", internal_url, internal_port, internal_key, internal_logging])
509514
510515
"""
511516
try:
@@ -514,7 +519,7 @@ def connect(url, port, key="", session_timeout=0, session_constructor_args=None)
514519
session_constructor_args = session_constructor_args if session_constructor_args else []
515520
if not isinstance(session_constructor_args, (list, tuple)):
516521
raise TypeError("Expect the session constructor to be a list or tuple")
517-
sess = _ffi_api.Connect(url, port, key, *session_constructor_args)
522+
sess = _ffi_api.Connect(url, port, key, enable_logging, *session_constructor_args)
518523
except NameError:
519524
raise RuntimeError("Please compile with USE_RPC=1")
520525
return RPCSession(sess)

src/runtime/crt/microtvm_rpc_server/rpc_server.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ class MicroRPCServer {
193193
} // namespace runtime
194194
} // namespace tvm
195195

196-
void* operator new[](size_t count, void* ptr) noexcept { return ptr; }
197-
198196
extern "C" {
199197

200198
static microtvm_rpc_server_t g_rpc_server = nullptr;

src/runtime/micro/micro_session.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
#include "../../support/str_escape.h"
4040
#include "../rpc/rpc_channel.h"
41+
#include "../rpc/rpc_channel_logger.h"
4142
#include "../rpc/rpc_endpoint.h"
4243
#include "../rpc/rpc_session.h"
4344
#include "crt_config.h"
@@ -404,6 +405,13 @@ TVM_REGISTER_GLOBAL("micro._rpc_connect").set_body([](TVMArgs args, TVMRetValue*
404405
throw std::runtime_error(ss.str());
405406
}
406407
std::unique_ptr<RPCChannel> channel(micro_channel);
408+
bool enable_logging = false;
409+
if (args.num_args > 7) {
410+
enable_logging = args[7];
411+
}
412+
if (enable_logging) {
413+
channel.reset(new RPCChannelLogging(std::move(channel)));
414+
}
407415
auto ep = RPCEndpoint::Create(std::move(channel), args[0], "", args[6]);
408416
auto sess = CreateClientSession(ep);
409417
*rv = CreateRPCSessionModule(sess);
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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_

0 commit comments

Comments
 (0)