-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[EXECUTOR] Enable load executor remotely #245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
edeafb5
[EXECUTOR] Enable load executor remotely
ZihengJiang 6a831a4
[EXECUTOR] Pipeline
ZihengJiang d59cd75
Pass bytearray directly
ZihengJiang c2b6373
Enable load dynamic library in rpc_server.py
ZihengJiang 59f130c
Fix
ZihengJiang f91d392
lint
ZihengJiang 25654a3
Merge branch 'master' into dev
ZihengJiang f8835c1
Return Module from remote side directly
ZihengJiang 274a76e
Merge branch 'master' into dev
ZihengJiang e5e54ca
Remove unused header file
ZihengJiang 9b9e3f4
Fix
ZihengJiang 068f2b6
fix
ZihengJiang 020a456
Merge branch 'master' into dev
ZihengJiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import tvm | ||
| from tvm.contrib import util, rpc | ||
| import tvm_graph as tg | ||
| import numpy as np | ||
| import os | ||
|
|
||
| def test_rpc_executor(): | ||
| host = 'localhost' | ||
| port = 9090 | ||
| server = rpc.Server(host, port) | ||
|
|
||
| tmp = util.tempdir() | ||
| sym_fname = tmp.relpath('net.json') | ||
| lib_fname = tmp.relpath('net.o') | ||
| param_fname = tmp.relpath('net.param') | ||
|
|
||
| x = tg.Variable('x') | ||
| y = tg.Variable('y') | ||
| sym = tg.exp(y + x) | ||
|
|
||
| shape = (10, 128) | ||
| dtype = tvm.float32 | ||
| na = tvm.nd.array(np.ones(shape).astype(dtype)) | ||
| nb = tvm.nd.array(np.ones(shape).astype(dtype)) | ||
| tg.save_params(param_fname, {'x': na, 'y': nb}) | ||
|
|
||
| target = "llvm" | ||
| shapes = {'x': shape, 'y': shape} | ||
| tg.compile_graph(sym_fname, lib_fname, param_fname, | ||
| sym, target, shapes) | ||
|
|
||
| remote = rpc.connect(host, port) | ||
| ctx = remote.cpu(0) | ||
|
|
||
| remote.upload(lib_fname) | ||
| rm = remote.load_executor(sym_fname, os.path.basename(lib_fname), | ||
| param_fname, ctx) | ||
| run, get_output = rm['run'], rm['get_output'] | ||
|
|
||
| nc = tvm.nd.array(np.zeros(shape, dtype=dtype), ctx) | ||
| run() | ||
| get_output(0, nc) | ||
|
|
||
| np.testing.assert_allclose( | ||
| nc.asnumpy(), np.exp(na.asnumpy() + nb.asnumpy())) | ||
| server.terminate() | ||
|
|
||
| if __name__ == "__main__": | ||
| test_rpc_executor() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,18 +3,57 @@ | |
|
|
||
| import logging | ||
| import argparse | ||
| import os | ||
| import ctypes | ||
| from ..contrib import rpc | ||
|
|
||
| def find_lib_path(name): | ||
|
||
| """Find dynamic library.""" | ||
| curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__))) | ||
| base_path = os.path.join(curr_path, "../../../") | ||
| apps_path = os.path.join(base_path, "apps/graph_executor/lib/") | ||
| api_path = os.path.join(base_path, 'lib/') | ||
| cmake_build_path = os.path.join(base_path, 'build/Release/') | ||
| dll_path = [curr_path, base_path, apps_path, api_path, cmake_build_path] | ||
| if os.name == 'nt': | ||
| vs_configuration = 'Release' | ||
| if platform.architecture()[0] == '64bit': | ||
| dll_path.append(os.path.join(base_path, 'build', vs_configuration)) | ||
| dll_path.append(os.path.join(base_path, 'windows/x64', vs_configuration)) | ||
| else: | ||
| dll_path.append(os.path.join(base_path, 'build', vs_configuration)) | ||
| dll_path.append(os.path.join(base_path, 'windows', vs_configuration)) | ||
| elif os.name == "posix" and os.environ.get('LD_LIBRARY_PATH', None): | ||
| dll_path.extend([p.strip() for p in os.environ['LD_LIBRARY_PATH'].split(":")]) | ||
| dll_path = [os.path.abspath(x) for x in dll_path] | ||
| lib_dll_path = [os.path.join(p, name) for p in dll_path] | ||
|
|
||
| # try to find lib_dll_path | ||
| lib_found = [p for p in lib_dll_path if os.path.exists(p) and os.path.isfile(p)] | ||
| if not lib_found: | ||
| raise RuntimeError('Cannot find the files.\n' + | ||
| 'List of candidates:\n' + | ||
| str('\n'.join(lib_dll_path))) | ||
| return lib_found | ||
|
|
||
|
|
||
| def main(): | ||
| """Main funciton""" | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument('--host', type=str, default="0.0.0.0", | ||
| help='the hostname of the server') | ||
| parser.add_argument('--port', type=int, default=9090, | ||
| help='The port of the PRC') | ||
| parser.add_argument('--port_end', type=int, default=9199, | ||
| parser.add_argument('--port-end', type=int, default=9199, | ||
| help='The end search port of the PRC') | ||
| parser.add_argument('--with-executor', type=bool, default=False, | ||
| help="Whether to load executor runtime") | ||
| args = parser.parse_args() | ||
|
|
||
| if args.with_executor: | ||
| lib_path = find_lib_path('libtvm_graph_exec.so') | ||
| ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL) | ||
|
|
||
| logging.basicConfig(level=logging.INFO) | ||
| server = rpc.Server(args.host, args.port, args.port_end) | ||
| server.proc.join() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this in c_runtime_api.cc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just put this here is fine