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/04/14 05:06:45 UTC

[GitHub] [tvm] yzhliu commented on a change in pull request #7832: [Relay] Recursive destructor call replaced with non-recursive for Call nodes.

yzhliu commented on a change in pull request #7832:
URL: https://github.com/apache/tvm/pull/7832#discussion_r612939038



##########
File path: include/tvm/relay/expr.h
##########
@@ -625,6 +629,64 @@ class TempExpr : public Expr {
   TVM_DEFINE_OBJECT_REF_METHODS(TempExpr, RelayExpr, TempExprNode);
 };
 
+/*
+ * Non-recursive traversal with dismantling unused call nodes,
+ * a derivative from ExpandDataflow method
+ */
+inline void __dismantle(Expr expr) {
+  std::unordered_set<const RelayExprNode*> visited;
+  std::stack<std::pair<Expr, bool>> stack;
+  auto fpush_to_stack = [&visited, &stack](const Expr& expr) {
+    if (expr.use_count() < 3 && !visited.count(expr.get())) {
+      stack.push({expr, false});
+    }
+  };
+  fpush_to_stack(expr);
+  while (stack.size() > 0) {
+    auto node = stack.top().first;
+
+    if (visited.count(node.get())) {
+      stack.pop();
+
+      // dismantle node
+      if (node.use_count() < 3) {

Review comment:
       could you elaborate a bit why number 3 and 2?




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

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