You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/08/18 22:45:06 UTC

[GitHub] [tvm] mkatanbaf opened a new pull request, #12495: [microTVM] add the option to open a saved project for debugging

mkatanbaf opened a new pull request, #12495:
URL: https://github.com/apache/tvm/pull/12495

   This PR adds the option to save a generated micro project at a custom path, and to open a saved project and start communicating with it (instead of generating a new one) for debugging.
   


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r960032709


##########
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:
   based on what I've seen the `flash` step rebuilds the project if needed. The `build` step creates the build dir for the first time and I believe it generates an error if the build dir already exists. I'll double check.



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1244986090

   @tvm-bot rerun


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961433765


##########
python/tvm/micro/build.py:
##########
@@ -123,9 +123,15 @@ class AutoTvmModuleLoader:
     """
 
     def __init__(
-        self, template_project_dir: Union[pathlib.Path, str], project_options: dict = None
+        self,
+        template_project_dir: Union[pathlib.Path, str],
+        project_options: dict = None,
+        build_dir: str = None,

Review Comment:
   done



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961899832


##########
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:
   I changed it to clear the existing `build` dir, and rebuild before flashing.



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961433712


##########
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 {}),

Review Comment:
   done



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] areusch merged pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
areusch merged PR #12495:
URL: https://github.com/apache/tvm/pull/12495


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r960032709


##########
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:
   based on what I've seen the flash step rebuilds the project if needed. The build step creates the build dir for the first time and I believe it generates an error if the build dir already exists. I'll double check.



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] guberti commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
guberti commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r966087664


##########
python/tvm/micro/session.py:
##########
@@ -275,25 +279,44 @@ 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)
+    project_dir: str
+        if use_existing is False: The path to save the generated microTVM Project.
+        if use_existing 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"),
+    use_existing: bool
+        skips the project generation and opens transport to the project at the project_dir address.
+    """
+
+    if use_existing:
+        project_dir = pathlib.Path(project_dir)
+        assert pathlib.Path(project_dir).is_dir(), f"{project_dir} does not exist."

Review Comment:
   No need to call `pathlib.Path` twice.
   ```suggestion
           assert project_dir.is_dir(), f"{project_dir} does not exist."
   ```



##########
python/tvm/micro/build.py:
##########
@@ -120,18 +120,35 @@ class AutoTvmModuleLoader:
 
     project_options : dict
         project generation option
+
+    project_dir: str
+        if use_existing is False: The path to save the generated microTVM Project.
+        if use_existing is True: The path to a generated microTVM Project for debugging.
+
+    use_existing: bool
+        skips the project generation and opens transport to the project at the project_dir address.
     """
 
     def __init__(
-        self, template_project_dir: Union[pathlib.Path, str], project_options: dict = None
+        self,
+        template_project_dir: Union[pathlib.Path, str],
+        project_options: dict = None,
+        project_dir: Union[pathlib.Path, str] = None,

Review Comment:
   Nit: the [Python docs](https://docs.python.org/3/library/os.html#os.PathLike) suggest using `os.PathLike` for typechecking, which is the abstract base class for `pathlib.Path`.
   ```suggestion
           template_project_dir: Union[os.PathLike, str],
           project_options: dict = None,
           project_dir: Union[os.PathLike, str] = None,
   ```



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1247347250

   @tvm-bot rerun


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] guberti commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
guberti commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961499633


##########
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:
   I do not believe the Arduino implementation does this - how do we want to handle that? IMO the cleanest/easiest solution is to always rebuild before flashing.



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] guberti commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
guberti commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961499633


##########
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:
   I do not believe the Arduino implementation does this - how do we want to handle that?



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1244525262

   @tvm-bot rerun


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] areusch commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961432778


##########
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:
   I checked and the `west flash` command rebuilds the project if needed.



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1245873861

   @tvm-bot rerun


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1244752028

   @tvm-bot rerun


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] guberti commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
guberti commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961294102


##########
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:
   I like `reuse_project` or `use_existing`. I also agree that deriving this property from `build_dir` would cause confusion.



##########
python/tvm/micro/build.py:
##########
@@ -123,9 +123,15 @@ class AutoTvmModuleLoader:
     """
 
     def __init__(
-        self, template_project_dir: Union[pathlib.Path, str], project_options: dict = None
+        self,
+        template_project_dir: Union[pathlib.Path, str],
+        project_options: dict = None,
+        build_dir: str = None,

Review Comment:
   Can we give `build_dir` a path-like object type instead of just `str`? i.e. `Union[os.PathLike, str]`?



##########
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 {}),

Review Comment:
   Can we store these in a variable (e.g. `project_options`) so this code isn't duplicated between the `if` and `else` statements?



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1254051966

   @areusch could you take another look please?


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r960030128


##########
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:
   how about `skip_project_generation: bool = False`? yes, we can drive it from `build_dir` but I think that might cause some confusion and it's better to explicitly express it when we would like to skip project generation.



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12495:
URL: https://github.com/apache/tvm/pull/12495#discussion_r961432059


##########
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:
   I used `use_existing`. Thanks @guberti for the suggestion.



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1258367564

   @tvm-bot rerun


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] areusch commented on pull request #12495: [microTVM] add the option to open a saved micro project for debugging

Posted by GitBox <gi...@apache.org>.
areusch commented on PR #12495:
URL: https://github.com/apache/tvm/pull/12495#issuecomment-1239811697

   @guberti can you have another look?


-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org