wrongtest-intellif commented on code in PR #12572:
URL: https://github.com/apache/tvm/pull/12572#discussion_r954289719


##########
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}):
+                B[i] = A[i] + T.float32(1)
+
+    mod = tvm.IRModule.from_expr(before)
+    with tvm.transform.PassContext(
+        config={"tir.LowerOpaqueBlock": {"preserved_annotations": ["k_0", 
"k_1", "k_3"]}}

Review Comment:
   A tracing of usages in current `test_tir_` and `test_meta_schedule_` show 
that for loop annotations, only software pipeline specified keys are used, they 
are consumed before lower opaque block. The other keys are mostly 
`meta_schedule.*` in block annotations.
   
   What about that for non-pragma keys? 
   - Always preserve loop annotations. 
   
   - Always drop block annotations, since they are mostly designed for 
meta-schedule thus make no sense to subsequent passes, and it seems not clear 
now how to lower the block's attrs after blocks get eliminated. 
   
   For my circumstance the loop annotations are quite useful while block 
annotations are not used for lowering passes. Could the decision about block 
annotation get delayed to when it is indeed needed :)?
   



-- 
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]

Reply via email to