You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by "Biubiubiu12 (via GitHub)" <gi...@apache.org> on 2023/07/10 03:37:10 UTC

[GitHub] [tvm] Biubiubiu12 opened a new pull request, #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   The original blockize will change the original structure of tir, so use the pass method to traverse and modify each block.


-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {

Review Comment:
   No, in the recursive process of `loop`, `in_lca` may become `true` in "condition with line 595", and the information of `xx.push_back(loop->extent)` will not be `xx.pop_back()`, you can think of it as a stack.



-- 
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] wrongtest-intellif commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

Posted by "wrongtest-intellif (via GitHub)" <gi...@apache.org>.
wrongtest-intellif commented on code in PR #15274:
URL: https://github.com/apache/tvm/pull/15274#discussion_r1269325874


##########
tests/python/unittest/test_tir_schedule_blockize.py:
##########
@@ -354,5 +355,168 @@ def after_blocks_blockize(
     verify_trace_roundtrip(sch=s, mod=blocks_func)
 
 
+def test_blockize_blocks_v1():

Review Comment:
   Could we depict what this script do, is it an auto-generated script or a certain cv algorithm?



##########
tests/python/unittest/test_tir_schedule_blockize.py:
##########
@@ -354,5 +355,168 @@ def after_blocks_blockize(
     verify_trace_roundtrip(sch=s, mod=blocks_func)
 
 
+def test_blockize_blocks_v1():
+    @T.prim_func
+    def blocks_func(concat_mat: T.Buffer((9, 9), "float32"), out: T.Buffer((3, 3), "float32")):
+        temp_buffer = T.alloc_buffer((18,))
+        j = T.alloc_buffer((1,), "int32")
+        for m, i in T.grid(3, 9):
+            j[0] = 1
+            for k in range(9):
+                if concat_mat[i, i] == T.float32(0) and i + j[0] < 9:
+                    for iter in range(18):
+                        with T.block("auto_0"):
+                            poly_m = T.axis.opaque(3, m)
+                            poly_i = T.axis.opaque(9, i)
+                            poly_k = T.axis.opaque(9, k)
+                            poly_iter = T.axis.spatial(18, iter)
+                            T.reads(
+                                concat_mat[
+                                    T.min(poly_i, poly_i + j[0]) : T.min(poly_i, poly_i + j[0])

Review Comment:
   what does the prefix "poly_" means?



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {

Review Comment:
   Please depict what this visitor do in comments.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {

Review Comment:
   It is to collect the external loop information of the common ancestor of the block list, and to replace some block and loop variables in BlockizeBlocks



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;

Review Comment:
   No, it is to ensure that `in_lca` is reinitialized to false after traversing lca, preventing `VisitStmt_(const BlockNode* block)` from processing the ir behind lca.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;

Review Comment:
   Var::copy_with_suffix can only add a string at the end. We hope that the IterVar of the external block is added with 'v' in front, and the IterVar of the internal block is added with '_i', which is more recognizable.



-- 
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] Hzfengsy commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   cc @MasterJH5574 @vinx13 


-- 
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 #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   <!---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 @Hzfengsy, @junrushao, @quic-sanirudh, @shingjan <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] Biubiubiu12 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   > Maybe offtopic question: Are/Will OpenCV operators (tscript) that you work on be public somewhere ?
   
   Yes, TVMScript is part of the implementation of some CV operator, but I forgot which operator.


-- 
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] Biubiubiu12 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   > Hi @Biubiubiu12 , thanks for the contribution, would you mind explaining more about the expected behavior of your PR?
   > 
   > I noticed a unit test but it's still not clear what the semantic is. It would be better if you can leave some explanations.
   
   Hi @yzh119 ,Thank you for your reply. In the process of developing OpenCV operators with TVMScript, there will be complex block nesting. We hope to use blockize to deal with it without changing the nesting relationship between blocks. I have added related unit tests to better explain the situation.


-- 
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] yzh119 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   Hi @Biubiubiu12 , thanks for the contribution, would you mind explaining more about the expected behavior of your PR?
   
   I noticed a unit test but it's still not clear what the semantic is. It would be better if you can leave some explanations.


-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);

Review Comment:
   buffer_order is to ensure the order of traversing the `intset_map` dictionary, and there may be duplicate values in `regions[i]->buffer`



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;
+        return;
+      }
+    }
+    StmtVisitor::VisitStmt_(block);
+  }
+
+  ScheduleState self_;
+  StmtSRef lca_;
+  Array<IterVar>* outer_iter_vars_;
+  Array<PrimExpr>* outer_bindings_;
+  Array<IterVar>* inner_iter_vars_;
+  Array<PrimExpr>* inner_bindings_;
+  Map<Var, PrimExpr>* block_var_subst_;
+  Array<PrimExpr> out_extent{nullptr};

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {

Review Comment:
   Now, we explicitly check by saving the `outer_extent `of` loop->extent`, `ICHECK(ana.CanProveEqual(outer_extent[i], iter_var->dom->extent))`.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;

Review Comment:
   In order to collect the `iter_vars` of externally generated blocks, please refer to L432 in test.Because this information only needs to be collected once, use `num_outer_iter_vars == 0` to judge. The maximum value of `num_outer_iter_vars` is the size of the input `Array<StmtSRef>& block_srefs`.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;
+        return;
+      }
+    }
+    StmtVisitor::VisitStmt_(block);
+  }
+
+  ScheduleState self_;
+  StmtSRef lca_;
+  Array<IterVar>* outer_iter_vars_;
+  Array<PrimExpr>* outer_bindings_;
+  Array<IterVar>* inner_iter_vars_;
+  Array<PrimExpr>* inner_bindings_;
+  Map<Var, PrimExpr>* block_var_subst_;
+  Array<PrimExpr> out_extent{nullptr};

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   Hi, cc @yzh119 ,CI has already passed, please help me 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.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

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


