Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tvm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cld
ml
tvm
Commits
07cc21f1
Commit
07cc21f1
authored
7 years ago
by
Lianmin Zheng
Committed by
Tianqi Chen
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add exclusive mode for rpc server (#941)
parent
589a2651
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
python/tvm/contrib/rpc.py
+16
-5
16 additions, 5 deletions
python/tvm/contrib/rpc.py
python/tvm/exec/rpc_server.py
+4
-1
4 additions, 1 deletion
python/tvm/exec/rpc_server.py
with
20 additions
and
6 deletions
python/tvm/contrib/rpc.py
+
16
−
5
View file @
07cc21f1
...
...
@@ -74,10 +74,16 @@ def _recvall(sock, nbytes):
return
b
""
.
join
(
res
)
def
_listen_loop
(
sock
):
def
_listen_loop
(
sock
,
exclusive
):
"""
Lisenting loop
"""
last_proc
=
None
while
True
:
conn
,
addr
=
sock
.
accept
()
if
last_proc
and
last_proc
.
is_alive
()
and
exclusive
:
logging
.
info
(
"
Kill last call
"
)
last_proc
.
terminate
()
logging
.
info
(
"
RPCServer: connection from %s
"
,
addr
)
magic
=
struct
.
unpack
(
"
@i
"
,
_recvall
(
conn
,
4
))[
0
]
if
magic
!=
RPC_MAGIC
:
...
...
@@ -90,9 +96,11 @@ def _listen_loop(sock):
else
:
conn
.
sendall
(
struct
.
pack
(
"
@i
"
,
RPC_MAGIC
))
logging
.
info
(
"
Connection from %s
"
,
addr
)
process
=
multiprocessing
.
Process
(
target
=
_serve_loop
,
args
=
(
conn
,
addr
))
process
.
deamon
=
True
process
.
start
()
last_proc
=
process
# close from our side.
conn
.
close
()
...
...
@@ -158,6 +166,11 @@ class Server(object):
This is recommended to switch on if we want to do local RPC demonstration
for GPU devices to avoid fork safety issues.
exclusive : bool, optional
If this is enabled, the server will kill old connection
when new connection comes. This can make sure the current call
monopolize the hardware resource.
key : str, optional
The key used to identify the server in Proxy connection.
"""
...
...
@@ -167,6 +180,7 @@ class Server(object):
port_end
=
9199
,
is_proxy
=
False
,
use_popen
=
False
,
exclusive
=
False
,
key
=
""
):
self
.
host
=
host
self
.
port
=
port
...
...
@@ -201,7 +215,7 @@ class Server(object):
sock
.
listen
(
1
)
self
.
sock
=
sock
self
.
proc
=
multiprocessing
.
Process
(
target
=
_listen_loop
,
args
=
(
self
.
sock
,))
target
=
_listen_loop
,
args
=
(
self
.
sock
,
exclusive
))
self
.
proc
.
deamon
=
True
self
.
proc
.
start
()
else
:
...
...
@@ -210,8 +224,6 @@ class Server(object):
self
.
proc
.
deamon
=
True
self
.
proc
.
start
()
def
terminate
(
self
):
"""
Terminate the server process
"""
if
self
.
proc
:
...
...
@@ -222,7 +234,6 @@ class Server(object):
self
.
terminate
()
class
RPCSession
(
object
):
"""
RPC Client session module
...
...
This diff is collapsed.
Click to expand it.
python/tvm/exec/rpc_server.py
+
4
−
1
View file @
07cc21f1
...
...
@@ -21,6 +21,9 @@ def main():
help
=
"
Whether to load executor runtime
"
)
parser
.
add_argument
(
'
--load-library
'
,
type
=
str
,
default
=
""
,
help
=
"
Additional library to load
"
)
parser
.
add_argument
(
'
--exclusive
'
,
action
=
'
store_true
'
,
help
=
"
If this is enabled, the server will kill old connection
"
"
when new connection comes
"
)
args
=
parser
.
parse_args
()
logging
.
basicConfig
(
level
=
logging
.
INFO
)
...
...
@@ -35,7 +38,7 @@ def main():
libs
.
append
(
ctypes
.
CDLL
(
file_name
,
ctypes
.
RTLD_GLOBAL
))
logging
.
info
(
"
Load additional library %s
"
,
file_name
)
server
=
rpc
.
Server
(
args
.
host
,
args
.
port
,
args
.
port_end
)
server
=
rpc
.
Server
(
args
.
host
,
args
.
port
,
args
.
port_end
,
exclusive
=
args
.
exclusive
)
server
.
libs
+=
libs
server
.
proc
.
join
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment