areusch commented on a change in pull request #8715:
URL: https://github.com/apache/tvm/pull/8715#discussion_r686999819
##########
File path: apps/microtvm/pyproject.toml
##########
@@ -111,6 +111,8 @@ tensorflow-estimator = {version = "^2.1", optional = true}
# TFLite frontend
tflite = {version = "2.1.0", optional = true}
wheel = "*"
+cloudpickle = "^1.6.0"
Review comment:
are these needed still?
##########
File path: python/tvm/micro/build.py
##########
@@ -57,3 +61,56 @@ def get_standalone_crt_dir() -> str:
raise CrtNotFoundError()
return STANDALONE_CRT_DIR
+
+
+def autotvm_module_loader(
+ template_project_dir: str,
+ project_options: dict = None,
+):
+ """Configure a new adapter.
+
+ Parameters
+ ----------
+ template_project_dir: str
+ Path to the template project directory on the runner.
+
+ project_options : dict
+ Opt
+ compiler options specific to this build.
+
+ workspace_kw : Optional[dict]
+ Keyword args passed to the Workspace constructor.
+ """
+ if isinstance(template_project_dir, pathlib.Path):
+ template_project_dir = str(template_project_dir)
+ elif not isinstance(template_project_dir, str):
+ raise TypeError(f"Incorrect type {type(template_project_dir)}.")
+
+ @contextlib.contextmanager
+ def module_loader(remote_kw, build_result):
+ with open(build_result.filename, "rb") as build_file:
+ build_result_bin = build_file.read()
+
+ tracker = _rpc.connect_tracker(remote_kw["host"], remote_kw["port"])
+ remote = tracker.request(
+ remote_kw["device_key"],
+ priority=remote_kw["priority"],
+ session_timeout=remote_kw["timeout"],
+ session_constructor_args=[
+ "tvm.micro.compile_and_create_micro_session",
+ build_result_bin,
+ template_project_dir,
+ json.dumps(project_options),
+ ],
+ )
+ system_lib = remote.get_function("runtime.SystemLib")()
+ yield remote, system_lib
+
+ return module_loader
+
+
+def autotvm_build_func():
Review comment:
could you document this is a dummy build function which causes autotvm
to use a different export format?
##########
File path: python/tvm/autotvm/measure/measure.py
##########
@@ -97,7 +112,17 @@ def set_task(self, task, build_kwargs=None):
The additional kwargs for build function
"""
self.task = task
- self.build_kwargs = build_kwargs
+ self.build_kwargs = build_kwargs if build_kwargs is not None else {}
Review comment:
can you create a copy of build_kwargs:
`self.build_kwargs = dict(build_kwargs.items()) if build_kwargs is not None
else {}`
##########
File path: python/tvm/micro/build.py
##########
@@ -57,3 +61,56 @@ def get_standalone_crt_dir() -> str:
raise CrtNotFoundError()
return STANDALONE_CRT_DIR
+
+
+def autotvm_module_loader(
+ template_project_dir: str,
+ project_options: dict = None,
+):
+ """Configure a new adapter.
+
+ Parameters
+ ----------
+ template_project_dir: str
+ Path to the template project directory on the runner.
+
+ project_options : dict
+ Opt
+ compiler options specific to this build.
+
+ workspace_kw : Optional[dict]
+ Keyword args passed to the Workspace constructor.
+ """
+ if isinstance(template_project_dir, pathlib.Path):
+ template_project_dir = str(template_project_dir)
+ elif not isinstance(template_project_dir, str):
+ raise TypeError(f"Incorrect type {type(template_project_dir)}.")
+
+ @contextlib.contextmanager
+ def module_loader(remote_kw, build_result):
+ with open(build_result.filename, "rb") as build_file:
+ build_result_bin = build_file.read()
+
+ tracker = _rpc.connect_tracker(remote_kw["host"], remote_kw["port"])
+ remote = tracker.request(
+ remote_kw["device_key"],
+ priority=remote_kw["priority"],
+ session_timeout=remote_kw["timeout"],
+ session_constructor_args=[
+ "tvm.micro.compile_and_create_micro_session",
+ build_result_bin,
+ template_project_dir,
+ json.dumps(project_options),
+ ],
+ )
+ system_lib = remote.get_function("runtime.SystemLib")()
+ yield remote, system_lib
+
+ return module_loader
+
+
+def autotvm_build_func():
+ pass
+
+
+autotvm_build_func.output_format = "tar.gz"
Review comment:
since this is a dummy, in retrospect let us use ".model-library-format"
here and comment that it is a sentinel value only.
##########
File path: python/tvm/micro/session.py
##########
@@ -234,3 +237,68 @@ def create_local_debug_executor(graph_json_str, mod,
device, dump_root=None):
graph_json_str,
dump_root=dump_root,
)
+
+
+RPC_SESSION = None
+
+
+@register_func("tvm.micro.compile_and_create_micro_session")
+def compile_and_create_micro_session(
+ mod_src_bytes: bytes,
+ template_project_dir: str,
+ project_options: dict = None,
+):
+ """Compile the given libraries and sources into a MicroBinary, then invoke
create_micro_session.
+
+ Parameters
+ ----------
+ mod_src_bytes : bytes
+ The content of a tarfile which contains the TVM-generated sources
which together form the
+ SystemLib. This tar is expected to be created by export_library. The
tar will be extracted
+ into a directory and the sources compiled into a MicroLibrary using
the Compiler.
+
+ template_project_dir: str
+ The path to a template microTVM Project API project which is used to
generate the embedded
+ project that is built and flashed onto the target device.
+
+ project_options: dict
+ Options for the microTVM API Server contained in template_project_dir.
+ """
+ global RPC_SESSION
+
+ temp_dir = utils.tempdir()
+ temp_dir.set_keep_for_debug(True)
+ model_library_format_path = temp_dir / "model.tar.gz"
+ with open(model_library_format_path, "wb") as mlf_f:
+ mlf_f.write(mod_src_bytes)
+
+ try:
+ template_project = project.TemplateProject.from_directory(
+ template_project_dir, options=json.loads(project_options)
+ )
+ generated_project = template_project.generate_project_from_mlf(
+ model_library_format_path, temp_dir / "generated-project"
+ )
+ except Exception as exception:
+ print("Project Generate Error", exception)
Review comment:
should we _LOG instead?
##########
File path: python/tvm/micro/session.py
##########
@@ -234,3 +237,68 @@ def create_local_debug_executor(graph_json_str, mod,
device, dump_root=None):
graph_json_str,
dump_root=dump_root,
)
+
+
+RPC_SESSION = None
+
+
+@register_func("tvm.micro.compile_and_create_micro_session")
+def compile_and_create_micro_session(
+ mod_src_bytes: bytes,
+ template_project_dir: str,
+ project_options: dict = None,
+):
+ """Compile the given libraries and sources into a MicroBinary, then invoke
create_micro_session.
+
+ Parameters
+ ----------
+ mod_src_bytes : bytes
+ The content of a tarfile which contains the TVM-generated sources
which together form the
+ SystemLib. This tar is expected to be created by export_library. The
tar will be extracted
+ into a directory and the sources compiled into a MicroLibrary using
the Compiler.
+
+ template_project_dir: str
+ The path to a template microTVM Project API project which is used to
generate the embedded
+ project that is built and flashed onto the target device.
+
+ project_options: dict
+ Options for the microTVM API Server contained in template_project_dir.
+ """
+ global RPC_SESSION
+
+ temp_dir = utils.tempdir()
+ temp_dir.set_keep_for_debug(True)
Review comment:
is this the part that's necessary? can you add comment?
--
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]