[GitHub] [tvm] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
tests/python/unittest/test_tir_schedule_blockize.py:
##########
@@ -354,5 +355,168 @@ def after_blocks_blockize(
     verify_trace_roundtrip(sch=s, mod=blocks_func)
 
 
+def test_blockize_blocks_v1():
+    @T.prim_func
+    def blocks_func(concat_mat: T.Buffer((9, 9), "float32"), out: T.Buffer((3, 3), "float32")):
+        temp_buffer = T.alloc_buffer((18,))
+        j = T.alloc_buffer((1,), "int32")
+        for m, i in T.grid(3, 9):
+            j[0] = 1
+            for k in range(9):
+                if concat_mat[i, i] == T.float32(0) and i + j[0] < 9:
+                    for iter in range(18):
+                        with T.block("auto_0"):
+                            poly_m = T.axis.opaque(3, m)
+                            poly_i = T.axis.opaque(9, i)
+                            poly_k = T.axis.opaque(9, k)
+                            poly_iter = T.axis.spatial(18, iter)
+                            T.reads(
+                                concat_mat[
+                                    T.min(poly_i, poly_i + j[0]) : T.min(poly_i, poly_i + j[0])

Review Comment:
   Just a way of naming.



-- 
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] cbalint13 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   
   > Hi @yzh119 ,Thank you for your reply. In the process of developing OpenCV operators with TVMScript, there will be complex block nesting. We hope to use blockize to deal with it without changing the nesting relationship between blocks. I have added related unit tests to better explain the situation.
   
   @Biubiubiu12 ,
   Maybe offtopic question: Are/Will OpenCV operators (tscript) that you work on be public somewhere ?
   


-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {

Review Comment:
   done!



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


Re: [PR] [TIR][Schedule] Refactor blockize implementation logic by pass [tvm]

Posted by "tqchen (via GitHub)" <gi...@apache.org>.
tqchen closed pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass
URL: https://github.com/apache/tvm/pull/15274


-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {

Review Comment:
   No, in the recursive process of StmtVisitor::VisitStmt(loop->body), in_lca may become true in "condition with line 595", and the information of xx.push_back(loop->extent) will not be xx.pop_back(), you can think of it as a stack.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;

Review Comment:
   In order to collect the `iter_vars` of externally generated blocks, please refer to L432 in test case.
   Because this information only needs to be collected once, use `num_outer_iter_vars == 0` to judge. The maximum value of `num_outer_iter_vars` is the size of the input `Array<StmtSRef>& block_srefs`.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {

Review Comment:
   No, it is to ensure that `in_lca` is reinitialized to false after traversing lca, preventing `VisitStmt_(const BlockNode* block)` from processing the ir behind lca.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;

Review Comment:
   In order to collect the `iter_vars` information of externally generated blocks, please refer to L432 in test.Because this information only needs to be collected once, use `num_outer_iter_vars == 0` to judge. The maximum value of `num_outer_iter_vars` is the size of the input `Array<StmtSRef>& block_srefs`.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
tests/python/unittest/test_tir_schedule_blockize.py:
##########
@@ -354,5 +355,168 @@ def after_blocks_blockize(
     verify_trace_roundtrip(sch=s, mod=blocks_func)
 
 
+def test_blockize_blocks_v1():

Review Comment:
   This script is only part of implementing cv2.warpAffine



##########
tests/python/unittest/test_tir_schedule_blockize.py:
##########
@@ -354,5 +355,168 @@ def after_blocks_blockize(
     verify_trace_roundtrip(sch=s, mod=blocks_func)
 
 
+def test_blockize_blocks_v1():

Review Comment:
   This script is only part of implementing cv2.warpAffine.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;
+        return;
+      }
+    }
+    StmtVisitor::VisitStmt_(block);
+  }
+
+  ScheduleState self_;
+  StmtSRef lca_;
+  Array<IterVar>* outer_iter_vars_;
+  Array<PrimExpr>* outer_bindings_;
+  Array<IterVar>* inner_iter_vars_;
+  Array<PrimExpr>* inner_bindings_;
+  Map<Var, PrimExpr>* block_var_subst_;
+  Array<PrimExpr> out_extent{nullptr};
+  bool in_lca = false;
+  int num_outer_iter_vars = 0;
+  int num_travered = 0;
+};
+
+class BlockizeBlocks : public StmtMutator {
+  Array<StmtSRef> blocks_;
+  StmtSRef lca_;
+  Map<Block, Block>* block_sref_reuse_;
+  BlockRealize* blockized_;
   Array<Stmt> seq_body;
-  PrimExpr outer_predicate{nullptr};
   Array<IterVar> outer_iter_vars{nullptr};
   Array<PrimExpr> outer_bindings{nullptr};
+  Array<IterVar> inner_iter_vars{nullptr};
+  Map<Var, PrimExpr> block_var_subst;
   Array<BufferRegion> read_regions;
   Array<BufferRegion> write_regions;
   std::string outer_block_name = "outer_";
   Map<Var, Var> loop_var_subst;
   arith::Analyzer analyzer;
-  for (const auto& block_sref : block_srefs) {
-    auto block_realize = GetBlockRealize(self, block_sref);
-    auto block = block_realize->block;
-    // Step 1: Derive subspace division
-    std::vector<const ForNode*> loops;
-    Array<Array<arith::IterMark>> division = SubspaceDivide(block_realize, block_sref, lca, &loops,
-                                                            &analyzer, preserve_unit_iters, true);
-    if (division.empty()) {
-      throw SubspaceNotDivisibleError(self->mod, GetRef<For>(loops.back()), block);
-    }
-    outer_predicate = division.back()[0]->extent;
-    PrimExpr inner_predicate = division.back()[1]->extent;
-    // Step 2. Derive block bindings for both outer and inner block.
-    Array<IterVar> inner_iter_vars;
-    Array<PrimExpr> inner_bindings;
-    Map<Var, PrimExpr> block_var_subst =                       //
-        DeriveBlockBinding(block->iter_vars, division,         //
-                           &outer_iter_vars, &outer_bindings,  //
-                           &inner_iter_vars, &inner_bindings,  //
-                           preserve_unit_iters, outer_iter_vars.defined());
-    // Step 3: Do var substitution to adjust to the new block bindings
+  Block tmp_in_block;
+  Map<Var, arith::IntSet> inner_iter_dom;
+  bool _first_in = false;

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;

Review Comment:
   `Var::copy_with_suffix` can only add a string at the end. We hope that the `IterVar` of the external block is added with `'v'` in front, and the `IterVar `of the internal block is added with `'_i'`, which is more recognizable.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);
+    const Buffer& buffer = it->first;
     Array<Range> regions;
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
-      const arith::IntSet intset = arith::Union(it.second[dim]);
-      regions.push_back({intset.min(), intset.max() + 1});
+      const arith::IntSet intset = arith::Union(it->second[dim]);
+      regions.push_back({analyzer.Simplify(intset.min()), analyzer.Simplify(intset.max() + 1)});

Review Comment:
   When using `tvm.ir.assert_structural_equal()`, the handwritten `@T.prim_func `will automatically `Simplify `the `regions`. For example,` i -- 3 `will automatically become` i+3`.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);
+    const Buffer& buffer = it->first;
     Array<Range> regions;
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
-      const arith::IntSet intset = arith::Union(it.second[dim]);
-      regions.push_back({intset.min(), intset.max() + 1});
+      const arith::IntSet intset = arith::Union(it->second[dim]);
+      regions.push_back({analyzer.Simplify(intset.min()), analyzer.Simplify(intset.max() + 1)});

Review Comment:
   When using `tvm.ir.assert_structural_equal()`, the handwritten `@T.prim_func` will automatically` Simplify` the `regions`. For example, `i -- 3` will automatically become `i+3`.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {

Review Comment:
   done!



-- 
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] Biubiubiu12 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   @multiverstack-intellif 


-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;

Review Comment:
   `Var::copy_with_suffix` can only add a string at the end. We hope that the `IterVar` of the external block is added with `'v'` in front, and the IterVar of the internal block is added with `'_i'`, which is more recognizable.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;

Review Comment:
   `Var::copy_with_suffix` can only add a string at the end. We hope that the `IterVar` of the external block is added with `'v'` in front, and the IterVar of the `internal `block is added with `'_i'`, which is more recognizable.



-- 
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] wrongtest-intellif commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

Posted by "wrongtest-intellif (via GitHub)" <gi...@apache.org>.
wrongtest-intellif commented on code in PR #15274:
URL: https://github.com/apache/tvm/pull/15274#discussion_r1271660324


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);
+    const Buffer& buffer = it->first;
     Array<Range> regions;
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
-      const arith::IntSet intset = arith::Union(it.second[dim]);
-      regions.push_back({intset.min(), intset.max() + 1});
+      const arith::IntSet intset = arith::Union(it->second[dim]);
+      regions.push_back({analyzer.Simplify(intset.min()), analyzer.Simplify(intset.max() + 1)});

Review Comment:
   Why we need simplify here, could we provide an example?



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);

