areusch commented on a change in pull request #9229:
URL: https://github.com/apache/tvm/pull/9229#discussion_r737938422
##########
File path: python/tvm/driver/tvmc/runner.py
##########
@@ -384,13 +482,27 @@ def run_module(
else:
logger.debug("Running on remote RPC with no key.")
session = rpc.connect(hostname, port)
+ elif device == "micro":
+ # Remote RPC (running on a micro target)
+ logger.debug("Running on remote RPC (micro target).")
+ try:
+ with ExitStack() as stack:
Review comment:
the ExitStack still only calls `__exit__` when leaving a `with` block
(or technically, when _its_ `__exit__` is called). to make this approach work,
can you move this line above 475 (so that the entire body of `run_module` past
that line is indented inside the with block)? then, calling `enter_session`
here will cause `__exit__` to be invoked when the function returns.
##########
File path: python/tvm/driver/tvmc/runner.py
##########
@@ -97,7 +110,57 @@ def add_run_parser(subparsers):
help="hostname (required) and port (optional, defaults to 9090) of the
RPC tracker, "
"e.g. '192.168.0.100:9999'",
)
- parser.add_argument("FILE", help="path to the compiled module file")
+ parser.add_argument(
+ "PATH",
+ help="path to the compiled module file or to the project directory
(micro devices only).",
+ )
+
+ #
+ # Hack to lookahead if 'run' was selected and make
+ # two dynamic parsers (in micro.py and in runner.py) work.
+ #
+ # print(sys.argv)
Review comment:
nit: rm
##########
File path: python/tvm/driver/tvmc/runner.py
##########
@@ -404,16 +513,24 @@ def run_module(
dev = session.vulkan()
elif device == "rocm":
dev = session.rocm()
+ elif device == "micro":
+ dev = session.device
+ lib = session.get_system_lib()
else:
assert device == "cpu"
dev = session.cpu()
+ # TODO(gromero): Adjust for micro targets.
Review comment:
i think this means that benchmark doesn't work with remote devices. i'd
suggest we mark benchmarking as unsupported with micro devices and merge this
PR rather than try to make benchmarking support remote devices.
##########
File path: python/tvm/driver/tvmc/runner.py
##########
@@ -97,7 +111,55 @@ def add_run_parser(subparsers):
help="hostname (required) and port (optional, defaults to 9090) of the
RPC tracker, "
"e.g. '192.168.0.100:9999'",
)
- parser.add_argument("FILE", help="path to the compiled module file")
+ parser.add_argument(
+ "PATH",
+ help="path to the compiled module file or to the project directory
(micro devices only).",
+ )
+
+ #
+ # Hack to lookahead if 'run' was selected and make
+ # two dynamic parsers (in micro.py and in runner.py) work.
+ #
+ # print(sys.argv)
+ if "run" in sys.argv:
Review comment:
er i meant like this on the invert thing.
```
if "run" not in sys.argv:
return
known_args, _ = main_parser.parse_known_args()
```
on the question about detecting "run", not sure i quite follow--let's chat
further offline.
##########
File path: python/tvm/micro/project_api/server.py
##########
@@ -42,15 +42,24 @@
_LOG = logging.getLogger(__name__)
-_ProjectOption = collections.namedtuple("ProjectOption", ("name", "choices",
"help"))
+_ProjectOption = collections.namedtuple(
+ "ProjectOption", ("name", "choices", "default", "type", "required",
"optional", "help")
+)
class ProjectOption(_ProjectOption):
+ """Class used to keep the metadata associated to project options."""
+
def __new__(cls, name, **kw):
"""Override __new__ to force all options except name to be specified
as kwargs."""
assert "name" not in kw
+ assert "required" in kw or "optional" in kw, "'required' or 'optional'
must be specified."
Review comment:
suggest "at least one of 'required' or 'optional' must be specified."
##########
File path: apps/microtvm/zephyr/template_project/microtvm_api_server.py
##########
@@ -229,40 +229,69 @@ def _get_nrf_device_args(options):
PROJECT_OPTIONS = [
server.ProjectOption(
"extra_files_tar",
+ optional=["generate_project"],
+ type="str",
Review comment:
oh i see. sorry about that, this does make sense then.
##########
File path: python/tvm/driver/tvmc/runner.py
##########
@@ -404,16 +513,24 @@ def run_module(
dev = session.vulkan()
elif device == "rocm":
dev = session.rocm()
+ elif device == "micro":
+ dev = session.device
+ lib = session.get_system_lib()
else:
assert device == "cpu"
dev = session.cpu()
+ # TODO(gromero): Adjust for micro targets.
Review comment:
ah yeah adding to device_api.h isn't going to fix this. the 129 part is
a bit confusing--it's actually 1 | (1 << 8) == 1 | 128. 128 is a mask
indicating the device is a remote device.
##########
File path: src/runtime/rpc/rpc_module.cc
##########
@@ -164,7 +164,7 @@ class RPCModuleNode final : public ModuleNode {
~RPCModuleNode() {
if (module_handle_ != nullptr) {
try {
- sess_->FreeHandle(module_handle_, kTVMModuleHandle);
+ // sess_->FreeHandle(module_handle_, kTVMModuleHandle);
Review comment:
i see. can you try modifying
[TVMModFree](https://github.com/apache/tvm/blob/main/src/runtime/crt/common/crt_runtime_api.c#L186)
to be a no-op when `mod == system_lib_handle` (and `system_lib_handle` is not
`kTVMModuleHandleUninitialized`)? this may fix your problem. it may also be
that we need to reset the board between run calls...but we could try to see if
this works first.
##########
File path: python/tvm/micro/project.py
##########
@@ -75,14 +75,23 @@ def __init__(self, api_client, options):
raise TemplateProjectError()
def build(self):
+ assert self._options is not None, "'options' is not set!"
self._api_client.build(self._options)
def flash(self):
+ assert self._options is not None, "'options' is not set!"
self._api_client.flash(self._options)
def transport(self):
+ assert self._options is not None, "'options' is not set!"
return ProjectTransport(self._api_client, self._options)
+ def info(self):
+ return self._info
+
+ def set_options(self, options):
Review comment:
can you use a python
[setter](https://python-reference.readthedocs.io/en/latest/docs/property/setter.html)
or just make options e.g. `self.options`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]