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

Change AOT from ExprVisitor to MixedModeVisitor #8856

Merged
merged 1 commit into from
Aug 27, 2021
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
10 changes: 3 additions & 7 deletions src/relay/backend/aot_executor_codegen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ using StorageMap =
* This is an on demand allocator for AOT. A new temporary
* (storage allocator identifier) is allocated for each operation.
*/
class AOTOnDemandAllocator : public ExprVisitor {
class AOTOnDemandAllocator : public MixedModeVisitor {
public:
// run the visitor on a function.
void Run(const Function& func) {
Expand Down Expand Up @@ -84,10 +84,7 @@ class AOTOnDemandAllocator : public ExprVisitor {
AssignReturnSid(GetRef<Expr>(op));
}

void VisitExpr_(const VarNode* op) final {
ExprVisitor::VisitExpr_(op);
AssignReturnSid(GetRef<Expr>(op));
}
void VisitExpr_(const VarNode* op) final { AssignReturnSid(GetRef<Expr>(op)); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original impl seems to do further visits, why is this change here as part of changing the visitor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was no matching VisitExpr in MixedModeVisitor, given the tests are passing for everything I've tried I'm at a loss for what it originally was meant to do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To further add to the mystery, here's what ExprVisitor::VisitExpr does:

void ExprVisitor::VisitExpr_(const VarNode* op) {
  this->VisitSpan(op->span);
  if (op->type_annotation.defined()) {
    this->VisitType(op->type_annotation);
  }
}

which calls into:

void ExprVisitor::VisitType(const Type& t) { return; }
void ExprVisitor::VisitSpan(const Span& span) { return; }

neither of which seem to be overridden by AOT, so I think this did nothing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, agreed!


void VisitExpr_(const FunctionNode* op) final {
// do not recurse into sub function.
Expand Down Expand Up @@ -218,7 +215,7 @@ class AOTOnDemandAllocator : public ExprVisitor {
};

/*! \brief Code generator for AOT executor */
class AOTExecutorCodegen : public ExprVisitor {
class AOTExecutorCodegen : public MixedModeVisitor {
protected:
/*!
* \brief Utility function to allocate a DLTensor or TVMValue
Expand Down Expand Up @@ -437,7 +434,6 @@ class AOTExecutorCodegen : public ExprVisitor {
void VisitExpr_(const OpNode* op) override {
throw std::runtime_error("can not compile op in non-eta expanded form");
}
void VisitExpr_(const GlobalVarNode* op) override { throw std::runtime_error(""); }
void VisitExpr_(const IfNode* op) override { throw std::invalid_argument("if not supported"); }
void VisitExpr_(const FunctionNode* op) override {
ICHECK(op->GetAttr<String>(attr::kCompiler).defined())
Expand Down