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 2021/03/05 14:31:54 UTC

[GitHub] [tvm] leeexyz opened a new pull request #7602: [TE] Fix bug in AutoInlineElemWise and implement AutoInlineBroadcast

leeexyz opened a new pull request #7602:
URL: https://github.com/apache/tvm/pull/7602


   Hi Community,
   
   When I try to use the auto inline functions, I found that one for element-wise is not working due to the wrong **VisitExpr_**, it should be **ProducerLoadNode** not **CallNode**. And I also implement the broadcast one by simply checking the **tag**, cause ops in Topi has the specified tag.
   
   @comaniac @ZihengJiang @tqchen Please help to review, thanks!


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

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



[GitHub] [tvm] comaniac commented on a change in pull request #7602: [TE] Fix bug in AutoInlineElemWise and implement AutoInlineBroadcast

Posted by GitBox <gi...@apache.org>.
comaniac commented on a change in pull request #7602:
URL: https://github.com/apache/tvm/pull/7602#discussion_r589194466



##########
File path: tests/python/unittest/test_te_schedule_ops.py
##########
@@ -110,19 +110,53 @@ def argmax_init(idx_typ, val_typ):
 
 
 def test_auto_inline():
-    m = te.var("m")
-    n = te.var("n")
-    A = te.placeholder((m, n), name="A")
-    B = te.placeholder((m, n), name="B")
-    C = te.placeholder((m, n), name="C")
-    T1 = te.compute((m, n), lambda i, j: A(i, j) * B(i, j), name="T1")
-    T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
-
-    s = te.create_schedule(T2.op)
-    tvm.te.schedule.AutoInlineElemWise(s)
-    s = s.normalize()
-    bounds = tvm.te.schedule.InferBound(s)
-    stmt = tvm.te.schedule.ScheduleOps(s, bounds)
+    def elemwise():
+        m = te.var("m")
+        n = te.var("n")
+        A = te.placeholder((m, n), name="A")
+        B = te.placeholder((m, n), name="B")
+        C = te.placeholder((m, n), name="C")
+        T1 = te.compute((m, n), lambda i, j: A(i, j) * B(i, j), name="T1")
+        T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
+
+        return te.create_schedule(T2.op), T1
+
+    def broadcast():
+        m = te.var("m")
+        n = te.var("n")
+        A = te.placeholder((1,), name="A")
+        B = te.placeholder((m, n), name="B")
+        C = te.placeholder((m, n), name="C")
+        T1 = te.compute((m, n), lambda i, j: A(0) * B(i, j), name="T1", tag="broadcast")
+        T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
+
+        return te.create_schedule(T2.op), T1
+
+    def injective():
+        m = te.var("m")
+        n = te.var("n")
+        A = te.placeholder((m,), name="A")
+        B = te.placeholder((m, n), name="B")
+        C = te.placeholder((m, n), name="C")
+        T1 = te.compute((m, n), lambda i, j: A(i) * B(i, j), name="T1")
+        T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
+
+        return te.create_schedule(T2.op), T1
+
+    def check_auto_inline(schedule_func, auto_inline_func):
+        s, T1 = schedule_func()
+        # before auto inline the attach type is AttachType.kGroupRoot
+        assert s[T1].attach_type == 1
+        auto_inline_func(s)
+        # after auto inline the attach type is AttachType.kInline
+        assert s[T1].attach_type == 2
+        s = s.normalize()
+        bounds = tvm.te.schedule.InferBound(s)
+        stmt = tvm.te.schedule.ScheduleOps(s, bounds)

Review comment:
       Is there any way to check `stmt`?




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

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



[GitHub] [tvm] leeexyz commented on a change in pull request #7602: [TE] Fix bug in AutoInlineElemWise and implement AutoInlineBroadcast

Posted by GitBox <gi...@apache.org>.
leeexyz commented on a change in pull request #7602:
URL: https://github.com/apache/tvm/pull/7602#discussion_r589192598



