Skip to content

Commit

Permalink
[FIX] Avoid stack overflow in TargetHookVisitor with large modules (a…
Browse files Browse the repository at this point in the history
…pache#11135)

Use MixedModeVisitor to not recursively visit let nodes.
  • Loading branch information
Tristan Konolige authored and Boblest Sebastian (ETAS-DEV/XPC-Fe1) committed May 27, 2022
1 parent f2cd06e commit 13f866c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/relay/transforms/target_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class TargetHookVisitor : public tvm::relay::MixedModeVisitor {
std::vector<Pass> pass_list_;
/*! \brief Attribute map for all registered targets */
TargetKindAttrMap<Pass> target_attr_map_;
using tvm::relay::MixedModeVisitor::VisitExpr_;

public:
TargetHookVisitor() : target_attr_map_(tvm::TargetKind::GetAttrMap<Pass>("RelayToTIR")) {}
Expand All @@ -48,6 +49,18 @@ class TargetHookVisitor : public tvm::relay::MixedModeVisitor {
return pass_list_;
}

void VisitExpr_(const LetNode* op) final {
auto pre_visit = [this](const LetNode* op) {
this->VisitExpr(op->var);
this->VisitExpr(op->value);
};
auto post_visit = [this](const LetNode* op) {
this->VisitExpr(op->body);
this->visit_counter_[op] += 1;
};
ExpandANormalForm(op, pre_visit, post_visit);
}

void VisitExpr_(const CallNode* call) override {
// Descend the call tree
for (auto arg : call->args) {
Expand Down

0 comments on commit 13f866c

Please sign in to comment.