Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
[microTVM] Fix RPC session close on runtime side (apache#13310)
Browse files Browse the repository at this point in the history
Currently, the RPC session on C/C++ side does not know if the session  
was closed on Python side which causes extra read/write on transport   
while the session is already closed. This commit reuses the Hexagon    
approach in microTVM to shutdown the RPC session.
  • Loading branch information
mehrdadh authored and xinetzone committed Nov 25, 2022
1 parent 4780645 commit 9123d08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions python/tvm/micro/project_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,17 @@ def __init__(

@property
def is_shutdown(self):
return self.read_file is None
return self.read_file.closed

def shutdown(self):
if self.is_shutdown:
if self.is_shutdown: # pylint: disable=using-constant-test
return

self.read_file.close()
self.write_file.close()

def _request_reply(self, method, params):
if self.is_shutdown:
if self.is_shutdown: # pylint: disable=using-constant-test
raise ConnectionShutdownError("connection already closed")

request = {
Expand Down
2 changes: 2 additions & 0 deletions python/tvm/micro/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
if not self._exit_called:
self._exit_called = True
self.transport.__exit__(exc_type, exc_value, exc_traceback)
shutdown_func = self._rpc._sess.get_function("CloseRPCConnection")
shutdown_func()

def _cleanup(self):
self.__exit__(None, None, None)
Expand Down

0 comments on commit 9123d08

Please sign in to comment.