-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[microTVM] add the option to open a saved micro project for debugging #12495
Conversation
f0da470
to
25c8e77
Compare
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.
thanks @mkatanbaf ! cc @mehrdadh @guberti
python/tvm/micro/session.py
Outdated
@@ -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, |
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.
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.
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.
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.
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.
I like reuse_project
or use_existing
. I also agree that deriving this property from build_dir
would cause confusion.
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.
I used use_existing
. Thanks @guberti for the suggestion.
python/tvm/micro/session.py
Outdated
logging.error("Project Generate Error: %s", str(exception)) | ||
raise exception | ||
|
||
generated_project.build() |
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.
should we still rebuild if we're going to flash? i mean, maybe not..just wondering some rationale here.
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.
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.
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.
I checked and the west flash
command rebuilds the project if needed.
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.
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.
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.
I changed it to clear the existing build
dir, and rebuild before flashing.
**(project_options or {}), | ||
}, | ||
) | ||
project.build() |
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.
same question here
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.
LGTM, just a few nits. I don't have a strong opinion on whether we should rebuild existing projects before flashing - either seems reasonable to me (though I think we would have to remove the existing build
dir if we rebuild)
After thinking about it more, I think one of the most common use cases for this feature will be letting folks make manual changes to the generated C++ code, and then evaluating how performance changes. Since calls to this utility will usually be accompanied by code changes, I think rebuilding explicitly by calling project.build()
makes sense.
python/tvm/micro/session.py
Outdated
@@ -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, |
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.
I like reuse_project
or use_existing
. I also agree that deriving this property from build_dir
would cause confusion.
{ | ||
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 {}), |
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.
Can we store these in a variable (e.g. project_options
) so this code isn't duplicated between the if
and else
statements?
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.
done
python/tvm/micro/build.py
Outdated
self, | ||
template_project_dir: Union[pathlib.Path, str], | ||
project_options: dict = None, | ||
build_dir: str = None, |
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.
Can we give build_dir
a path-like object type instead of just str
? i.e. Union[os.PathLike, str]
?
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.
done
6c6af0f
to
32a652a
Compare
@guberti can you have another look? |
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.
Two small comments, but this still looks good.
python/tvm/micro/build.py
Outdated
template_project_dir: Union[pathlib.Path, str], | ||
project_options: dict = None, | ||
project_dir: Union[pathlib.Path, str] = None, |
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.
Nit: the Python docs suggest using os.PathLike
for typechecking, which is the abstract base class for pathlib.Path
.
template_project_dir: Union[pathlib.Path, str], | |
project_options: dict = None, | |
project_dir: Union[pathlib.Path, str] = None, | |
template_project_dir: Union[os.PathLike, str], | |
project_options: dict = None, | |
project_dir: Union[os.PathLike, str] = None, |
python/tvm/micro/session.py
Outdated
|
||
if use_existing: | ||
project_dir = pathlib.Path(project_dir) | ||
assert pathlib.Path(project_dir).is_dir(), f"{project_dir} does not exist." |
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.
No need to call pathlib.Path
twice.
assert pathlib.Path(project_dir).is_dir(), f"{project_dir} does not exist." | |
assert project_dir.is_dir(), f"{project_dir} does not exist." |
@tvm-bot rerun |
1 similar comment
@tvm-bot rerun |
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.
LGTM - thanks for the fix!
@tvm-bot rerun |
1b75133
to
9ccdd30
Compare
@areusch could you take another look please? |
@tvm-bot rerun |
…apache#12495) * add the option to open a saved project for debugging. * addressing comments Co-authored-by: Mohamad <mkatanbaf@users.noreply.github.com>
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.
cc @alanmacd @areusch @gromero @guberti @mehrdadh