Skip to content

[TVMScript] Allow val = buf[index] without type annotation#11060

Merged
vinx13 merged 2 commits intoapache:mainfrom
Lunderberg:tvmscript_bufferload_without_annotation
Apr 21, 2022
Merged

[TVMScript] Allow val = buf[index] without type annotation#11060
vinx13 merged 2 commits intoapache:mainfrom
Lunderberg:tvmscript_bufferload_without_annotation

Conversation

@Lunderberg
Copy link
Contributor

Other instances of var = expr were previously allowed without requiring a type annotation, by using the dtype of the expression as the dtype of var. This behavior didn't work for buf[index] expressions, which are internally represented as BufferSlice python objects, and only converted to BufferLoad primexprs when used as an expression.

This commit adds a dtype property to BufferSlice, allowing buf[index] to be used in a let statement without a type annotation.

Copy link
Contributor

@MasterJH5574 MasterJH5574 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for the fix! Would you like to do a rebase to retrigger the CI?

Other instances of `var = expr` were previously allowed without
requiring a type annotation, by using the dtype of the expression as
the dtype of `var`.  This behavior didn't work for `buf[index]`
expressions, which are internally represented as `BufferSlice` python
objects, and only converted to `BufferLoad` primexprs when used as an
expression.

This commit adds a `dtype` property to `BufferSlice`, allowing
`buf[index]` to be used in a let statement without a type annotation.
Automatically adding a type annotation to Var if it could be
determined from the dtype let the unit test directly compare the
annotated and unannotated versions of buffer load.  Unfortunately, it
also broke 54 unrelated tests, so that change is removed from this PR.
@Lunderberg Lunderberg force-pushed the tvmscript_bufferload_without_annotation branch from 5986c79 to a8fb90f Compare April 21, 2022 14:18
@Lunderberg
Copy link
Contributor Author

Certainly! Rebased, and CI is re-running.

@vinx13 vinx13 merged commit ba4cc6c into apache:main Apr 21, 2022
@Lunderberg Lunderberg deleted the tvmscript_bufferload_without_annotation branch April 21, 2022 18:49
shtinsa pushed a commit to Deelvin/tvm that referenced this pull request May 17, 2022
…11060)

* [TVMScript] Allow `val = buf[index]` without type annotation

Other instances of `var = expr` were previously allowed without
requiring a type annotation, by using the dtype of the expression as
the dtype of `var`.  This behavior didn't work for `buf[index]`
expressions, which are internally represented as `BufferSlice` python
objects, and only converted to `BufferLoad` primexprs when used as an
expression.

This commit adds a `dtype` property to `BufferSlice`, allowing
`buf[index]` to be used in a let statement without a type annotation.

* Reverted a wider change

Automatically adding a type annotation to Var if it could be
determined from the dtype let the unit test directly compare the
annotated and unannotated versions of buffer load.  Unfortunately, it
also broke 54 unrelated tests, so that change is removed from this PR.
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