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] Improved ergonomics of HexagonLauncher in unit tests. #10581

Merged
merged 9 commits into from
Mar 25, 2022

Conversation

Lunderberg
Copy link
Contributor

The goal of this commit is to reduce/eliminate common code required through unit tests that interact with Hexagon hardware.

  • New testing fixtures in tests/python/contrib/test_hexagon. A test running on hexagon hardware should only need to use the hexagon_session fixture.

    • rpc_server_port: Iterates through port numbers, selecting an unused port for each unit test. Avoids needing to explicitly specify unique ports for each unit test.

    • tvm_tracker: Starts a tracker on use, exits after test. Avoids needing to manually start a tracker prior to running the unit test.

    • hexagon_launcher: Starts a HexagonLauncher server on use, stops server after test. Avoids needing to call start_server() and stop_server() in each test.

    • hexagon_session: Starts a hexagon session using hexagon_launcher.start_session(), exits after test.

  • Added Session.upload function, which delegates to HexagonLauncher.upload. Avoids needing to interact with both the launcher and the session.

  • Allowed tvm.IRModule as argument passed to Session.load_module, which will automatically save/upload the module, then load it. Avoids needing to handle save/upload of temporary files in each unit test.

@Lunderberg
Copy link
Contributor Author

Looks like the current failures in CI are due to the ci_hexagon docker image not having the psutil python package, which is necessary to call tracker.terminate(). The tests pass in main, because the tracker is started and killed from bash, rather than within the test fixtures.

The ci_cpu docker image has psutil installed in the ubuntu_install_redis.sh script, which isn't run for generating the ci_hexagon image. This should probably be moved to ubuntu_install_python_packages.sh instead.

return port


@pytest.fixture(scope="session")
def tvm_tracker(tvm_tracker_port):
Copy link
Member

Choose a reason for hiding this comment

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

In nightly test we assume there's a tvm_tracker already running with registered devices on it. So I suggest either remove tvm_tracker from pytext feature or if you could do something more complicated that like this it should work. You can query the server/port and if there was a response don't instantiate the tracker.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, and I hadn't accounted for that. It looks like it is handled similarly in tests/scripts/task_python_hexagon_simulator.sh, with the script starting the tracker before running pytest. I still like having the tracker start from the pytest call, since that minimizes the amount of local setup needed to reproduce a CI failure, but I can see how it would be useful to avoid repeated setup/teardown of the tracker in CI.

I like the idea of choosing whether pytest starts a tracker, though I think I'll implement it based on the presence of the TVM_TRACKER_HOST and TVM_TRACKER_PORT environment variables. This would avoid a potential failure mode from using a server query in a multi-user system, where somebody else's tracker is mistaken for one's own.

The goal of this commit is to reduce/eliminate common code required
through unit tests that interact with Hexagon hardware.

- New testing fixtures in `tests/python/contrib/test_hexagon`.  A test
  running on hexagon hardware should only need to use the
  `hexagon_session` fixture.

  - `rpc_server_port`: Iterates through port numbers, selecting an
    unused port for each unit test.  Avoids needing to explicitly
    specify unique ports for each unit test.

  - `tvm_tracker`: Starts a tracker on use, exits after test.  Avoids
    needing to manually start a tracker prior to running the unit
    test.

  - `hexagon_launcher`: Starts a `HexagonLauncher` server on use,
    stops server after test.  Avoids needing to call `start_server()`
    and `stop_server()` in each test.

  - `hexagon_session`: Starts a hexagon session using
    `hexagon_laucnehr.start_session()`, exits after test.

- Added `Session.upload` function, which delegates to
  `HexagonLauncher.upload`.  Avoids needing to interact with both the
  launcher and the session.

- Allowed `tvm.IRModule` as argument passed to `Session.load_module`,
  which will automatically save/upload the module, then load it.
  Avoids needing to handle save/upload of temporary files in each unit
  test.
@Lunderberg Lunderberg force-pushed the hexagon_launcher_ergonomics branch from b73501a to 9c16f66 Compare March 21, 2022 14:59
@Lunderberg
Copy link
Contributor Author

Rebased onto main to resolve merge conflict.

@Lunderberg Lunderberg force-pushed the hexagon_launcher_ergonomics branch from 9c16f66 to 52fda7e Compare March 21, 2022 15:08
@Lunderberg Lunderberg marked this pull request as ready for review March 23, 2022 15:23
Copy link
Contributor

@csullivan csullivan left a comment

Choose a reason for hiding this comment

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

Looks great! Only a couple nits. Forgot to click submit earlier..

