Skip to content
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][Arduino]Add serial_number to project options and tests #13518

Merged
merged 11 commits into from
Dec 5, 2022

Conversation

mehrdadh
Copy link
Member

This PR adds serial_number as a project option to Arduino project API. In addition, it is added to micro pytest_plugin to enable testing with assigned serial number.

@tvm-bot
Copy link
Collaborator

tvm-bot commented Nov 30, 2022

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

@mehrdadh mehrdadh requested a review from gromero November 30, 2022 01:50
@mehrdadh
Copy link
Member Author

cc @guberti for review

Copy link
Member

@guberti guberti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few general comments, but I can't get this PR working. I see this error:

guberti@guberti-Precision-7540:~/tvm$ python -m pytest -s tests/micro/arduino/test_arduino_rpc_server.py::test_compile_runtime[due] --board due --serial 123

...lines omitted for brevity...

E             File "/home/guberti/tvm/tests/micro/arduino/workspace_due/2022-12-01T05-46-57/project/microtvm_api_server.py", line 597, in flash
E               port = self._get_arduino_port(cli_command, board, port, serial_number)
E             File "/home/guberti/tvm/tests/micro/arduino/workspace_due/2022-12-01T05-46-57/project/microtvm_api_server.py", line 564, in _get_arduino_port
E               self._port = self._auto_detect_port(
E             File "/home/guberti/tvm/tests/micro/arduino/workspace_due/2022-12-01T05-46-57/project/microtvm_api_server.py", line 549, in _auto_detect_port
E               com_ports = serial.tools.list_ports.comports()
E           NameError: name 'serial' is not defined

python/tvm/micro/project_api/client.py:135: ServerError
=========================== short test summary info ============================
FAILED tests/micro/arduino/test_arduino_rpc_server.py::test_compile_runtime[due]
========================= 1 failed, 1 warning in 2.63s =========================

I think moving import serial.tools.list_ports from flash to _auto_detect_port will fix the issue.

# If no compatible boards, raise an error
raise BoardAutodetectFailed()

def _get_arduino_port(self, arduino_cli_cmd: str, board: str, port: int):
def _get_arduino_port(self, arduino_cli_cmd: str, board: str, port: int, serial_number: str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update type annotations to reflect that port and serial_number are optional.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

python/tvm/micro/testing/pytest_plugin.py Outdated Show resolved Hide resolved
python/tvm/micro/testing/pytest_plugin.py Outdated Show resolved Hide resolved
tests/micro/arduino/test_arduino_rpc_server.py Outdated Show resolved Hide resolved
python/tvm/micro/testing/pytest_plugin.py Show resolved Hide resolved
@mehrdadh mehrdadh requested a review from guberti December 1, 2022 17:31
Copy link
Member

@guberti guberti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and passes on my local Arduino hardware. Just a few nits!

Comment on lines +625 to 627
# TODO: This is to avoid breaking GPU docker on running the tutorials.
import serial
import serial.tools.list_ports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify this comment a bit? I don't understand how this fixes the GPU docker on tutorials.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I moved these imports to the top of the file, there was an error with doc stage in GPU. I think the reason is that we don't have dependencies for this in GPU docker. cc @driazati

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this file is imported but this function isn't run during the tutorial docs build then it would fail, this fixes it with a lazy import. it would be nice to link to an issue about this though for more context

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driazati I remember there was some discussion about running tutorials in the related docker and only render the results in GPU/Doc stage. Did that happen?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we never implemented anything like that, though here it might be easiest to just install pyserial in the GPU docker image and call it a day

tests/micro/arduino/test_arduino_rpc_server.py Outdated Show resolved Hide resolved
Comment on lines 560 to 563
if device_port:
return device_port
# If no compatible boards, raise an error
raise BoardAutodetectFailed()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic is bugged. If I pass an invalid serial_number, I get:

E             File "/home/guberti/tvm/tests/micro/arduino/workspace_due/2022-12-01T16-09-00/project/microtvm_api_server.py", line 560, in _auto_detect_port
E               if device_port:
E           UnboundLocalError: local variable 'device_port' referenced before assignment

This makes sense, as device_port is never defined if device["fqbn"] == desired_fqbn.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

investigating this

Copy link
Member Author

@mehrdadh mehrdadh Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was an issue. I changed _get_arduino_port function to address this issue. Now in this function we have this priority:

  1. port
  2. detect port using serial_number
  3. auto detect port with arduino-cli
    In 2 and 3 we show proper exception if it was not able to find the port. Also I changed project option help messages to include this change.

Also if both port and serial_number are set it will show exception

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm but isn't device_port only set if we find a valid port?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah. Are you suggesting to just return it in the for loop?

@mehrdadh mehrdadh requested a review from areusch December 2, 2022 00:50
Comment on lines 560 to 563
if device_port:
return device_port
# If no compatible boards, raise an error
raise BoardAutodetectFailed()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm but isn't device_port only set if we find a valid port?

@@ -33,3 +33,9 @@ To see the list of supported values for `--board`, run:
```
$ pytest --help
```

If you like to test with a real hardware, you have the option to pass the serial number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If you like to test with a real hardware, you have the option to pass the serial number
If you would like to test with a real hardware and need to target one of many identical devices, you have the option to pass the serial number

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added that

@mehrdadh mehrdadh merged commit 2b11036 into apache:main Dec 5, 2022
@mehrdadh mehrdadh deleted the micro/use_serial_for_arduino branch December 5, 2022 17:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants