[NODE][REFACTOR] Rename IRFunctor->NodeFunctor, use func pointer - #4247
Merged
Conversation
…for dispatching. Previously we used std::function for the functor dispatching. It introduces additional overhead and problems during dll destruction(of std::function). This PR changes the std::function to function pointers. This change a bit restrictions around the set_dispatch that we can get around, but will improve the general efficiency by reducing one level of indirection in the std::function. We also no longer need special marcos to register functions to the Functor.
Member
Author
zhiics
reviewed
Nov 1, 2019
| */ | ||
| R operator()(const ObjectRef& n, Args... args) const { | ||
| uint32_t type_index = n->type_index(); | ||
| CHECK(type_index < func_.size() && |
| return type_index < func_.size() && func_[type_index] != nullptr; | ||
| } | ||
| /*! | ||
| * \brief invoke the functor , dispatch on type of n |
Member
There was a problem hiding this comment.
Suggested change
| * \brief invoke the functor , dispatch on type of n | |
| * \brief invoke the functor, dispatch on type of n |
| * | ||
| * \code | ||
| * // Use NodeFunctor to implement IRPrinter similar to Visitor Pattern. | ||
| * // vtable allows easy patch in of new Node types, without changing |
Member
There was a problem hiding this comment.
Suggested change
| * // vtable allows easy patch in of new Node types, without changing | |
| * // vtable allows easy patch of new Node types, without changing |
Member
Author
|
Thanks @zhiics i have updated per your comment |
zhiics
reviewed
Nov 1, 2019
| CHECK(can_dispatch(n)) | ||
| << "NodeFunctor calls un-registered function on type " | ||
| << n->GetTypeKey(); | ||
| return (*func_[type_index])(n, std::forward<Args>(args)...); |
Member
There was a problem hiding this comment.
s/type_index/n->type_index()
This is probably the error.
Member
Author
|
Thanks @zhiics |
zxy844288792
pushed a commit
to neo-ai/tvm
that referenced
this pull request
Nov 13, 2019
…che#4247) * [NODE][REFACTOR] Rename IRFunctor->NodeFunctor, use function pointer for dispatching. Previously we used std::function for the functor dispatching. It introduces additional overhead and problems during dll destruction(of std::function). This PR changes the std::function to function pointers. This change a bit restrictions around the set_dispatch that we can get around, but will improve the general efficiency by reducing one level of indirection in the std::function. We also no longer need special marcos to register functions to the Functor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously we used std::function for the functor dispatching.
It introduces additional overhead and problems during dll destruction(of std::function).
This PR changes the std::function to function pointers.
This change a bit restrictions around the set_dispatch that we can get around,
but will improve the general efficiency by reducing one level of indirection in the std::function.
We also no longer need special marcos to register functions to the Functor.