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 2021/12/09 02:12:14 UTC

[GitHub] [tvm] vinx13 commented on a change in pull request #9680: [TVMScript] Improve printer for TIR syntax sugar

vinx13 commented on a change in pull request #9680:
URL: https://github.com/apache/tvm/pull/9680#discussion_r765380321



##########
File path: src/printer/tvmscript_printer.cc
##########
@@ -471,6 +479,47 @@ Doc TVMScriptPrinter::PrintMatchBufferRegion(const MatchBufferRegionNode* op) {
   return doc;
 }
 
+// check if all arguments, except the first two, are specified for T.match_buffer
+// if not, then this match buffer is printed out as syntax sugar
+bool TVMScriptPrinter::IsMatchBufferSugarred(const Buffer& buf) {

Review comment:
       ```suggestion
   bool TVMScriptPrinter::IsSimpleBuffer(const Buffer& buf) {
   ```
   

##########
File path: src/printer/tvmscript_printer.cc
##########
@@ -471,6 +479,47 @@ Doc TVMScriptPrinter::PrintMatchBufferRegion(const MatchBufferRegionNode* op) {
   return doc;
 }
 
+// check if all arguments, except the first two, are specified for T.match_buffer
+// if not, then this match buffer is printed out as syntax sugar
+bool TVMScriptPrinter::IsMatchBufferSugarred(const Buffer& buf) {
+  if (memo_var_.find(buf->data) != memo_var_.end()) {
+    return false;
+  }
+  if (!buf->strides.empty()) {
+    return false;
+  }
+  if (buf->elem_offset->IsInstance<VarNode>()) {
+    Var elem_offset = Downcast<Var>(buf->elem_offset);
+    if (memo_var_.find(elem_offset) != memo_var_.end()) {
+      return false;
+    }
+  } else if (buf->elem_offset->IsInstance<IntImmNode>()) {
+    IntImm elem_offset = Downcast<IntImm>(buf->elem_offset);
+    if (elem_offset->value != 0) {
+      return false;
+    }
+  }
+  if (buf.scope() != "global") {
+    return false;
+  }
+  if (buf->data_alignment != runtime::kAllocAlignment) {
+    return false;
+  }
+  if (buf->offset_factor != 1) {
+    return false;
+  }
+  if (buf->buffer_type != 1) {
+    return false;
+  }
+  return true;
+}
+
+Doc TVMScriptPrinter::MatchBufferDeclaration(const Buffer& buffer) {
+  Doc doc = Print(buffer->shape);

Review comment:
       Printing `T.Buffer` should also be part of this function

##########
File path: src/printer/tvmscript_printer.cc
##########
@@ -471,6 +479,47 @@ Doc TVMScriptPrinter::PrintMatchBufferRegion(const MatchBufferRegionNode* op) {
   return doc;
 }
 
+// check if all arguments, except the first two, are specified for T.match_buffer
+// if not, then this match buffer is printed out as syntax sugar
+bool TVMScriptPrinter::IsMatchBufferSugarred(const Buffer& buf) {
+  if (memo_var_.find(buf->data) != memo_var_.end()) {
+    return false;
+  }
+  if (!buf->strides.empty()) {
+    return false;
+  }
+  if (buf->elem_offset->IsInstance<VarNode>()) {
+    Var elem_offset = Downcast<Var>(buf->elem_offset);
+    if (memo_var_.find(elem_offset) != memo_var_.end()) {
+      return false;
+    }
+  } else if (buf->elem_offset->IsInstance<IntImmNode>()) {
+    IntImm elem_offset = Downcast<IntImm>(buf->elem_offset);
+    if (elem_offset->value != 0) {
+      return false;
+    }
+  }
+  if (buf.scope() != "global") {
+    return false;
+  }
+  if (buf->data_alignment != runtime::kAllocAlignment) {
+    return false;
+  }
+  if (buf->offset_factor != 1) {
+    return false;
+  }
+  if (buf->buffer_type != 1) {
+    return false;
+  }
+  return true;
+}
+
+Doc TVMScriptPrinter::MatchBufferDeclaration(const Buffer& buffer) {
+  Doc doc = Print(buffer->shape);
+  doc << ", dtype=" << PrintDType(buffer->dtype);

Review comment:
       Let's use bracket syntax which is simpler

##########
File path: src/printer/tvmscript_printer.cc
##########
@@ -471,6 +479,47 @@ Doc TVMScriptPrinter::PrintMatchBufferRegion(const MatchBufferRegionNode* op) {
   return doc;
 }
 
+// check if all arguments, except the first two, are specified for T.match_buffer
+// if not, then this match buffer is printed out as syntax sugar
+bool TVMScriptPrinter::IsMatchBufferSugarred(const Buffer& buf) {
+  if (memo_var_.find(buf->data) != memo_var_.end()) {
+    return false;
+  }
+  if (!buf->strides.empty()) {
+    return false;
+  }
+  if (buf->elem_offset->IsInstance<VarNode>()) {
+    Var elem_offset = Downcast<Var>(buf->elem_offset);
+    if (memo_var_.find(elem_offset) != memo_var_.end()) {
+      return false;
+    }
+  } else if (buf->elem_offset->IsInstance<IntImmNode>()) {
+    IntImm elem_offset = Downcast<IntImm>(buf->elem_offset);
+    if (elem_offset->value != 0) {
+      return false;
+    }
+  }
+  if (buf.scope() != "global") {
+    return false;
+  }
+  if (buf->data_alignment != runtime::kAllocAlignment) {
+    return false;
+  }
+  if (buf->offset_factor != 1) {
+    return false;
+  }
+  if (buf->buffer_type != 1) {

Review comment:
       What is 1? Is it some enum?




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