junrushao commented on code in PR #12572:
URL: https://github.com/apache/tvm/pull/12572#discussion_r953857171
##########
tests/python/unittest/test_tir_transform_lower_opaque_block.py:
##########
@@ -321,6 +321,47 @@ def test_annotated_loops():
tvm.ir.assert_structural_equal(attr3.value, tvm.tir.FloatImm("float32",
0.0))
+def test_annotated_block():
+ @T.prim_func
+ def annotated_block() -> None:
+ with T.block():
+ T.block_attr({"pragma_1": "str_value", "pragma_2": 1, "pragma_3":
0.0})
+ T.evaluate(0)
+
+ mod = tvm.IRModule.from_expr(annotated_block)
+ mod = tvm.tir.transform.LowerOpaqueBlock()(mod)
+ attr1 = mod["main"].body
+ attr2 = attr1.body
+ attr3 = attr2.body
+ assert attr1.attr_key == "pragma_1" and attr1.value == "str_value"
+ assert attr2.attr_key == "pragma_2"
+ tvm.ir.assert_structural_equal(attr2.value, tvm.tir.IntImm("int32", 1))
+ assert attr3.attr_key == "pragma_3"
+ tvm.ir.assert_structural_equal(attr3.value, tvm.tir.FloatImm("float32",
0.0))
+
+
+def test_preserved_annotations():
+ @T.prim_func
+ def before(A: T.Buffer[8, "float32"], B: T.Buffer[8, "float32"]):
+ for i in T.serial(8, annotations={"k_0": 1, "k_1": [2, 3], "k_2": 4}):
+ with T.block("block"):
+ T.block_attr({"k_3": 3.14, "k_4": ""})
+ B[i] = A[i] + 1.0
+
+ @T.prim_func
+ def after(A: T.Buffer[8, "float32"], B: T.Buffer[8, "float32"]):
+ for i in T.serial(8, annotations={"k_0": 1, "k_1": [2, 3]}):
+ for _ in range(1, annotations={"k_3": 3.14}):
Review Comment:
I'm a bit uncertain if haivng an AttrStmt might make sense in our workflow,
given it's something in the low-level TIR that we might want to minimize its
usage (CC: @tqchen). I'm aware that there could be any implications if we
directly remove a unit loop without preserving its annotation too. Not sure
what the best approach is.
--
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]