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 2021/10/27 16:19:33 UTC

[GitHub] [tvm] areusch commented on a change in pull request #9364: [microTVM] Fix AOT/ARMv7m tests on physical devices.

areusch commented on a change in pull request #9364:
URL: https://github.com/apache/tvm/pull/9364#discussion_r737634955



##########
File path: python/tvm/micro/testing.py
##########
@@ -31,3 +35,55 @@ def check_tune_log(log_path: Union[pathlib.Path, str]):
         if len(line) > 0:
             tune_result = json.loads(line)
             assert tune_result["result"][0][0] < 1000000000.0
+
+
+def aot_transport_init_wait(transport):
+    """Send init message to microTVM device until it receives wakeup sequence."""
+    timeout = 5
+    while True:
+        try:
+            aot_transport_find_message(transport, "wakeup", timeout_sec=timeout)
+            break
+        except IoTimeoutError:
+            transport.write(b"init%", timeout_sec=timeout)
+
+
+def aot_transport_find_message(transport, expression: str, timeout_sec: int):
+    """Read transport message until it finds the expression."""
+    while True:
+        data = _read_line(transport, timeout_sec)

Review comment:
       what if each time, `_read_line` takes `timeout_sec - 0.001`?

##########
File path: apps/microtvm/zephyr/template_project/src/aot_demo/main.c
##########
@@ -38,14 +38,21 @@
 #include "posix_board_if.h"
 #endif
 
-#define WORKSPACE_SIZE (270 * 1024)
+// WORKSPACE_SIZE defined in Project API Makefile
 
 static uint8_t g_aot_memory[WORKSPACE_SIZE];
 tvm_workspace_t app_workspace;
 
-// Wakeup sequence used to wake up QEMU on the host.
-const unsigned char g_wakeup_sequence[] = "#wakeup\n";
-const char g_start_cmd[] = "start\n";
+// Transport Commands.
+// Commands on host end with `\n`
+// Commands on microTVM device end with `%`
+const unsigned char CMD_WAKEUP[] = "wakeup\n";

Review comment:
       just documenting for posterity: so i think ultimately we may want to just have one communication protocol (the TVM RPC one), but this is sort of a stopgap til we build the glue that talks to AOT executor from TVM RPC server.

##########
File path: python/tvm/micro/testing.py
##########
@@ -31,3 +35,55 @@ def check_tune_log(log_path: Union[pathlib.Path, str]):
         if len(line) > 0:
             tune_result = json.loads(line)
             assert tune_result["result"][0][0] < 1000000000.0
+
+
+def aot_transport_init_wait(transport):
+    """Send init message to microTVM device until it receives wakeup sequence."""
+    timeout = 5
+    while True:
+        try:
+            aot_transport_find_message(transport, "wakeup", timeout_sec=timeout)
+            break
+        except IoTimeoutError:
+            transport.write(b"init%", timeout_sec=timeout)
+
+
+def aot_transport_find_message(transport, expression: str, timeout_sec: int):
+    """Read transport message until it finds the expression."""
+    while True:
+        data = _read_line(transport, timeout_sec)
+        logging.debug("new line: %s", data)
+        if expression in data:
+            return data
+
+
+def _read_line(transport, timeout_sec: int):
+    data = ""
+    new_line = False

Review comment:
       what's the point of this var?

##########
File path: tests/micro/zephyr/test_zephyr.py
##########
@@ -374,8 +374,8 @@ def test_tensors(sess):
 @tvm.testing.requires_micro
 def test_autotune_conv2d(temp_dir, board, west_cmd, tvm_debug):
     """Test AutoTune for microTVM Zephyr"""
-    if board in ["qemu_riscv32", "qemu_riscv64"]:
-        pytest.xfail(f"Autotune fails on  {board}.")
+    if board != "qemu_x86":
+        pytest.xfail(f"Autotune fails on {board}.")

Review comment:
       want to say more about why this fails on qemu_x86 since it's just the one board?

##########
File path: python/tvm/micro/testing.py
##########
@@ -31,3 +35,55 @@ def check_tune_log(log_path: Union[pathlib.Path, str]):
         if len(line) > 0:
             tune_result = json.loads(line)
             assert tune_result["result"][0][0] < 1000000000.0
+
+
+def aot_transport_init_wait(transport):
+    """Send init message to microTVM device until it receives wakeup sequence."""
+    timeout = 5

Review comment:
       timeout_sec and make it a module-level constant with comment

##########
File path: python/tvm/micro/testing.py
##########
@@ -31,3 +35,55 @@ def check_tune_log(log_path: Union[pathlib.Path, str]):
         if len(line) > 0:
             tune_result = json.loads(line)
             assert tune_result["result"][0][0] < 1000000000.0
+
+
+def aot_transport_init_wait(transport):
+    """Send init message to microTVM device until it receives wakeup sequence."""
+    timeout = 5
+    while True:
+        try:
+            aot_transport_find_message(transport, "wakeup", timeout_sec=timeout)
+            break
+        except IoTimeoutError:
+            transport.write(b"init%", timeout_sec=timeout)
+
+
+def aot_transport_find_message(transport, expression: str, timeout_sec: int):
+    """Read transport message until it finds the expression."""
+    while True:
+        data = _read_line(transport, timeout_sec)
+        logging.debug("new line: %s", data)
+        if expression in data:
+            return data
+
+
+def _read_line(transport, timeout_sec: int):
+    data = ""

Review comment:
       make this a bytearray to avoid chr()--you want to convert the whole line to utf-8 at once by calling `str(data)` at the end of the function, if you want to do this.

##########
File path: python/tvm/micro/testing.py
##########
@@ -31,3 +35,55 @@ def check_tune_log(log_path: Union[pathlib.Path, str]):
         if len(line) > 0:
             tune_result = json.loads(line)
             assert tune_result["result"][0][0] < 1000000000.0
+
+
+def aot_transport_init_wait(transport):
+    """Send init message to microTVM device until it receives wakeup sequence."""
+    timeout = 5
+    while True:
+        try:
+            aot_transport_find_message(transport, "wakeup", timeout_sec=timeout)
+            break
+        except IoTimeoutError:
+            transport.write(b"init%", timeout_sec=timeout)
+
+
+def aot_transport_find_message(transport, expression: str, timeout_sec: int):
+    """Read transport message until it finds the expression."""
+    while True:
+        data = _read_line(transport, timeout_sec)
+        logging.debug("new line: %s", data)
+        if expression in data:
+            return data
+
+
+def _read_line(transport, timeout_sec: int):
+    data = ""
+    new_line = False
+    while True:
+        if new_line:
+            break
+        new_data = transport.read(1, timeout_sec=timeout_sec)
+        logging.debug("read data: %s", new_data)
+        for item in new_data:
+            new_c = chr(item)
+            data = data + new_c
+            if new_c == "\n":
+                new_line = True
+                break
+    return data
+
+
+def mlf_extract_workspace_size_bytes(
+    mlf_tar_path: Union[pathlib.Path, str], extract_path: Union[pathlib.Path, str]
+):
+    """Extract an MLF archive file and read workspace size from metadata file."""
+
+    tar_file = str(mlf_tar_path)

Review comment:
       want to use [tarfile](https://docs.python.org/3/library/tarfile.html) module to do this? since it's checked in to python/tvm/micro.




-- 
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