Review Comment:
   It seems that we do not need `buffer_order` array, it is just `regions[i]->buffer`?



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {

Review Comment:
   is this dupliacte condition with line 595?



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;

Review Comment:
   could we use same condition with when we set `in_lca = true`: `if (loop == lca_->stmt)`?



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;
+        return;
+      }
+    }
+    StmtVisitor::VisitStmt_(block);
+  }
+
+  ScheduleState self_;
+  StmtSRef lca_;
+  Array<IterVar>* outer_iter_vars_;
+  Array<PrimExpr>* outer_bindings_;
+  Array<IterVar>* inner_iter_vars_;
+  Array<PrimExpr>* inner_bindings_;
+  Map<Var, PrimExpr>* block_var_subst_;
+  Array<PrimExpr> out_extent{nullptr};

Review Comment:
   `out_extent` -> `outer_extent`



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {

Review Comment:
   size_t i



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {

Review Comment:
   Please add these comments to the class's code.



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {

Review Comment:
   here we assumes `iter_var[i]` always refer to `loops[i]`, we may prove it is the case or explicitly check it.



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;

Review Comment:
   the `num_outer_iter_vars` seems to be either 0 or 1 by implementation, it is as expected?



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),

Review Comment:
   `RangeFromExtent(iter_var->dom->extent)` is just `iter_var->dom`?



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;

Review Comment:
   we could use Var::copy_with_suffix



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;
+        return;
+      }
+    }
+    StmtVisitor::VisitStmt_(block);
+  }
+
+  ScheduleState self_;
+  StmtSRef lca_;
+  Array<IterVar>* outer_iter_vars_;
+  Array<PrimExpr>* outer_bindings_;
+  Array<IterVar>* inner_iter_vars_;
+  Array<PrimExpr>* inner_bindings_;
+  Map<Var, PrimExpr>* block_var_subst_;
+  Array<PrimExpr> out_extent{nullptr};

