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 2022/11/10 08:37:54 UTC

[GitHub] [tvm] masahi commented on a diff in pull request #13343: [Relay] Refactor constant folding over expr into a utility function

masahi commented on code in PR #13343:
URL: https://github.com/apache/tvm/pull/13343#discussion_r1018792828


##########
src/relay/transforms/pattern_utils.h:
##########
@@ -120,6 +120,21 @@ inline Expr InferType(const Expr& expr) {
   }
 }
 
+/*!
+ * \brief Try to apply constant folding over expr:
+ *
+ * Do constant_fold over each node in expr
+ *
+ * \param expr The IR expression
+ * \return resulting expr
+ */
+inline Expr FoldConstantExpr(const Expr& expr) {
+  IRModule const_mod = IRModule::FromExpr(expr);
+  const_mod = transform::FoldConstant()(const_mod);
+  GlobalVar const_main = const_mod->GetGlobalVar("main");
+  return Downcast<Function>(const_mod->functions[const_main])->body;
+}

Review Comment:
   There is already https://github.com/apache/tvm/blob/78142ad2e4ce2c5ca096f7e80f4f4f62ca9c2bd5/src/relay/transforms/fold_constant.cc#L429. You can probably just use that.
   
   And it's odd to add this function in `pattern_utils.h`.



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