-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[TVMScript] Support inlined function call as a sugar #11324
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
Conversation
|
That seems so cool. Is this functionality under the scope of meta-programming? |
yeah, I'd say this is the simplest kind of a macro. I'm literally calling the python function inside the parser. |
Hzfengsy
left a comment
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.
What will happen if the function body is not supported by TVM? like
def f(x):
return np.sum(x)
Can we check it and report error?
c57e26d to
7c188e0
Compare
|
@Hzfengsy Thanks for the suggestion. I wrapped the func call with I couldn't make a good test case, but this is an example of an err msg when a user tries a funky function call: |
7c188e0 to
7036f59
Compare
7036f59 to
5fdd335
Compare
Hzfengsy
left a comment
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.
LGTM
I came across a use case where being able to call a python function as a sugar to construct AST fragments is extremely handy.
The attached test case illustrates two ways of describing the same TVMScript function, one of which is using the proposed syntax sugar. Here, the called function does some complicated index transformation - Calling a function to construct such mapping, rather than spelling them out by hand, significantly cleans up the TVMScript description.
Moreover, since the index map is just a normal python function, it can also be used in the layout transformation primitive in a schedule:
This way, we can be sure that tensorize pattern matching will not fail, since the intrinsic description (written in TVMScript) and the schedule are using exactly the same index map. Without this capability, we need to keep the index map used in a schedule and its explicit description in TVMScript always in sync manually.
Note:
@Hzfengsy @spectrometerHBH @vinx13 @junrushao1994 @Lunderberg @csullivan