junrushao commented on code in PR #13813:
URL: https://github.com/apache/tvm/pull/13813#discussion_r1082269934
##########
tests/python/unittest/test_tvmscript_printer_tir.py:
##########
@@ -327,6 +328,53 @@ def test_allocate():
)
+def test_allocate_with_decl_buffer_sugar():
+ with IRBuilder() as ib:
+ with T.allocate([128, 128], "float32") as buffer_data:
+ with T.decl_buffer([128, 128], "float32", data=buffer_data) as
buffer:
+ T.evaluate(0)
+ obj = ib.get()
+ _assert_print(
+ obj,
+ """
+with T.decl_buffer((128, 128)) as buffer:
+ T.evaluate(0)
+""",
+ )
+
+
+def test_allocate_with_decl_buffer_no_sugar_multi_usage():
+ with IRBuilder() as ib:
+ with T.allocate([128, 128], "float32") as buffer_data:
+ with T.decl_buffer([128, 128], "float32", data=buffer_data) as
buffer:
+ T.evaluate(buffer_data)
+ obj = ib.get()
+ _assert_print(
+ obj,
+ """
+with T.allocate([128, 128], "float32", "global") as v:
+ buffer = T.decl_buffer((128, 128), data=v)
+ T.evaluate(v)
+""",
+ )
+
+
+def test_allocate_with_decl_buffer_no_sugar_mismatch():
+ with IRBuilder() as ib:
+ with T.allocate([128, 128], "float32") as buffer_data:
+ with T.decl_buffer([256, 256], "float32", data=buffer_data) as
buffer:
+ T.evaluate(buffer_data)
+ obj = ib.get()
+ _assert_print(
+ obj,
+ """
+with T.allocate([128, 128], "float32", "global") as v:
+ buffer = T.decl_buffer((256, 256), data=v)
+ T.evaluate(v)
Review Comment:
i think we could still do sugaring in this case, i.e.:
```python
with T.decl_buffer((256, 256), data=v) as buffer:
T.evaluate(buffer.data)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]