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

[TVMScript] Improved error message for unexpected top frame #14399

Merged
merged 1 commit into from
Mar 28, 2023
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
26 changes: 22 additions & 4 deletions src/script/ir_builder/tir/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,15 @@ inline tvm::tir::Stmt AsStmt(const Array<tvm::tir::Stmt>& stmt) {
inline PrimFuncFrame FindPrimFuncFrame(const String& method) {
if (Optional<PrimFuncFrame> frame = IRBuilder::Current()->GetLastFrame<PrimFuncFrame>()) {
return frame.value();
} else if (Optional<PrimFuncFrame> frame = IRBuilder::Current()->FindFrame<PrimFuncFrame>()) {
LOG(FATAL) << "ValueError: " << method << " must be called at the top of a PrimFunc. "
<< "While " << method << " did occur within the PrimFunc \"" << frame.value()->name
<< "\", other frames (e.g. block/if/else/let) had been introduced since the "
<< "PrimFunc's frame";
} else {
LOG(FATAL) << "ValueError: " << method << " must be called at the top of a PrimFunc, "
<< "but " << method << " occurred outside of any T.prim_func() frame";
}
LOG(FATAL) << "ValueError: PrimFunc frame not find. Please ensure '" << method
<< "' is called under T.prim_func()";
throw;
}

Expand All @@ -83,9 +89,15 @@ inline PrimFuncFrame FindPrimFuncFrame(const String& method) {
inline BlockFrame FindBlockFrame(const String& method) {
if (Optional<BlockFrame> frame = IRBuilder::Current()->GetLastFrame<BlockFrame>()) {
return frame.value();
} else if (Optional<BlockFrame> frame = IRBuilder::Current()->FindFrame<BlockFrame>()) {
LOG(FATAL) << "ValueError: " << method << " must be called at the top of a T.block(). "
<< "While " << method << " did occur within the block \"" << frame.value()->name
<< "\", other frames (e.g. if/else/let) had been introduced since the T.block(\""
<< frame.value()->name << "\") frame";
} else {
LOG(FATAL) << "ValueError: " << method << " must be called at the top of a T.block(), "
<< "but " << method << " occurred outside of any T.block() frame";
}
LOG(FATAL) << "ValueError: Block frame not find. Please ensure '" << method
<< "' is called under T.block()";
throw;
}

Expand All @@ -97,6 +109,12 @@ inline BlockFrame FindBlockFrame(const String& method) {
inline IfFrame FindIfFrame(const String& method) {
if (Optional<IfFrame> frame = IRBuilder::Current()->GetLastFrame<IfFrame>()) {
return frame.value();
} else if (Optional<IfFrame> frame = IRBuilder::Current()->FindFrame<IfFrame>()) {
LOG(FATAL) << "ValueError: " << method << " must be called at the top of a T.if_(). "
<< "While " << method << " did occur within the conditional based on ("
<< frame.value()->condition
<< "), other frames (e.g. if/else/let) had been introduced since the "
<< "IfThenElse frame";
} else {
LOG(FATAL) << "ValueError: IfThenElse frame not find. Please ensure '" << method
<< "' is called under T.if_()";
Expand Down