python/tvm/contrib/hexagon/build.py Outdated Show resolved Hide resolved
python/tvm/contrib/hexagon/session.py Show resolved Hide resolved
python/tvm/contrib/hexagon/session.py Show resolved Hide resolved
tests/python/contrib/test_hexagon/conftest.py Outdated Show resolved Hide resolved
@Lunderberg Lunderberg force-pushed the hexagon_launcher_ergonomics branch from a611b3c to f7844ef Compare March 25, 2022 13:19
@Lunderberg
Copy link
Contributor Author

Looks like the Windows build failed due to network failure, all other tests passed. Pushed a dummy commit to restart the CI.

@csullivan csullivan merged commit f16286e into apache:main Mar 25, 2022
@Lunderberg Lunderberg deleted the hexagon_launcher_ergonomics branch March 25, 2022 16:31
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Apr 5, 2022
Follow-up from apache#10581, applying
similar changes to the AOT and graph executor interactions.  This
moves the file management and upload/download from the unit tests into
the launcher.
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Apr 7, 2022
Should have been removed as part of
apache#10581.
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Apr 8, 2022
Should have been removed as part of
apache#10581.
kparzysz-quic pushed a commit that referenced this pull request Apr 8, 2022
Should have been removed as part of
#10581.
pfk-beta pushed a commit to pfk-beta/tvm that referenced this pull request Apr 11, 2022
…he#10581)

* [Hexagon] Improved ergonomics of HexagonLauncher in unit tests.

The goal of this commit is to reduce/eliminate common code required
through unit tests that interact with Hexagon hardware.

- New testing fixtures in `tests/python/contrib/test_hexagon`.  A test
  running on hexagon hardware should only need to use the
  `hexagon_session` fixture.

  - `rpc_server_port`: Iterates through port numbers, selecting an
    unused port for each unit test.  Avoids needing to explicitly
    specify unique ports for each unit test.

  - `tvm_tracker`: Starts a tracker on use, exits after test.  Avoids
    needing to manually start a tracker prior to running the unit
    test.

  - `hexagon_launcher`: Starts a `HexagonLauncher` server on use,
    stops server after test.  Avoids needing to call `start_server()`
    and `stop_server()` in each test.

  - `hexagon_session`: Starts a hexagon session using
    `hexagon_laucnehr.start_session()`, exits after test.

- Added `Session.upload` function, which delegates to
  `HexagonLauncher.upload`.  Avoids needing to interact with both the
  launcher and the session.

- Allowed `tvm.IRModule` as argument passed to `Session.load_module`,
  which will automatically save/upload the module, then load it.
  Avoids needing to handle save/upload of temporary files in each unit
  test.

* Added default port for tracker if not already set.

* Pass through None from hexagon_launcher to hexagon_session.

* Updated launcher to use external tracker if specified.

* Avoid setting up the local tracker unless required.

* Declare previous_port as global, instead of list.

* Corrected type hints.

* Docstring updates
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Apr 11, 2022
kparzysz-quic pushed a commit that referenced this pull request Apr 12, 2022
* [Hexagon] Move aot/graph_executor interactions into launcher

Follow-up from #10581, applying
similar changes to the AOT and graph executor interactions.  This
moves the file management and upload/download from the unit tests into
the launcher.

* Added Session.test_executor to avoid duplication in graph/aot test.

* Resolve lint errors

* Moved link flags workaround out of session, into create_aot_shared

* Separated Session.get_*_executor and Session.get_executor_from_factory

* Updated to resolve lint error
Lucien0 pushed a commit to Lucien0/tvm that referenced this pull request Apr 19, 2022
Lucien0 pushed a commit to Lucien0/tvm that referenced this pull request Apr 19, 2022
…10907)

* [Hexagon] Move aot/graph_executor interactions into launcher

Follow-up from apache#10581, applying
similar changes to the AOT and graph executor interactions.  This
moves the file management and upload/download from the unit tests into
the launcher.

* Added Session.test_executor to avoid duplication in graph/aot test.

* Resolve lint errors

* Moved link flags workaround out of session, into create_aot_shared

* Separated Session.get_*_executor and Session.get_executor_from_factory

* Updated to resolve lint error
altanh pushed a commit to altanh/tvm that referenced this pull request Apr 28, 2022
altanh pushed a commit to altanh/tvm that referenced this pull request Apr 28, 2022
…10907)

* [Hexagon] Move aot/graph_executor interactions into launcher

Follow-up from apache#10581, applying
similar changes to the AOT and graph executor interactions.  This
moves the file management and upload/download from the unit tests into
the launcher.

* Added Session.test_executor to avoid duplication in graph/aot test.

* Resolve lint errors

* Moved link flags workaround out of session, into create_aot_shared

* Separated Session.get_*_executor and Session.get_executor_from_factory

* Updated to resolve lint error
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.

3 participants