You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "LeshengJin (via GitHub)" <gi...@apache.org> on 2023/06/29 18:15:50 UTC

[GitHub] [tvm] LeshengJin opened a new pull request, #15184: [Unity] Legalization for LayoutTransform

LeshengJin opened a new pull request, #15184:
URL: https://github.com/apache/tvm/pull/15184

   This pr implements layout_transform legalization mentioned in https://discuss.tvm.apache.org/t/codegen-support-for-relax-layout-transform/15187.


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


[GitHub] [tvm] tqchen merged pull request #15184: [Unity] Legalization for LayoutTransform

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen merged PR #15184:
URL: https://github.com/apache/tvm/pull/15184


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


[GitHub] [tvm] LeshengJin commented on a diff in pull request #15184: [Unity] Legalization for LayoutTransform

Posted by "LeshengJin (via GitHub)" <gi...@apache.org>.
LeshengJin commented on code in PR #15184:
URL: https://github.com/apache/tvm/pull/15184#discussion_r1248309101


##########
python/tvm/relax/transform/legalize_ops/manipulate.py:
##########
@@ -163,3 +163,30 @@ def _scatter_elements(bb: BlockBuilder, call: Call) -> Expr:
         call.attrs.axis,
         call.attrs.reduction,
     )
+
+
+@register_legalize("relax.layout_transform")
+def _layout_transform(bb: BlockBuilder, call: Call) -> Expr:
+    index_map: tvm.tir.IndexMap = call.attrs.index_map
+    pad_value = call.attrs.pad_value.value
+
+    def te_layout_transform(data):
+        inverse, padding_predicate = index_map.non_surjective_inverse(data.shape)
+        output_shape = index_map.map_shape(data.shape)
+        return te.compute(
+            output_shape,
+            lambda *idx: tvm.te.if_then_else(

Review Comment:
   Yes, that's better. Added an if-else statement to check if the predicated is 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


[GitHub] [tvm] psrivas2 commented on a diff in pull request #15184: [Unity] Legalization for LayoutTransform

Posted by "psrivas2 (via GitHub)" <gi...@apache.org>.
psrivas2 commented on code in PR #15184:
URL: https://github.com/apache/tvm/pull/15184#discussion_r1247093272


##########
tests/python/relax/test_transform_legalize_ops_manipulate.py:
##########
@@ -1522,5 +1522,45 @@ def main(
     tvm.ir.assert_structural_equal(mod, Expected)
 
 
+def test_layout_transform():
+    transformation = lambda a, b, c: (a, c, b // 3, b % 3)
+    pad_value = 2
+    # fmt: off
+    @I.ir_module
+    class LayoutTransform:
+        @R.function
+        def main(x: R.Tensor((10, 20, 30), "float32")):

Review Comment:
   should we also add a test case with symbolic dimensions? 



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


[GitHub] [tvm] tvm-bot commented on pull request #15184: [Unity] Legalization for LayoutTransform

Posted by "tvm-bot (via GitHub)" <gi...@apache.org>.
tvm-bot commented on PR #15184:
URL: https://github.com/apache/tvm/pull/15184#issuecomment-1613595941

   <!---bot-comment-->
   
   Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from [Reviewers](https://github.com/apache/incubator-tvm/blob/master/CONTRIBUTORS.md#reviewers) by @-ing them in a comment.
   
   <!--bot-comment-ccs-start-->
    * cc @quic-sanirudh <sub>See [#10317](https://github.com/apache/tvm/issues/10317) for details</sub><!--bot-comment-ccs-end-->
   
   <sub>Generated by [tvm-bot](https://github.com/apache/tvm/blob/main/ci/README.md#github-actions)</sub>


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


[GitHub] [tvm] LeshengJin commented on a diff in pull request #15184: [Unity] Legalization for LayoutTransform

Posted by "LeshengJin (via GitHub)" <gi...@apache.org>.
LeshengJin commented on code in PR #15184:
URL: https://github.com/apache/tvm/pull/15184#discussion_r1247669389


##########
tests/python/relax/test_transform_legalize_ops_manipulate.py:
##########
@@ -1522,5 +1522,45 @@ def main(
     tvm.ir.assert_structural_equal(mod, Expected)
 
 
+def test_layout_transform():
+    transformation = lambda a, b, c: (a, c, b // 3, b % 3)
+    pad_value = 2
+    # fmt: off
+    @I.ir_module
+    class LayoutTransform:
+        @R.function
+        def main(x: R.Tensor((10, 20, 30), "float32")):

Review Comment:
   Good idea! Have added a symbolic shape test case.



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


[GitHub] [tvm] vinx13 commented on a diff in pull request #15184: [Unity] Legalization for LayoutTransform

Posted by "vinx13 (via GitHub)" <gi...@apache.org>.
vinx13 commented on code in PR #15184:
URL: https://github.com/apache/tvm/pull/15184#discussion_r1248175247


##########
python/tvm/relax/transform/legalize_ops/manipulate.py:
##########
@@ -163,3 +163,30 @@ def _scatter_elements(bb: BlockBuilder, call: Call) -> Expr:
         call.attrs.axis,
         call.attrs.reduction,
     )
+
+
+@register_legalize("relax.layout_transform")
+def _layout_transform(bb: BlockBuilder, call: Call) -> Expr:
+    index_map: tvm.tir.IndexMap = call.attrs.index_map
+    pad_value = call.attrs.pad_value.value
+
+    def te_layout_transform(data):
+        inverse, padding_predicate = index_map.non_surjective_inverse(data.shape)
+        output_shape = index_map.map_shape(data.shape)
+        return te.compute(
+            output_shape,
+            lambda *idx: tvm.te.if_then_else(

Review Comment:
   shall we simplified if_then_else when the predicate is not 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