Review Comment:
   strange initializer `nullptr`



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {

Review Comment:
   !block->iter_vars.empty()



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -565,58 +569,230 @@ StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_u
   return result;
 }
 
-BlockRealize BlockizeBlocks(const ScheduleState& self, const Array<StmtSRef>& block_srefs,
-                            const StmtSRef& lca, Map<Block, Block>* block_sref_reuse,
-                            bool preserve_unit_iters) {
+class CollectSubstInfo : public StmtVisitor {
+ public:
+  static void Collect(const ScheduleState& self, const StmtSRef& lca, const StmtSRef& block_sref,
+                      Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                      Map<Var, PrimExpr>* block_var_subst) {
+    CollectSubstInfo collector(self, lca, outer_iter_vars, outer_bindings, block_var_subst);
+    StmtSRef scope_root = tir::GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false);
+    const BlockNode* root_block = scope_root->StmtAs<BlockNode>();
+    Block block = GetRef<Block>(root_block);
+    return collector(block);
+  }
+
+ private:
+  explicit CollectSubstInfo(const ScheduleState& self, const StmtSRef& lca,
+                            Array<IterVar>* outer_iter_vars, Array<PrimExpr>* outer_bindings,
+                            Map<Var, PrimExpr>* block_var_subst)
+      : self_(self),
+        lca_(lca),
+        outer_iter_vars_(outer_iter_vars),
+        outer_bindings_(outer_bindings),
+        block_var_subst_(block_var_subst) {}
+
+  void VisitStmt_(const ForNode* loop) final {
+    if (!in_lca) {
+      if (loop == lca_->stmt) {
+        in_lca = true;
+      }
+      outer_bindings_->push_back(loop->loop_var);
+      out_extent.push_back(loop->extent);
+      // traverse lca
+      ++num_travered;
+      StmtVisitor::VisitStmt(loop->body);
+      --num_travered;
+      if (!in_lca) {
+        outer_bindings_->pop_back();
+        out_extent.pop_back();
+      }
+      if (num_travered == 0) {
+        in_lca = false;
+      }
+    } else {
+      StmtVisitor::VisitStmt_(loop);
+    }
+  }
+
+  void VisitStmt_(const BlockNode* block) final {
+    if (block == lca_->stmt && block->name_hint == String("root")) {
+      // nothings need to substitute, so all output is nullptr.
+      return;
+    }
+    if (in_lca) {
+      if (block->iter_vars.size() > 0) {
+        // collect info
+        for (int i = 0, n = block->iter_vars.size(); i < n; ++i) {
+          const IterVar& iter_var = block->iter_vars[i];
+          if (static_cast<unsigned int>(i) < out_extent.size()) {
+            arith::Analyzer ana;
+            // According to outer_bindings info, check outer iter_vars
+            ICHECK(ana.CanProveEqual(out_extent[i], iter_var->dom->extent));
+            auto outer_bind = Downcast<Var>((*outer_bindings_)[i]);
+            ObjectPtr<VarNode> new_ptr = make_object<VarNode>(*iter_var->var.get());
+            new_ptr->name_hint = "v" + outer_bind->name_hint;
+            auto outer_iter = IterVar(/*dom=*/RangeFromExtent(iter_var->dom->extent),
+                                      /*var=*/Var(new_ptr),
+                                      /*iter_type=*/iter_var->iter_type);
+            if (num_outer_iter_vars == 0) {
+              outer_iter_vars_->push_back(outer_iter);
+              block_var_subst_->Set(iter_var->var, outer_iter->var);
+            }
+          }
+        }
+        ++num_outer_iter_vars;
+        return;
+      }
+    }
+    StmtVisitor::VisitStmt_(block);
+  }
+
+  ScheduleState self_;
+  StmtSRef lca_;
+  Array<IterVar>* outer_iter_vars_;
+  Array<PrimExpr>* outer_bindings_;
+  Array<IterVar>* inner_iter_vars_;
+  Array<PrimExpr>* inner_bindings_;
+  Map<Var, PrimExpr>* block_var_subst_;
+  Array<PrimExpr> out_extent{nullptr};
+  bool in_lca = false;
+  int num_outer_iter_vars = 0;
+  int num_travered = 0;
+};
+
+class BlockizeBlocks : public StmtMutator {
+  Array<StmtSRef> blocks_;
+  StmtSRef lca_;
+  Map<Block, Block>* block_sref_reuse_;
+  BlockRealize* blockized_;
   Array<Stmt> seq_body;
-  PrimExpr outer_predicate{nullptr};
   Array<IterVar> outer_iter_vars{nullptr};
   Array<PrimExpr> outer_bindings{nullptr};
+  Array<IterVar> inner_iter_vars{nullptr};
+  Map<Var, PrimExpr> block_var_subst;
   Array<BufferRegion> read_regions;
   Array<BufferRegion> write_regions;
   std::string outer_block_name = "outer_";
   Map<Var, Var> loop_var_subst;
   arith::Analyzer analyzer;
-  for (const auto& block_sref : block_srefs) {
-    auto block_realize = GetBlockRealize(self, block_sref);
-    auto block = block_realize->block;
-    // Step 1: Derive subspace division
-    std::vector<const ForNode*> loops;
-    Array<Array<arith::IterMark>> division = SubspaceDivide(block_realize, block_sref, lca, &loops,
-                                                            &analyzer, preserve_unit_iters, true);
-    if (division.empty()) {
-      throw SubspaceNotDivisibleError(self->mod, GetRef<For>(loops.back()), block);
-    }
-    outer_predicate = division.back()[0]->extent;
-    PrimExpr inner_predicate = division.back()[1]->extent;
-    // Step 2. Derive block bindings for both outer and inner block.
-    Array<IterVar> inner_iter_vars;
-    Array<PrimExpr> inner_bindings;
-    Map<Var, PrimExpr> block_var_subst =                       //
-        DeriveBlockBinding(block->iter_vars, division,         //
-                           &outer_iter_vars, &outer_bindings,  //
-                           &inner_iter_vars, &inner_bindings,  //
-                           preserve_unit_iters, outer_iter_vars.defined());
-    // Step 3: Do var substitution to adjust to the new block bindings
+  Block tmp_in_block;
+  Map<Var, arith::IntSet> inner_iter_dom;
+  bool _first_in = false;

Review Comment:
   It would be great to make variable name consistent for `_first_in`, `target_in`, `IsBlockNode`



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);

Review Comment:
   buffer_order is to ensure the order of traversing the `intset_map` dictionary, and there may be duplicate values in `regions[i]->buffer`.



##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);

Review Comment:
   `buffer_order` is to ensure the order of traversing the `intset_map` dictionary, and there may be duplicate values in `regions[i]->buffer`.



-- 
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] Biubiubiu12 commented on a diff in pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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


