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

[TVMScript] T.allocate with T.decl_buffer syntax sugar for TVMScript printer #13813

Merged
merged 1 commit into from
Jan 20, 2023

Conversation

cyx-6
Copy link
Contributor

@cyx-6 cyx-6 commented Jan 20, 2023

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

buffer_data = T.allocate([128, 128])
buffer = T.decl_buffer([128, 128], data=buffer_data)

into

buffer = T.decl_buffer([128, 128])

but keep the following T.allocate unchanged:

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

buffer_data = T.allocate([128, 128])
buffer = T.decl_buffer([256, 256], data=buffer_data)

fix outdated code

fix outdated unittest

`match_buffer` syntax sugar

`T.allocate` and `T.decl_buffer` syntax sugar

.


fix
@tvm-bot
Copy link
Collaborator

tvm-bot commented Jan 20, 2023

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

Comment on lines +371 to +373
with T.allocate([128, 128], "float32", "global") as v:
buffer = T.decl_buffer((256, 256), data=v)
T.evaluate(v)
Copy link
Member

@junrushao junrushao Jan 20, 2023

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)

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! Please enhance the sugaring in a separate PR :-)

@junrushao junrushao merged commit 8f80e42 into apache:main Jan 20, 2023
junrushao pushed a commit that referenced this pull request Jan 24, 2023
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)
```
fzi-peccia pushed a commit to fzi-peccia/tvm that referenced this pull request Mar 27, 2023
…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)
```
fzi-peccia pushed a commit to fzi-peccia/tvm that referenced this pull request Mar 27, 2023
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)
```
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.

3 participants