junrushao commented on code in PR #11639:
URL: https://github.com/apache/tvm/pull/11639#discussion_r971122346


##########
src/tir/schedule/analysis/analysis.cc:
##########
@@ -1514,115 +1519,235 @@ class PatternMatcher : public ExprVisitor {
 
  private:
   bool match_success_{true};
-  PrimExpr pattern_, expr_to_match_;
+  Array<PrimExpr> pattern_;
+  PrimExpr expr_to_match_;
   std::unordered_map<const VarNode*, PrimExpr> filled_map_;
 };
 
 /******** Reduction Block Related ********/
 
-class InitBodyNotBufferStoreError : public ScheduleError {
- public:
-  explicit InitBodyNotBufferStoreError(IRModule mod, Block block, bool 
init_is_bufferstore,
-                                       bool body_is_bufferstore)
-      : mod_(std::move(mod)),
-        block_(std::move(block)),
-        init_is_bufferstore_(init_is_bufferstore),
-        body_is_bufferstore_(body_is_bufferstore) {}
-
-  String FastErrorString() const final {
-    return "ScheduleError: The `init` and `body` of reduction block are 
required to be both "
-           "BufferStore so that rfactor or cross-thread reduction can be 
applied";
-  }
+static const char* kRFactorCrossThreadReductionApplicableBlockDef =
+    R"(Definition of a reduction block that is applicable by RFactor and 
Cross-Thread Reduction:
+1) The block init should be a single BufferStore or a SeqStmt of BufferStores
+2) The buffers initialized in the block init should be all different
+3) The number of consecutive LetStmts in the block body (if any) should equal 
the number of BufferStores in the block init
+4) The variables of the LetStmts in the block body should be all different
+5) The body of the innermost LetStmt should be a single BufferStore or a 
SeqStmt of BufferStores
+6) The number of BufferStores under the block body should equal the number of 
BufferStores in the block init, and thereby equal the number of LetStmts above
+7) The variables bound by the LetStmts in the block body must all directly 
serve as values of the BufferStores inside, and the stored values of the 
BufferStores can only be those variables
+8) The variables stored by the BufferStores in the block body should be all 
different
+9) The buffers written by the BufferStores in the block body should be all 
different
+10) The buffers initialized in the block init and written in the block body 
should match
+11) The buffers written by the block should have same shape
+12) The indices of all BufferStores in the reduction block should be the 
same)";
+
+void ErrorRFactorCrossThreadReductionNotApplicable(const 
Optional<ScheduleState>& self, Block block,

Review Comment:
   nit: move the reducer-related logic into a separate file given they are 
relatively isolated and the logic is much longer



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to