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] Initial support for meta schedule tuning #12587

Merged
merged 10 commits into from
Aug 26, 2022

Conversation

masahi
Copy link
Member

@masahi masahi commented Aug 25, 2022

Enables AutoTVM-style, template-based tuning for Hexagon.

To run compiled code on Hexagon, we need to use Hexagon Session object

in the metaschedule RPCRunner. But for RPC "session", RPCRunner expects an instance of RPCSession,
class RPCSession(object):
, to be created and used by various customizable functions.

Since RPCSession and Hexagon Session have slightly different API, we cannot use RPCRunner with customizable functions directly. So I introduced an alternative implementation of RPCRunner for Hexagon.

The test is disabled for simulator since HexagonLauncherSimulator is not pickle-able due to its multiprocessing.Process attribute:

self._server_process = mp.Process(target=lambda *a: _start(self, *a))

Output log from tuning vrmpy dense (included in the test)

 ID | Name |      FLOP | Weight | Speed (GFLOPS) | Latency (us) | Weighted Latency (us) | Trials | Terminated
--------------------------------------------------------------------------------------------------------------
  0 | main | 150994944 |      1 |       380.3399 |     397.0000 |              397.0000 |     32 |
--------------------------------------------------------------------------------------------------------------

cc @mehrdadh @csullivan @kparzysz-quic @junrushao @zxybazh

@github-actions github-actions bot requested a review from mehrdadh August 25, 2022 01:57
@junrushao junrushao changed the title [Hexagon] Initial support for meta scheduler tuning [Hexagon] Initial support for meta schedule tuning Aug 25, 2022
@junrushao
Copy link
Member

just a quick typo fix: it's meta schedule not meta scheduler :-) meta schedule is a "meta" schedule that generate basic schedules

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.

🎉

@pytest.mark.skip(reason="xgboost not installed on CI")
@tvm.testing.requires_hexagon
def test_vrmpy_dense(hexagon_launcher):
if hexagon_launcher._serial_number == "simulator":
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be really great for this to be tested pre-commit on the simulator so future changes don't regress on the ability to tune. @kparzysz-quic do you think we could remove the use of a local x86 rpc server for targeting the hexagon simulator? Goal would be to make HexagonLauncherSimulator pickleable.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand the goal. What exactly do you want to make pickleable? Where would it be unpickled?

Right now the simulator fits in the general RPC infrastructure, with the RPC tracker and all. I guess it would be possible to change this, but I'm concerned that it would make Hexagon a "special case", plus I'm really not sure what we gain by doing this.

Copy link
Member Author

@masahi masahi Aug 25, 2022

Choose a reason for hiding this comment

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

The issue is that meta schedule RPCRunner uses PopenPoolExuecutor which requires everything that's passed to it be pickle-able:

future=self.pool.submit(
_worker_func,
self.hexagon_launcher,
self.evaluator_config,
self.alloc_repeat,
str(runner_input.artifact_path),
tuple(arg_info.as_json() for arg_info in runner_input.args_info),
),
timeout_sec=100,

If we try to pass HexagonLauncherSimulator, we get this error https://ci.tlcpack.ai/blue/organizations/jenkins/tvm/detail/PR-12587/3/pipeline/ , Pickling an AuthenticationString object is disallowed for security reasons. Apparently this is coming from trying to pickle

self._server_process = mp.Process(target=lambda *a: _start(self, *a))
.

The question is, can we remove _server_process from HexagonLauncherSimulator?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @masahi @kparzysz-quic - By the way also, not using a local RPC server is not making Hexagon a special case. For example, the CUDA target can be used locally without an x86 RPC server if it is attached to the machine being compiled. For the simulator there may be a similar solution, though it would end up testing a different codepath than runs with HW, so it is worth considering carefully.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, that makes sense. Could we keep the current setup with the x86 server, and add another way to execute the simulator? I think there is value in being able to test the HW code path via simulator (and tests wouldn't need to be changed---right now they are set up to only depend on the device serial to decide whether they should run on HW or sim).

@csullivan csullivan merged commit d87fa85 into apache:main Aug 26, 2022
driazati pushed a commit that referenced this pull request Aug 26, 2022
driazati pushed a commit to driazati/tvm that referenced this pull request Aug 26, 2022
driazati pushed a commit to driazati/tvm that referenced this pull request Aug 26, 2022
driazati pushed a commit to driazati/tvm that referenced this pull request Aug 29, 2022
areusch pushed a commit that referenced this pull request Aug 30, 2022
[CI] Update Hexagon image to install boost (#12613)

The new image has xgboost installed, which I need for #12587

Validated in https://ci.tlcpack.ai/blue/organizations/jenkins/tvm/detail/ci-docker-staging/279/pipeline

Co-authored-by: masahi <masahi129@gmail.com>
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
Enables AutoTVM-style, template-based tuning for Hexagon.

To run compiled code on Hexagon, we need to use Hexagon `Session` object https://github.com/apache/tvm/blob/dc522a6ff65b68532cd1bba43827cd981114df2c/python/tvm/contrib/hexagon/session.py#L35 in the metaschedule `RPCRunner`. But for RPC "session", `RPCRunner` expects an instance of `RPCSession`, https://github.com/apache/tvm/blob/53fe5966823eee4e011d7228bceab3c82c1d9caa/python/tvm/rpc/client.py#L32,  to be created and used by various customizable functions. 

Since `RPCSession` and Hexagon `Session` have slightly different API, we cannot use `RPCRunner` with customizable functions directly. So I introduced an alternative implementation of `RPCRunner` for Hexagon.

The test is disabled for simulator since `HexagonLauncherSimulator` is not pickle-able due to its `multiprocessing.Process` attribute: https://github.com/apache/tvm/blob/c97895e0ffb512e73c89de7cdee9846f052244fc/python/tvm/contrib/hexagon/build.py#L614


Output log from tuning `vrmpy` dense (included in the test)

```
 ID | Name |      FLOP | Weight | Speed (GFLOPS) | Latency (us) | Weighted Latency (us) | Trials | Terminated
--------------------------------------------------------------------------------------------------------------
  0 | main | 150994944 |      1 |       380.3399 |     397.0000 |              397.0000 |     32 |
--------------------------------------------------------------------------------------------------------------
```
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
[CI] Update Hexagon image to install boost (apache#12613)

The new image has xgboost installed, which I need for apache#12587

Validated in https://ci.tlcpack.ai/blue/organizations/jenkins/tvm/detail/ci-docker-staging/279/pipeline

Co-authored-by: masahi <masahi129@gmail.com>
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.

4 participants