You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/08/24 20:53:09 UTC

[GitHub] [tvm] wrongtest-intellif commented on a diff in pull request #12572: [TIR] Preserve annotations after lower opaque block

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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org