You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by tq...@apache.org on 2023/06/20 23:24:25 UTC

[tvm] branch unity updated: [Unity] Minor fix to `RewriteDataflowReshape` condition (#15125)

This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/unity by this push:
     new 0a672548e8 [Unity] Minor fix to `RewriteDataflowReshape` condition  (#15125)
0a672548e8 is described below

commit 0a672548e809360f4c520745faa55e2b9aa7c7bd
Author: masahi <ma...@gmail.com>
AuthorDate: Wed Jun 21 08:24:18 2023 +0900

    [Unity] Minor fix to `RewriteDataflowReshape` condition  (#15125)
---
 src/relax/transform/rewrite_dataflow_reshape.cc       |  7 ++-----
 .../relax/test_transform_rewrite_dataflow_reshape.py  | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/relax/transform/rewrite_dataflow_reshape.cc b/src/relax/transform/rewrite_dataflow_reshape.cc
index 796b761a16..2053a56bb7 100644
--- a/src/relax/transform/rewrite_dataflow_reshape.cc
+++ b/src/relax/transform/rewrite_dataflow_reshape.cc
@@ -72,7 +72,8 @@ class DataflowReshapeRewriter : public ExprMutator {
   }
 
   Expr VisitExpr_(const CallNode* call) final {
-    if (call->args.size() < 2) {
+    static const Op& call_tir_op = Op::Get("relax.call_tir");
+    if (call->op != call_tir_op) {
       return GetRef<Call>(call);
     }
 
@@ -103,10 +104,6 @@ class DataflowReshapeRewriter : public ExprMutator {
   }
 
   bool IsCallingTIRReshape(const CallNode* call, Expr inp) {
-    static const Op& call_tir_op = Op::Get("relax.call_tir");
-    if (call->op != call_tir_op) {
-      return false;
-    }
     const GlobalVar& global_var = Downcast<GlobalVar>(call->args[0]);
     const auto* func = mod_->functions.Get(global_var).as<tir::PrimFuncNode>();
     ICHECK_NOTNULL(func);
diff --git a/tests/python/relax/test_transform_rewrite_dataflow_reshape.py b/tests/python/relax/test_transform_rewrite_dataflow_reshape.py
index 3a3da3a7dc..b02663e5eb 100644
--- a/tests/python/relax/test_transform_rewrite_dataflow_reshape.py
+++ b/tests/python/relax/test_transform_rewrite_dataflow_reshape.py
@@ -427,5 +427,24 @@ def test_invalid_reshape():
     tvm.ir.assert_structural_equal(rewritten, Module)
 
 
+def test_reshape_detect_nop():
+    @tvm.script.ir_module
+    class Module:
+        @R.function
+        def main(x: R.Tensor((8, 8), dtype="float16")) -> R.Tensor((8, 8), dtype="float16"):
+            with R.dataflow():
+                gv = R.call_pure_packed(
+                    "foo", x, x, sinfo_args=(R.Tensor((8, 8), dtype="float16"),)
+                )
+                out = R.call_pure_packed(
+                    "foo", gv, gv, sinfo_args=(R.Tensor((8, 8), dtype="float16"),)
+                )
+                R.output(out)
+            return out
+
+    rewritten = relax.transform.RewriteDataflowReshape()(Module)
+    tvm.ir.assert_structural_equal(rewritten, Module)
+
+
 if __name__ == "__main__":
     tvm.testing.main()