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] Add support for linked-in model parameters #8865

Merged
merged 6 commits into from
Sep 6, 2021
Merged

[Hexagon] Add support for linked-in model parameters #8865

merged 6 commits into from
Sep 6, 2021

Conversation

kparzysz-quic
Copy link
Contributor

No description provided.

@jroesch
Copy link
Member

jroesch commented Aug 27, 2021

cc @manupa-arm @leandron is this using same machinery you guys are using? would you mind reviewing?

cc @areusch

@kparzysz-quic
Copy link
Contributor Author

Gentle ping...

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

I had a look.
Few questions and a nit.

Is it possible to add a test that to show the linked params are generated?

linked_params =
Downcast<Map<String, LinkedParam>>(attrs_dict[::tvm::tir::attr::kLinkedParams]);
found_linked_params = true;
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit : this seems searching for whether at least one function have linked_params, if so I think we dont need to continue searching. A further suggestion is to break it out to a function for that check w/o needing to maintain found_linked_params bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is traversing all functions and

  • if f is a "linked-params" function, we set it aside,
  • otherwise we add f to the list of functions for codegen.

We need to skip the "linked-params" function, because the codegen path for it is different. We create the bool variable so that we know to generate the linked parameters function later on, but the variable is not the only effect of the loop, so there isn't much to gain by extracting it into a separate function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack, so this is just to skip the linked-params function -- might be better to add a comment.

I guess my original concern is it would be bit more readable if it was a different function to obtain the linked-params altogether rather than fusing it with the loop as you correctly note here -- it being not the only effect, WDYT?

cc: @d-smirnov , another occurence where linked-param will be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We will still need to recognize it when adding functions to the codegen module (to avoid adding it).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ack and thanks for the explaination -- maybe a comment would help then :)

Map<String, ObjectRef> attrs_dict = Downcast<Map<String, ObjectRef>>(kv.second->attrs->dict);
CHECK(attrs_dict.find(::tvm::tir::attr::kLinkedParams) != attrs_dict.end())
<< "no " << ::tvm::tir::attr::kLinkedParams << " attribute found!";
linked_params =
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we replacing the map here (as opposed to setting it) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "replacing" the map? Map is an ObjectRef, so we're not really copying anything here.

Copy link
Contributor

@manupak manupak Sep 1, 2021

Choose a reason for hiding this comment

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

I thought the reason for declaring the Map outside of the scope of loop is to 'Set' it -- hence the question.

Another way to ask the same thing : any reason to declare the Map outside of the for loop ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used after the loop. The map holds the parameters that we pass to LinkParameters.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm, it seems this work because it is only set once in the loop.
Any reason not to codegen it here (rather than doing it down there) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to add a check there to make sure it's not set more than once.

@kparzysz-quic
Copy link
Contributor Author

kparzysz-quic commented Sep 1, 2021

I'll add a testcase for Hexagon, but it won't run in the CI, because Hexagon is not built (it requires SDK).

@kparzysz-quic
Copy link
Contributor Author

kparzysz-quic commented Sep 4, 2021

  • Rebased the PR on top of main.
  • Removed the found_linked_params variable.
  • Added codegen testcase.

Edit: make bulleted list.

Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

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

sorry for the delay @kparzysz-quic . i think we can proceed with this since it uses the same mechanism we currently use in GraphRuntime C land. for AOT we'll need to likely go a different route, but we'll need to handle that in the C source codegen anyhow I believe.

@@ -107,7 +109,71 @@ def test_alloc_vtcm():
assert "HexagonBackendFreeVTCM" in calls


def test_linked_params_codegen():
if not check_prereq_and_setup():
Copy link
Contributor

Choose a reason for hiding this comment

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

(also ok for a follow-up) do you mind migrating this to the pytest decorator style and modifying the __main__ invocation:

if __name__ == "__main__":
    sys.exit(pytest.main([__file__] + sys.argv[1:]))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll do it, but I'd prefer to do it in a separate PR, since I'd need to change some extra files.

Copy link
Contributor

@manupak manupak left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the changes.

@areusch , when we have non-scalar constants in TIR -- the code generation for operators will incorporate codegen for linked-params and I believe it'll be executor agnostic.

@kparzysz-quic kparzysz-quic merged commit 9b034d7 into apache:main Sep 6, 2021
@kparzysz-quic kparzysz-quic deleted the hexagon-link-params branch September 6, 2021 23:54
ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
* [Hexagon] Add support for linked-in model parameters

* Remove entry_func, since it's not used anywhere

* Simplify linked-param codegen preparation a bit

* Detect multiple linked-params functions

* Add testcase to check for linked-param codegen

* Empty commit to restart build
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
* [Hexagon] Add support for linked-in model parameters

* Remove entry_func, since it's not used anywhere

* Simplify linked-param codegen preparation a bit

* Detect multiple linked-params functions

* Add testcase to check for linked-param codegen

* Empty commit to restart build
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.

5 participants