slyubomirsky commented on code in PR #14282:
URL: https://github.com/apache/tvm/pull/14282#discussion_r1134332228


##########
src/relax/backend/vm/vm_builtin_lower.cc:
##########
@@ -129,9 +131,45 @@ class VMBuiltinLowerMutator : public ExprMutator {
   Expr Reshape(const Call& call_node) {
     ICHECK(call_node->args.size() == 2);
     ICHECK(call_node->struct_info_.defined());
-    CHECK(call_node->args[1]->IsInstance<ShapeExprNode>())
-        << "VMBuiltinLower expects the shape arg of reshape op to be a 
ShapeExpr";
-    return Call(builtin_reshape_, call_node->args, Attrs(), 
{GetStructInfo(call_node)});
+    auto arg = call_node->args[1];
+    CHECK(arg->IsInstance<ShapeExprNode>() || arg->IsInstance<VarNode>())
+        << "VMBuiltinLower expects the shape arg of reshape op to be a 
ShapeExpr or VarNode bound "
+           "to a ShapeExpr";
+
+    if (arg->IsInstance<ShapeExprNode>()) {
+      return Call(builtin_reshape_, call_node->args, Attrs(), 
{GetStructInfo(call_node)});
+    }
+
+    ICHECK(arg->IsInstance<VarNode>());
+    Optional<Expr> _bound_val = 
LookupBinding(Downcast<Var>(call_node->args[1]));
+    ICHECK(_bound_val.defined());
+    Expr bound_val = _bound_val.value();
+    CHECK(bound_val->IsInstance<ShapeExprNode>())
+        << "VMBuiltinLower expects bound value to be a ShapeExpr";
+    return Call(builtin_reshape_, {call_node->args[0], bound_val}, Attrs(),
+                {GetStructInfo(call_node)});
+  }
+
+  ShapeExpr TensorToShape(const Call& call_node) {
+    ICHECK(call_node->args.size() == 1);
+    ICHECK(call_node->struct_info_.defined());
+    Expr expr = call_node->args[0];
+    const ShapeStructInfoNode* sinfo = 
GetStructInfoAs<ShapeStructInfoNode>(call_node);
+    ICHECK(sinfo);
+    // call builtin function that converts tensor to shape tuple
+    Var call = builder_->Emit(Call(ExternFunc("vm.builtin.tensor_to_shape"), 
{expr}, {},
+                                   {GetRef<ShapeStructInfo>(sinfo)}));
+
+    // define symbolic variables
+    Array<PrimExpr> shape_var;
+    for (int i = 0; i < sinfo->ndim; i++) {
+      shape_var.push_back(tir::Var("x", DataType::Int(64)));

Review Comment:
   Generating the names sounds like it should be a BlockBuilder functionality



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