masahi commented on a change in pull request #10638:
URL: https://github.com/apache/tvm/pull/10638#discussion_r835967212



##########
File path: src/tir/schedule/primitive/reduction.cc
##########
@@ -284,7 +284,22 @@ StmtSRef DecomposeReduction(ScheduleState self, const 
StmtSRef& block_sref,
                /*body=*/body);
   }
   body = Substitute(body, loop_var_map);
-  // Step 6. Mutate IR
+  // Step 6. Add write regions back to read regions in update block.
+  Array<BufferRegion> new_reads;
+  std::unordered_set<const BufferNode*> read_bufs;
+  for (const BufferRegion& read_access : block->reads) {
+    read_bufs.insert(read_access->buffer.get());
+  }
+  for (const BufferRegion& write_access : block->writes) {
+    if (read_bufs.find(write_access->buffer.get()) == read_bufs.end()) {
+      new_reads.push_back(write_access);
+    }
+  }
+  for (const BufferRegion& read_access : block->reads) {
+    new_reads.push_back(read_access);
+  }
+  (const_cast<BlockNode*>(block))->reads = std::move(new_reads);

Review comment:
       After this PR, I'm getting a structural hash mismatch in meta schedule 
`ApplyHistoryBest` 
https://github.com/apache/tvm/blob/ce335c3a74185df6cc1152e53c60695d8a418d8e/src/meta_schedule/integration.cc#L134
   
   I found that if I do `decompose_reduction`, IRModules that have been 
committed to the database are modified. Specifically, the query module has
   ```
   reads([placeholder[b, i, k], T_layout_trans[b, floordiv(j, 16), floordiv(k, 
4), floormod(j, 16), floormod(k, 4)]])
   writes([compute[b, i, j]])
   ...
   with init() {
     compute[b, i, j] = 0
   }
   compute[b, i, j] = (compute[b, i, j] + (int32(placeholder[b, i, 
k])*int32(T_layout_trans[b, floordiv(j, 16), floordiv(k, 4), floormod(j, 16), 
floormod(k, 4)])))
   ```
   but the corresponding mod in the database has different `reads`:
   ```
   reads(compute[b, i, j], [placeholder[b, i, k], T_layout_trans[b, floordiv(j, 
16), floordiv(k, 4), floormod(j, 16), floormod(k, 4)]])
   ...
   ```
   
   I haven't looked at what this PR does, but I'm pretty sure this line is the 
offending bug...




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