##########
src/tir/schedule/primitive/blockize_tensorize.cc:
##########
@@ -441,25 +441,29 @@ Array<BufferRegion> EvalSetRegions(const Array<BufferRegion>& regions,
  * \return The union regions
  */
 Array<BufferRegion> UnionRegions(const Array<BufferRegion>& regions) {
+  arith::Analyzer analyzer;
   typedef std::vector<Array<arith::IntSet>> ranges_t;
   std::unordered_map<Buffer, ranges_t, ObjectPtrHash, ObjectPtrEqual> intset_map;
+  Array<Buffer> buffer_order;
   for (const BufferRegion& buffer_region : regions) {
     const Buffer& buffer = buffer_region->buffer;
     if (intset_map.find(buffer) == intset_map.end()) {
       intset_map[buffer] = {buffer->shape.size(), Array<arith::IntSet>()};
+      buffer_order.push_back(buffer);
     }
     std::vector<Array<arith::IntSet>> dim_range(buffer->shape.size(), Array<arith::IntSet>());
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
       intset_map[buffer][dim].push_back(arith::IntSet::FromRange(buffer_region->region[dim]));
     }
   }
   Array<BufferRegion> results;
-  for (const auto& it : intset_map) {
-    const Buffer& buffer = it.first;
+  for (size_t i = 0; i < buffer_order.size(); ++i) {
+    auto it = intset_map.find(buffer_order[i]);
+    const Buffer& buffer = it->first;
     Array<Range> regions;
     for (size_t dim = 0; dim < buffer->shape.size(); ++dim) {
-      const arith::IntSet intset = arith::Union(it.second[dim]);
-      regions.push_back({intset.min(), intset.max() + 1});
+      const arith::IntSet intset = arith::Union(it->second[dim]);
+      regions.push_back({analyzer.Simplify(intset.min()), analyzer.Simplify(intset.max() + 1)});

Review Comment:
   When using `tvm.ir.assert_structural_equal()`, the handwritten `@T.prim_func` will automatically` Simplify` the `regions`. For example, `i -- 3` will automatically become `i+3`.



-- 
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] Biubiubiu12 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   @tvm-bot re-run
   


-- 
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] Biubiubiu12 commented on pull request #15274: [TIR][Schedule] Refactor blockize implementation logic by pass

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

   @tvm-bot re-run


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