-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[RUNTIME] Add TypedPackedFunc #1626
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some small nits about English, the code looks good.
include/tvm/runtime/packed_func.h
Outdated
* | ||
* TypedPackedFunc enables compile time type checking. | ||
* TypedPackedFunc works with the runtime system: | ||
* - It can be passed as an argument of PackedFunc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing comma should be a period?
include/tvm/runtime/packed_func.h
Outdated
* - It can be assigned to TVMRetValue. | ||
* - It can be directly converted to a type-erased PackedFunc. | ||
* | ||
* Please use it when possible in the c++ code to enable more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like "Developers should prefer TypedPackedFunc over PackedFunc in C++ code as it enables compile time checking."
Are we going to use it in frontend language bindings? |
@yzhliu This is mainly for c++ backend code, in the frontend binding, what user see is mainly PackedFunc.
This being said, we can also try to support type signature for strongly typed language like java, if we have ways to dynamically build up the function(I do not know if that is possible). |
To follow up on what this might be helpful, currently, nnvm uses std::function for most of the operator attributes, which makes it hard to interchange between frontend(python) and backend. We want to upgrade the operator attribute system so that next version we can directly use PackedFunc, but we still want to have the std::function signature so that the c++ side of pass gives you strong type and compiler will hit an error when you mistakenly call it with wrong signature |
got it. thanks for explaining. |
TypedPackedFunc enables compile-time type checking. TypedPackedFunc works with the runtime system:
This allows us to write more typed code in c++ while taking benefit of PackedFunc that can be used interchangeably with frontend code.
Example