##########
File path: src/te/schedule/auto_inline_elem_wise.cc
##########
@@ -113,6 +117,8 @@ void AutoInlineInjective(Schedule sch) {
 
 TVM_REGISTER_GLOBAL("schedule.AutoInlineElemWise").set_body_typed(AutoInlineElemWise);
 
+TVM_REGISTER_GLOBAL("schedule.AutoInlineBroadcast").set_body_typed(AutoInlineBroadcast);

Review comment:
       > Also add an interface to `tvm/te/schedule_pass.h`.
   
   Thanks! The API was added.




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

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



[GitHub] [tvm] leeexyz commented on a change in pull request #7602: [TE] Fix bug in AutoInlineElemWise and implement AutoInlineBroadcast

Posted by GitBox <gi...@apache.org>.
leeexyz commented on a change in pull request #7602:
URL: https://github.com/apache/tvm/pull/7602#discussion_r589219271



##########
File path: tests/python/unittest/test_te_schedule_ops.py
##########
@@ -110,19 +110,53 @@ def argmax_init(idx_typ, val_typ):
 
 
 def test_auto_inline():
-    m = te.var("m")
-    n = te.var("n")
-    A = te.placeholder((m, n), name="A")
-    B = te.placeholder((m, n), name="B")
-    C = te.placeholder((m, n), name="C")
-    T1 = te.compute((m, n), lambda i, j: A(i, j) * B(i, j), name="T1")
-    T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
-
-    s = te.create_schedule(T2.op)
-    tvm.te.schedule.AutoInlineElemWise(s)
-    s = s.normalize()
-    bounds = tvm.te.schedule.InferBound(s)
-    stmt = tvm.te.schedule.ScheduleOps(s, bounds)
+    def elemwise():
+        m = te.var("m")
+        n = te.var("n")
+        A = te.placeholder((m, n), name="A")
+        B = te.placeholder((m, n), name="B")
+        C = te.placeholder((m, n), name="C")
+        T1 = te.compute((m, n), lambda i, j: A(i, j) * B(i, j), name="T1")
+        T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
+
+        return te.create_schedule(T2.op), T1
+
+    def broadcast():
+        m = te.var("m")
+        n = te.var("n")
+        A = te.placeholder((1,), name="A")
+        B = te.placeholder((m, n), name="B")
+        C = te.placeholder((m, n), name="C")
+        T1 = te.compute((m, n), lambda i, j: A(0) * B(i, j), name="T1", tag="broadcast")
+        T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
+
+        return te.create_schedule(T2.op), T1
+
+    def injective():
+        m = te.var("m")
+        n = te.var("n")
+        A = te.placeholder((m,), name="A")
+        B = te.placeholder((m, n), name="B")
+        C = te.placeholder((m, n), name="C")
+        T1 = te.compute((m, n), lambda i, j: A(i) * B(i, j), name="T1")
+        T2 = te.compute((m, n), lambda i, j: T1(i, j) + C(i, j), name="T2")
+
+        return te.create_schedule(T2.op), T1
+
+    def check_auto_inline(schedule_func, auto_inline_func):
+        s, T1 = schedule_func()
+        # before auto inline the attach type is AttachType.kGroupRoot
+        assert s[T1].attach_type == 1
+        auto_inline_func(s)
+        # after auto inline the attach type is AttachType.kInline
+        assert s[T1].attach_type == 2
+        s = s.normalize()
+        bounds = tvm.te.schedule.InferBound(s)
+        stmt = tvm.te.schedule.ScheduleOps(s, bounds)

Review comment:
       > Is there any way to check `stmt`?
   
   Yes, check **IR** structure is an option, like if the inlined ProducerRealizeNode is still there. But is it a bit redundant? Cause we already checked the **attach_type**.




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

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



[GitHub] [tvm] comaniac commented on pull request #7602: [TE] Fix bug in AutoInlineElemWise and implement AutoInlineBroadcast

Posted by GitBox <gi...@apache.org>.
comaniac commented on pull request #7602:
URL: https://github.com/apache/tvm/pull/7602#issuecomment-792947922


   Thanks @leeexyz @jcf94 


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

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



[GitHub] [tvm] jcf94 commented on a change in pull request #7602: [TE] Fix bug in AutoInlineElemWise and implement AutoInlineBroadcast

Posted by GitBox <gi...@apache.org>.
jcf94 commented on a change in pull request #7602:
URL: https://github.com/apache/tvm/pull/7602#discussion_r589142702



##########
File path: src/te/schedule/auto_inline_elem_wise.cc
##########
@@ -113,6 +117,8 @@ void AutoInlineInjective(Schedule sch) {
 
 TVM_REGISTER_GLOBAL("schedule.AutoInlineElemWise").set_body_typed(AutoInlineElemWise);
 
+TVM_REGISTER_GLOBAL("schedule.AutoInlineBroadcast").set_body_typed(AutoInlineBroadcast);

Review comment:
       Also add an interface to `tvm/te/schedule_pass.h`.




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

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



[GitHub] [tvm] comaniac merged pull request #7602: [TE] Fix bug in AutoInlineElemWise and implement AutoInlineBroadcast

Posted by GitBox <gi...@apache.org>.
comaniac merged pull request #7602:
URL: https://github.com/apache/tvm/pull/7602


   


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

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