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

[Hexagon] Download generated artifacts from android device to host #11476

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions python/tvm/contrib/hexagon/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ class HexagonLauncherAndroid(HexagonLauncherRPC):
]

def __init__(
self, serial_number: str, rpc_info: dict, workspace: Union[str, pathlib.Path] = None
self,
serial_number: str,
rpc_info: dict,
workspace: Union[str, pathlib.Path] = None,
host_workspace: Union[str, pathlib.Path] = None,
):
"""Configure a new HexagonLauncherAndroid

Expand All @@ -335,6 +339,7 @@ def __init__(
"""
if not rpc_info.get("workspace_base"):
rpc_info["workspace_base"] = self.ANDROID_HEXAGON_TEST_BASE_DIR
self._host_workspace = host_workspace
self._serial_number = serial_number
adb_socket = rpc_info["adb_server_socket"] if rpc_info["adb_server_socket"] else "tcp:5037"
self._adb_device_sub_cmd = ["adb", "-L", adb_socket, "-s", self._serial_number]
Expand Down Expand Up @@ -472,6 +477,15 @@ def _cleanup_directory(self):
# Remove workspace directory on remote target
subprocess.Popen(self._adb_device_sub_cmd + ["shell", f"rm -rf {self._workspace}"])

def _copy_artifacts_to_host(self):
# Copy generated artifacts from device to host
if self._host_workspace:
for file in ["tvm_rpc_android.farf", "tvm_rpc_android.log"]:
Copy link
Contributor

Choose a reason for hiding this comment

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

The farf file only configures fastrpc to forward Hexagon logs to Android's logging facility. There's no need to pull it back off the device.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the intention is to pull of the debug output from Hexagon, you'll likely need to run logcat in parallel, possibly filtering out extraneous messages from the rest of the system.

subprocess.Popen(
self._adb_device_sub_cmd
+ ["pull", str(self._workspace / file), str(self._host_workspace / file)]
)

def start_server(self):
"""Abstract method implementation. See description in HexagonLauncherRPC."""
self._copy_binaries()
Expand All @@ -481,6 +495,7 @@ def stop_server(self):
"""Abstract method implementation. See description in HexagonLauncherRPC."""
self._cleanup_port_forwarding()
self._terminate_remote()
self._copy_artifacts_to_host()
self._cleanup_directory()


Expand Down Expand Up @@ -593,7 +608,12 @@ def _is_port_in_use(port: int) -> bool:


# pylint: disable=invalid-name
def HexagonLauncher(serial_number: str, rpc_info: dict, workspace: Union[str, pathlib.Path] = None):
def HexagonLauncher(
serial_number: str,
rpc_info: dict,
workspace: Union[str, pathlib.Path] = None,
host_workspace: Union[str, pathlib.Path] = None,
):
if serial_number == "simulator":
return HexagonLauncherSimulator(rpc_info, workspace)
return HexagonLauncherAndroid(serial_number, rpc_info, workspace)
return HexagonLauncherAndroid(serial_number, rpc_info, workspace, host_workspace)
28 changes: 26 additions & 2 deletions python/tvm/contrib/hexagon/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
import os
import random
from typing import Optional, Union
import pathlib
import datetime

import pytest

import tvm
import tvm.rpc.tracker
from tvm.contrib.hexagon.build import HexagonLauncher, HexagonLauncherRPC
from tvm.contrib.hexagon.session import Session
from tvm.contrib.utils import tempdir

HEXAGON_TOOLCHAIN = "HEXAGON_TOOLCHAIN"
TVM_TRACKER_HOST = "TVM_TRACKER_HOST"
Expand Down Expand Up @@ -156,9 +159,28 @@ def adb_server_socket() -> str:
return os.getenv(ADB_SERVER_SOCKET, default="tcp:5037")


@pytest.fixture
def temp_dir():
workspace = (
pathlib.Path(os.path.abspath("."))
/ f"hexagon_workspace"
/ datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
)
workspace_base = str(workspace)
number = 1
while workspace.exists():
workspace = pathlib.Path(workspace_base + f"-{number}")
number += 1
if not os.path.exists(workspace.parent):
os.makedirs(workspace.parent)

# return tempdir(custom_path=board_workspace, keep_for_debug=True)
return tempdir(custom_path=workspace)


@tvm.testing.fixture
def hexagon_launcher(
request, android_serial_number, rpc_server_port, adb_server_socket
request, android_serial_number, rpc_server_port, adb_server_socket, temp_dir
) -> HexagonLauncherRPC:
"""Initials and returns hexagon launcher if ANDROID_SERIAL_NUMBER is defined"""
if android_serial_number is None:
Expand All @@ -176,7 +198,9 @@ def hexagon_launcher(
"rpc_server_port": rpc_server_port,
"adb_server_socket": adb_server_socket,
}
launcher = HexagonLauncher(serial_number=android_serial_number, rpc_info=rpc_info)
launcher = HexagonLauncher(
serial_number=android_serial_number, rpc_info=rpc_info, host_workspace=temp_dir
)
launcher.start_server()
try:
yield launcher
Expand Down