-
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][Zephyr] Add 'serial_number' option #13377
[microTVM][Zephyr] Add 'serial_number' option #13377
Conversation
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment. Generated by tvm-bot |
f47a3f1
to
f6b907e
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.
@mehrdadh Hi.
I'm still reviewing it, but when testing this PR I've realized that since commit 2252f958f75c6e33b946d23f1ebb803d41f0b63d
(#11362) the CMSIS_PATH, although marked as optional, is actually required: either as env. var or passed as a server option. Due to portability, I'd rather like to not force users to have CMSIS-NN installed to use microTVM. Could it be fixed ?
So far iirc only new options were added to the server, but this PR will change an existing option, zephyr_board
, to board
. This will break previous command line uses passing zephyr_board
, do you know if we have any policy about it? I roughly seems an API breakage.
|
||
extra_files_tar = options.get("extra_files_tar") | ||
|
||
cmsis_path = get_cmsis_path(options) |
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.
Here, although cmsis_path
is declared as optional, it's actually required, so on an env, without CMSIS installed I get:
$ tvmc micro create-project --force /tmp/micro_speech ~/scripts/micro_speech.tar zephyr --project-option board=nrf5340dk_nrf5340_cpuapp project_type=host_driven
WARNING:__main__:Board memory information is not available.
The following error occurred on the Project API server side:
calling method generate_project: JSON-RPC error # -32000: calling method generate_project
Traceback (most recent call last):
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 486, in serve_one_request # <--- Outermost server-side stack frame
self._dispatch_request(request)
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 598, in _dispatch_request
return_value = dispatch_method(**params)
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 630, in _dispatch_generate_project
options,
File "/home/gromero/git/tvm/build/microtvm_template_projects/zephyr/microtvm_api_server.py", line 564, in generate_project
cmsis_path = get_cmsis_path(options)
File "/home/gromero/git/tvm/build/microtvm_template_projects/zephyr/microtvm_api_server.py", line 382, in get_cmsis_path
cmsis_path = options.get("cmsis_path", os.environ["CMSIS_PATH"])
File "/usr/lib/python3.6/os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'CMSIS_PATH
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.
This is a bug, I fixed it.
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.
Now getting this exception since pathlib.Path()
is not expecting a None
type:
$ tvmc micro create-project --force /tmp/micro_speech ~/scripts/micro_speech.tar zephyr --project-option board=nrf5340dk_nrf5340_cpuapp project_type=host_driven
WARNING:__main__:Board memory information is not available.
The following error occurred on the Project API server side:
calling method generate_project: JSON-RPC error # -32000: calling method generate_project
Traceback (most recent call last):
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 486, in serve_one_request # <--- Outermost server-side stack frame
self._dispatch_request(request)
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 598, in _dispatch_request
return_value = dispatch_method(**params)
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 630, in _dispatch_generate_project
options,
File "/home/gromero/git/tvm/build/microtvm_template_projects/zephyr/microtvm_api_server.py", line 564, in generate_project
cmsis_path = get_cmsis_path(options)
File "/home/gromero/git/tvm/build/microtvm_template_projects/zephyr/microtvm_api_server.py", line 383, in get_cmsis_path
return pathlib.Path(cmsis_path)
File "/usr/lib/python3.6/pathlib.py", line 1001, in __new__
self = cls._from_parts(args, init=False)
File "/usr/lib/python3.6/pathlib.py", line 656, in _from_parts
drv, root, parts = self._parse_args(args)
File "/usr/lib/python3.6/pathlib.py", line 640, in _parse_args
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
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.
Fixed this, I added a test to build without this options/environment variable to protect this.
@gromero the change from |
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 this PR, and I've left a few small nits. However, I can't seem to get your branch working locally. I'm running:
python -m pytest -s tests/micro/zephyr/test_zephyr.py::test_add_uint --board nucleo_l4r5zi
and I get:
E tvm.micro.project_api.server.ServerError: calling method flash: JSON-RPC error # -32000: calling method flash
E Traceback (most recent call last):
E File "/home/guberti/tvm/python/tvm/micro/project_api/server.py", line 486, in serve_one_request # <--- Outermost server-side stack frame
E self._dispatch_request(request)
E File "/home/guberti/tvm/python/tvm/micro/project_api/server.py", line 598, in _dispatch_request
E return_value = dispatch_method(**params)
E File "/home/guberti/tvm/tests/micro/zephyr/workspace_nucleo_l4r5zi/2022-11-18T02-28-22/project/microtvm_api_server.py", line 765, in flash
E check_call(
E File "/home/guberti/tvm/tests/micro/zephyr/workspace_nucleo_l4r5zi/2022-11-18T02-28-22/project/microtvm_api_server.py", line 90, in check_call
E return subprocess.check_call(cmd_args, *args, **kwargs)
E File "/usr/lib/python3.8/subprocess.py", line 359, in check_call
E retcode = call(*popenargs, **kwargs)
E File "/usr/lib/python3.8/subprocess.py", line 340, in call
E with Popen(*popenargs, **kwargs) as p:
E File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
E self._execute_child(args, executable, preexec_fn, close_fds,
E File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
E raise child_exception_type(errno_num, err_msg, err_filename)
E FileNotFoundError: [Errno 2] No such file or directory: '/usr/bin/python -m west'
python/tvm/micro/project_api/client.py:135: ServerError
It seems like check_call
is being passed the arguments ['/usr/bin/python -m west', 'flash', '-r', 'openocd']
, and subprocess
assumes that '/usr/bin/python -m west'
is one str
argument and surrounds it with quotes. Maybe this is a bug, or maybe I'm using it wrong?
CMSIS_PATH_ERROR = ( | ||
"cmsis_path is not defined! Please pass it as" | ||
"an option or provide it with setting `CMSIS_PATH` env variable." | ||
) |
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.
CMSIS_PATH_ERROR = ( | |
"cmsis_path is not defined! Please pass it as" | |
"an option or provide it with setting `CMSIS_PATH` env variable." | |
) | |
CMSIS_PATH_ERROR = ( | |
"cmsis_path is not defined! Please pass it as" | |
"an option or set the `CMSIS_PATH` env variable." | |
) |
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
def _generate_cmake_args(self, mlf_extracted_path, options) -> str: | ||
def _generate_cmake_args( | ||
self, | ||
mlf_extracted_path, |
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.
What's the type 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.
added
heap_size = recommended_heap_size | ||
if heap_size_bytes: | ||
heap_size = heap_size_bytes |
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.
Having two different variables heap_size_bytes
and heap_size
might be confusing. Could we instead do:
heap_size = recommended_heap_size | |
if heap_size_bytes: | |
heap_size = heap_size_bytes | |
heap_size = options.get("heap_size_bytes") or recommended_heap_size |
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.
changed that.
|
||
extra_files_tar = options.get("extra_files_tar") | ||
|
||
cmsis_path = get_cmsis_path(options) |
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.
Now getting this exception since pathlib.Path()
is not expecting a None
type:
$ tvmc micro create-project --force /tmp/micro_speech ~/scripts/micro_speech.tar zephyr --project-option board=nrf5340dk_nrf5340_cpuapp project_type=host_driven
WARNING:__main__:Board memory information is not available.
The following error occurred on the Project API server side:
calling method generate_project: JSON-RPC error # -32000: calling method generate_project
Traceback (most recent call last):
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 486, in serve_one_request # <--- Outermost server-side stack frame
self._dispatch_request(request)
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 598, in _dispatch_request
return_value = dispatch_method(**params)
File "/home/gromero/git/tvm/python/tvm/micro/project_api/server.py", line 630, in _dispatch_generate_project
options,
File "/home/gromero/git/tvm/build/microtvm_template_projects/zephyr/microtvm_api_server.py", line 564, in generate_project
cmsis_path = get_cmsis_path(options)
File "/home/gromero/git/tvm/build/microtvm_template_projects/zephyr/microtvm_api_server.py", line 383, in get_cmsis_path
return pathlib.Path(cmsis_path)
File "/usr/lib/python3.6/pathlib.py", line 1001, in __new__
self = cls._from_parts(args, init=False)
File "/usr/lib/python3.6/pathlib.py", line 656, in _from_parts
drv, root, parts = self._parse_args(args)
File "/usr/lib/python3.6/pathlib.py", line 640, in _parse_args
a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType
@mehrdadh I changed the title to add a space after the tags and tweak it a bit the wording to emphasize the new option 'serial_number' since the tweak on the tests would be a merely a consequence of it, although I do guess you're adding it for the internal test fleet. |
We should also update the README.md file to explain correct usage: |
@guberti in cortex_m docker image, the Update: I take back what I said, I need to fix this. |
@guberti I added details about using serial_number in testing. |
d5f9ee9
to
ef992a8
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.
LGTM! I've tested this locally with the NUCLEO-L4R5ZI and it all works as intended.
It would be awesome to make this part of the microTVM pytest plugin and enable this functionality for the Arduino and common tests in a future PR.
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.
@mehrdadh Thanks a lot for addressing the comments. Just three remaining tweaks and I think it's good to land.
@gromero thanks for catching those! PTAL. |
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.
@mehrdadh LGTM!
To whom / Committer / Maintainer that will squash & merge this PR, please consider copying the text from this PR body/description and pasting it as the commit message, avoiding the commit message prepared by GH automatically that brings the review comments, it just takes 1 second and produces a clearer git log. Also in consonance with the Commit Message Guideline. Thanks! |
06fce1f
to
ec2e55e
Compare
I rebased because of this commit: 8cccc25 |
@@ -40,3 +40,9 @@ To see the list of supported values for `--board`, run: | |||
``` | |||
$ pytest test_zephyr.py --help | |||
``` | |||
|
|||
If you like to test with a real hardware, you have the option to pass the serial number |
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:
If you like to test with a real hardware, you have the option to pass the serial number | |
If you like to test with real hardware, you have the option to pass the serial number |
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'll apply it to the next PR if the CI passed.
This commit adds a new option 'serial_number' to allow specifying the serial device number in Zephyr, used to flash and to communicate with target boards attached to specific serial ports, and adjusts Zephyr tests to run with this new option. This is particularly useful in an environment where multiple boards are connected to the host. It also removes 'west_cmd' in test arguments, as it is not used, and refactors Zephyr server API to set the required/optional project options at the beginning of each API call.
Added config_main_stack_size to autotune since running graph debugger requires more workspace. Also added to micro_aot because of KWS model. Also removed west_cmd option in tutorial because of #13377
This PR does these changes: