guberti commented on code in PR #13518:
URL: https://github.com/apache/tvm/pull/13518#discussion_r1037672769
##########
tests/micro/arduino/test_arduino_rpc_server.py:
##########
@@ -318,31 +354,48 @@ def test_byoc_microtvm(board, arduino_cli_cmd,
microtvm_debug, workspace_dir):
arduino_board=board,
arduino_cli_cmd=arduino_cli_cmd,
workspace_dir=workspace_dir,
+ serial_number=serial_number,
)
def _make_add_sess_with_shape(
- model, arduino_board, arduino_cli_cmd, workspace_dir, shape, build_config
+ model,
+ arduino_board,
+ arduino_cli_cmd,
+ workspace_dir,
+ shape,
+ build_config,
+ serial_number: str = None,
):
A = tvm.te.placeholder(shape, dtype="int8")
C = tvm.te.compute(A.shape, lambda i: A[i] + A[i], name="C")
sched = tvm.te.create_schedule(C.op)
return _make_sess_from_op(
- model, arduino_board, arduino_cli_cmd, workspace_dir, "add", sched,
[A, C], build_config
+ model,
+ arduino_board,
+ arduino_cli_cmd,
+ workspace_dir,
+ "add",
+ sched,
+ [A, C],
+ build_config,
+ serial_number,
)
@pytest.mark.parametrize(
"shape,",
[
pytest.param((1 * 1024,), id="(1*1024)"),
- pytest.param((4 * 1024,), id="(4*1024)"),
- pytest.param((16 * 1024,), id="(16*1024)"),
+ # pytest.param((4 * 1024,), id="(4*1024)"),
+ # pytest.param((16 * 1024,), id="(16*1024)"),
Review Comment:
Why did we comment these out?
##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -594,21 +622,24 @@ def flash(self, options):
)
def open_transport(self, options):
+ # TODO: This is to avoid breaking GPU docker on running the tutorials.
import serial
import serial.tools.list_ports
Review Comment:
Can you clarify this comment a bit? I don't understand how this fixes the
GPU docker on tutorials.
##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -93,6 +93,13 @@ class BoardAutodetectFailed(Exception):
default=None,
help="Port to use for connecting to hardware.",
),
+ server.ProjectOption(
+ "serial_number",
+ optional=["open_transport", "flash"],
+ type="str",
+ default=None,
+ help=("Board serial number."),
+ ),
Review Comment:
Rather than having one override the other, I'd prefer to raise an error if
there is a conflict. Your call, though.
##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -524,26 +534,42 @@ def _parse_connected_boards(self, tabular_str):
device[col_name] = str_row[column.start() :
column.end()].strip()
yield device
- def _auto_detect_port(self, arduino_cli_cmd: str, board: str) -> str:
- list_cmd = [self._get_arduino_cli_cmd(arduino_cli_cmd), "board",
"list"]
- list_cmd_output = subprocess.run(
- list_cmd, check=True, stdout=subprocess.PIPE
- ).stdout.decode("utf-8")
+ def _auto_detect_port(self, arduino_cli_cmd: str, board: str,
serial_number: str) -> str:
+ # TODO: This is to avoid breaking GPU docker on running the tutorials.
+ import serial.tools.list_ports
- desired_fqbn = self._get_fqbn(board)
- for device in self._parse_connected_boards(list_cmd_output):
- if device["fqbn"] == desired_fqbn:
- return device["port"]
+ if not serial_number:
+ # If serial_number is not set, it is assumed only one board
+ # with this type is connected to this host machine.
+ list_cmd = [self._get_arduino_cli_cmd(arduino_cli_cmd), "board",
"list"]
+ list_cmd_output = subprocess.run(
+ list_cmd, check=True, stdout=subprocess.PIPE
+ ).stdout.decode("utf-8")
+
+ desired_fqbn = self._get_fqbn(board)
+ for device in self._parse_connected_boards(list_cmd_output):
+ if device["fqbn"] == desired_fqbn:
+ device_port = device["port"]
+ break
+ else:
+ com_ports = serial.tools.list_ports.comports()
+ for port in com_ports:
+ if port.serial_number == serial_number:
+ device_port = port.device
+ if device_port:
+ return device_port
# If no compatible boards, raise an error
raise BoardAutodetectFailed()
Review Comment:
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`.
--
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]