junrushao1994 commented on code in PR #12420:
URL: https://github.com/apache/tvm/pull/12420#discussion_r945234175


##########
src/ir/expr.cc:
##########
@@ -49,6 +50,18 @@ PrimExpr PrimExpr::FromObject_(ObjectRef ref) {
   if (auto* ptr = ref.as<runtime::StringObj>()) {
     return tir::StringImm(GetRef<runtime::String>(ptr));
   }
+  if (auto* ptr = ref.as<tir::BufferRegionNode>()) {
+    tir::BufferRegion buffer_region = GetRef<tir::BufferRegion>(ptr);
+    Array<PrimExpr> indices;
+    for (Range r : buffer_region->region) {
+      if (arith::Analyzer().CanProveEqual(r->extent, 1)) {
+        indices.push_back(r->min);
+      } else {
+        indices.push_back(tir::Ramp(r->min, 1, 
Downcast<IntImm>(r->extent)->value));
+      }
+    }
+    return tir::BufferLoad(buffer_region->buffer, indices);
+  }

Review Comment:
   This impl needs some small clean-up:
   
   ```suggestion
     if (const auto* buffer_region = ref.as<tir::BufferRegionNode>()) {
       Array<PrimExpr> indices;
       indices.reserve(buffer_region->region.size());
       for (const Range& r : buffer_region->region) {
         if (is_one(r->extent)) {
           indices.push_back(r->min);
         } else if (const auto* extent = r->extent.as<IntImmNode>()) {
           indices.push_back(tir::Ramp(r->min, make_const(r->min->dtype, 1), 
extent->value));
         } else {
           LOG(FATAL) << "ValueError: Cannot convert to BufferLoad: " << ref;
         }
       }
       return tir::BufferLoad(buffer_region->buffer, indices);
     }
   ```
   
   
   



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