You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2023/01/16 21:09:55 UTC

[GitHub] [tvm] junrushao commented on a diff in pull request #13743: [TVMScript] `T.axis.remap` syntax sugar for TVMScript printer

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


##########
src/script/printer/tir/block.cc:
##########
@@ -67,6 +110,30 @@ Doc PrintBlock(IRDocsifier d, tir::Block block, ObjectPath block_p,  //
     }
     (*frame)->stmts.push_back(AssignDoc(DefineVar(iter_var->var, *frame, d), rhs, NullOpt));
   }
+
+  // Step 1.4. Construct block var bindings of T.axis.remap
+  if (remap_vars.size()) {
+    int m = remap_vars.size();
+    Array<ExprDoc> lhs;
+    Array<ExprDoc> loop_var_doc;
+    lhs.reserve(m);
+    loop_var_doc.reserve(m);
+    std::string binding_type = "";
+    for (int i = 0; i < n_vars; ++i) {
+      tir::IterVar iter_var = block->iter_vars[i];
+      ObjectPath iter_var_p = block_p->Attr("iter_var")->ArrayIndex(i);
+      if (remap_vars.count(iter_var)) {
+        lhs.push_back(DefineVar(iter_var->var, *frame, d));
+        loop_var_doc.push_back(d->AsDoc<ExprDoc>(realize->iter_values[i],
+                                                 realize_p->Attr("iter_values")->ArrayIndex(i)));
+        binding_type += iter_var->iter_type == tir::IterVarType::kDataPar ? "S" : "R";
+      }
+    }
+    ExprDoc rhs = TIR("axis")->Attr("remap");
+    rhs = rhs->Call({LiteralDoc::Str(binding_type), ListDoc(loop_var_doc)});
+    (*frame)->stmts.push_back(AssignDoc(TupleDoc(lhs), rhs, NullOpt));

Review Comment:
   I was worried if it's going to introduce different ordering of iter vars?
   
   For example:
   
   ```python
   i0 = T.axis.S(...)
   i1, i2, i3 = T.axis.remap(...)
   i4 = T.axis.R(...)
   ```
   
   is structurally different than
   
   ```python
   i0 = T.axis.S(...)
   i4 = T.axis.R(...)
   i1, i2, i3 = T.axis.remap(...)
   ```



-- 
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: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org