Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Avoid stack overflow in TargetHookVisitor with large modules #11135

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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