areusch commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r959999034


##########
python/tvm/micro/session.py:
##########
@@ -259,6 +259,8 @@ def compile_and_create_micro_session(
     mod_src_bytes: bytes,
     template_project_dir: str,
     project_options: dict = None,
+    build_dir: str = None,
+    debug: bool = False,

Review Comment:
   could we use a more descriptive parameter name? e.g. `reuse_project` or 
`generate_project: bool = True`? alternatively, could derive this from 
`build_dir` (e.g. if it already exists, don't regenerate); but that could be 
troublesome if we want to assert a workflow actually generates a project too.



##########
python/tvm/micro/session.py:
##########
@@ -275,27 +277,45 @@ def compile_and_create_micro_session(
 
     project_options: dict
         Options for the microTVM API Server contained in template_project_dir.
-    """
 
-    temp_dir = utils.tempdir()
-    # Keep temp directory for generate project
-    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)
+    build_dir: str
+        if debug is False: The path to save the generated microTVM Project.
+        if debug is True: The path to a generated microTVM Project for 
debugging.
 
-    try:
-        template_project = 
project.TemplateProject.from_directory(template_project_dir)
-        generated_project = template_project.generate_project_from_mlf(
-            model_library_format_path,
-            str(temp_dir / "generated-project"),
+    debug: bool
+        skips the project generation and opens transport to the project at the 
project_dir address.
+    """
+
+    if debug:
+        project_dir = Path(build_dir)
+        assert Path(build_dir).is_dir(), f"{build_dir} does not exist."
+        generated_project = project.GeneratedProject.from_directory(
+            str(project_dir / "generated-project"),
             options=json.loads(project_options),
         )
-    except Exception as exception:
-        logging.error("Project Generate Error: %s", str(exception))
-        raise exception
+    else:
+        if build_dir:
+            temp_dir = utils.tempdir(custom_path=build_dir, 
keep_for_debug=True)
+        else:
+            temp_dir = utils.tempdir()
+
+        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)
+            generated_project = template_project.generate_project_from_mlf(
+                model_library_format_path,
+                str(temp_dir / "generated-project"),
+                options=json.loads(project_options),
+            )
+        except Exception as exception:
+            logging.error("Project Generate Error: %s", str(exception))
+            raise exception
+
+        generated_project.build()

Review Comment:
   should we still rebuild if we're going to flash? i mean, maybe not..just 
wondering some rationale here.



##########
python/tvm/micro/testing/evaluation.py:
##########
@@ -124,21 +124,32 @@ def create_aot_session(
     parameter_size = len(tvm.runtime.save_param_dict(lowered.get_params()))
     print(f"Model parameter size: {parameter_size}")
 
-    project = tvm.micro.generate_project(
-        str(tvm.micro.get_microtvm_template_projects(platform)),
-        lowered,
-        build_dir / "project",
-        {
-            f"{platform}_board": board,
-            "project_type": "host_driven",
-            # {} shouldn't be the default value for project options ({}
-            # is mutable), so we use this workaround
-            **(project_options or {}),
-        },
-    )
-    project.build()
-    project.flash()
+    if debug:
+        project = tvm.micro.GeneratedProject.from_directory(
+            str(build_dir / "project"),
+            options={
+                f"{platform}_board": board,
+                "project_type": "host_driven",
+                **(project_options or {}),
+            },
+        )
 
+    else:
+        project = tvm.micro.generate_project(
+            str(tvm.micro.get_microtvm_template_projects(platform)),
+            lowered,
+            build_dir / "project",
+            {
+                f"{platform}_board": board,
+                "project_type": "host_driven",
+                # {} shouldn't be the default value for project options ({}
+                # is mutable), so we use this workaround
+                **(project_options or {}),
+            },
+        )
+        project.build()

Review Comment:
   same question here



-- 
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]

Reply via email to