-
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
[TVMScript] T.allocate
with T.decl_buffer
syntax sugar for TVMScript printer
#13813
Conversation
fix outdated code fix outdated unittest `match_buffer` syntax sugar `T.allocate` and `T.decl_buffer` syntax sugar . fix
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
with T.allocate([128, 128], "float32", "global") as v: | ||
buffer = T.decl_buffer((256, 256), data=v) | ||
T.evaluate(v) |
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.
i think we could still do sugaring in this case, i.e.:
with T.decl_buffer((256, 256)) as buffer:
T.evaluate(buffer.data)
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! Please enhance the sugaring in a separate PR :-)
This PR is the follow up of #13813. We simplify the printing output of `T.allocate` with `T.decl_buffer`. For example, we have a code snippet as ```python buffer_data = T.allocate(...) buffer = T.decl_buffer(..., data=buffer_data) T.evaluate(buffer_data) ``` Originally, we skip the `T.allocate` only if the var `buffer_data` defined by `T.allocate` is used only once by the following `T.decl_buffer`. This was due to the limitation of the old printer design. But in the new printer, we may automatically replace the `buffer_data` with `buffer.data` if skipping the definition of `buffer_data`. We are able to link all `buffer_data` usages together. So the new output result will be like ```python buffer = T.decl_buffer(...) T.evaluate(buffer.data) ```
…ipt printer (apache#13813) This PR implements the syntax sugar of `T.allocate` with `T.decl_buffer` for new TVMScript printer. This syntax sugar will skip the `T.allocate`, when its body is a matched `T.decl_buffer`, and the `Var` defined in `T.allocate` is only used in that `T.decl_buffer`. For example, it will change ```python buffer_data = T.allocate([128, 128]) buffer = T.decl_buffer([128, 128], data=buffer_data) ``` into ```python buffer = T.decl_buffer([128, 128]) ``` but keep the following `T.allocate` unchanged: ```python buffer_data = T.allocate([128, 128]) buffer_0 = T.decl_buffer([128, 128], data=buffer_data) buffer_1 = T.decl_buffer([128, 128], data=buffer_data) ``` and ```python buffer_data = T.allocate([128, 128]) buffer = T.decl_buffer([256, 256], data=buffer_data) ```
This PR is the follow up of apache#13813. We simplify the printing output of `T.allocate` with `T.decl_buffer`. For example, we have a code snippet as ```python buffer_data = T.allocate(...) buffer = T.decl_buffer(..., data=buffer_data) T.evaluate(buffer_data) ``` Originally, we skip the `T.allocate` only if the var `buffer_data` defined by `T.allocate` is used only once by the following `T.decl_buffer`. This was due to the limitation of the old printer design. But in the new printer, we may automatically replace the `buffer_data` with `buffer.data` if skipping the definition of `buffer_data`. We are able to link all `buffer_data` usages together. So the new output result will be like ```python buffer = T.decl_buffer(...) T.evaluate(buffer.data) ```
This PR implements the syntax sugar of
T.allocate
withT.decl_buffer
for new TVMScript printer. This syntax sugar will skip theT.allocate
, when its body is a matchedT.decl_buffer
, and theVar
defined inT.allocate
is only used in thatT.decl_buffer
. For example, it will changeinto
but keep the following
T.allocate
unchanged:and