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

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


The following commit(s) were added to refs/heads/main by this push:
     new cb31cb3e4f [Debug] Improve error message in VMShapeLower (#16806)
cb31cb3e4f is described below

commit cb31cb3e4f06f4752df35ea3f0eb233634afc931
Author: Eric Lunderberg <lunderb...@users.noreply.github.com>
AuthorDate: Thu Mar 28 16:52:56 2024 -0500

    [Debug] Improve error message in VMShapeLower (#16806)
    
    If `VMShapeLower` raises an error, specify which function produced the
    error.
---
 src/relax/backend/vm/vm_shape_lower.cc | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/relax/backend/vm/vm_shape_lower.cc 
b/src/relax/backend/vm/vm_shape_lower.cc
index 5875ad5562..06c2e31767 100644
--- a/src/relax/backend/vm/vm_shape_lower.cc
+++ b/src/relax/backend/vm/vm_shape_lower.cc
@@ -224,6 +224,7 @@ class VMShapeLowerMutator
     // prepare mapping and heap var
     slot_vec_.clear();
     slot_map_.clear();
+    current_gvar_ = gvar;
     PrimExprSlotCollector::Collect(func, &slot_vec_, &slot_map_);
     heap_size_ = IntImm(ShapeDType(), static_cast<int64_t>(slot_vec_.size()));
     VarBinding shape_heap_binding = this->AllocShapeHeapBinding(heap_size_);
@@ -285,6 +286,9 @@ class VMShapeLowerMutator
     }
 
     auto new_body = builder_->Normalize(SeqExpr(blocks, body_seq->body));
+
+    current_gvar_ = NullOpt;
+
     // create a new function
     return Function(func->params, new_body, func->ret_struct_info, 
func->is_pure, func->attrs);
   }
@@ -357,7 +361,8 @@ class VMShapeLowerMutator
       auto it = slot_map_.find(expr);
       ICHECK(it != slot_map_.end());
       auto* slot = it->second;
-      ICHECK(slot->value_computed) << "PrimExpr " << expr << " has not been 
computed";
+      ICHECK(slot->value_computed)
+          << "PrimExpr " << expr << " in function " << current_gvar_ << " has 
not been computed";
       return {PrimValue::Int64(static_cast<int>(MakeShapeCode::kLoadShape)),
               PrimValue::Int64(slot->index)};
     }
@@ -772,6 +777,7 @@ class VMShapeLowerMutator
   std::vector<std::unique_ptr<PrimExprSlot>> slot_vec_;
   /*! \brief Expr => slot. */
   PrimExprSlotMap slot_map_;
+  Optional<GlobalVar> current_gvar_ = NullOpt;
   /*!
    * \brief List of vars that are being defined but
    * have not go through outstanding shape compute check.

Reply via email to