[REFACTOR][RPC][PROCOTOL-CHANGE] Modularize the RPC infra (#5484)
authorTianqi Chen <tqchen@users.noreply.github.com>
Tue, 5 May 2020 00:05:33 +0000 (17:05 -0700)
committerGitHub <noreply@github.com>
Tue, 5 May 2020 00:05:33 +0000 (17:05 -0700)
commit95e06b3ec999da03e554cae7c81c257f3755fb41
tree53d12cbcc0349ab20e21b7e4d98a4ba220772341
parent7e88030a804357421b766d7309f9085ca2b83378
[REFACTOR][RPC][PROCOTOL-CHANGE] Modularize the RPC infra (#5484)

* Update dmlc-core which was mistakenly overriden

* [REFACTOR][RPC][PROCOTOL-CHANGE] Modularize the RPC infra.

This PR refactors the RPC protocol to make it more modularized.

- RPCSession: represent a set of features that need to be implemented
- RPCEndPont: End point that forwards the RPCSession requests over a communication channel.
- RPCModule: Exposes an RPCSession as an rpc device in the TVM Runtime API.

In the new design, the local machine is presented as a special case of RPCSession.
The remote is just another client session that calls into RPCEndPoint.
The RPC communication path is as follows.

```
client -> ClientSession -> EndPoint[client@n0]
-> networking[between n0 <=> n1]
-> EndPoint[server@n1] -> LocalSession[@n1]

```

Because of the new modular design, we can now chain more sessions together.
For example, we can now run the following proxy setup (testcase in test_runtime_rpc.test_session_constructor).

```
client -> ClientSession -> Endpoint[client@n0]
-> networking[between n0 <=> n1]
-> Endpoint[server@n1] -> ClientSession -> Endpoint[client@n1]
-> networking[between n1 <=> n2]
-> Endpoint[server@n2] -> LocalSession[@n2]
```

We can also implement other types of Sessions.
As an example, We introduced a PopenSession that communicates with
the another process via a pipe.

We also add more comments about the internal of the RPC.
The communication protocol is simplfied using a similar convention as PackedFunc.
This allows us to further reduce the amount of special remote syscalls.

Due to the major improvement and simplification, we are making a non-compatible update to the RPC protocol.
It means that the client and server needs to be upgraded to together in order for it to function correctly.

This PR also introduces a versioning mechanism to the current RPC procotol,
so that future upgrade will be produce more user friendly with error messages.

* Address review comments

* Remove ld library path
47 files changed:
.gitignore
3rdparty/dmlc-core
apps/cpp_rpc/rpc_server.cc
apps/cpp_rpc/rpc_tracker_client.h
include/tvm/runtime/c_runtime_api.h
include/tvm/runtime/device_api.h
jvm/core/src/main/java/org/apache/tvm/contrib/GraphRuntime.java
jvm/core/src/main/java/org/apache/tvm/rpc/Client.java
jvm/core/src/main/java/org/apache/tvm/rpc/NativeServerLoop.java
jvm/core/src/main/java/org/apache/tvm/rpc/RPCSession.java
python/tvm/_ffi/_ctypes/packed_func.py
python/tvm/_ffi/_cython/packed_func.pxi
python/tvm/_ffi/base.py
python/tvm/contrib/cc.py
python/tvm/contrib/graph_runtime.py
python/tvm/error.py
python/tvm/rpc/__init__.py
python/tvm/rpc/_ffi_api.py [new file with mode: 0644]
python/tvm/rpc/base.py
python/tvm/rpc/client.py
python/tvm/rpc/minrpc.py [new file with mode: 0644]
python/tvm/rpc/proxy.py
python/tvm/rpc/server.py
python/tvm/runtime/module.py
src/runtime/c_runtime_api.cc
src/runtime/module.cc
src/runtime/registry.cc
src/runtime/rpc/minrpc/minrpc_server.h [new file with mode: 0644]
src/runtime/rpc/minrpc/posix_popen_server.cc [new file with mode: 0644]
src/runtime/rpc/rpc_channel.cc [new file with mode: 0644]
src/runtime/rpc/rpc_channel.h [new file with mode: 0644]
src/runtime/rpc/rpc_device_api.cc
src/runtime/rpc/rpc_endpoint.cc [new file with mode: 0644]
src/runtime/rpc/rpc_endpoint.h [new file with mode: 0644]
src/runtime/rpc/rpc_event_impl.cc
src/runtime/rpc/rpc_local_session.cc [new file with mode: 0644]
src/runtime/rpc/rpc_local_session.h [new file with mode: 0644]
src/runtime/rpc/rpc_module.cc
src/runtime/rpc/rpc_pipe_impl.cc [new file with mode: 0644]
src/runtime/rpc/rpc_protocol.h [new file with mode: 0644]
src/runtime/rpc/rpc_server_env.cc
src/runtime/rpc/rpc_session.cc
src/runtime/rpc/rpc_session.h
src/runtime/rpc/rpc_socket_impl.cc
src/support/arena.h
tests/python/unittest/test_runtime_rpc.py
web/tvm_runtime.js