Skip to content
Draft
Show file tree
Hide file tree
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
7 changes: 5 additions & 2 deletions src/relax/backend/vm/codegen_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ class CodeGenVM : public ExprFunctor<Instruction::Arg(const Expr&)> {
} else {
// every "normal" operator is lowered to a global var in the IRModule. The Attrs for those
// ops are handled in a pass when lowering them to TIR.
TVM_FFI_THROW(InternalError) << "CodeGenVM cannot handle this intrinsic now:\n"
<< call_node->op;
TVM_FFI_THROW(InternalError)
<< "CodeGenVM cannot emit this Relax operator directly. "
<< "Run the appropriate lowering pass, or route the operator to an external "
<< "codegen before VM codegen.\nOffending call:\n"
<< call;
}
} else {
EmitNormalCall(call, dst_reg);
Expand Down
7 changes: 5 additions & 2 deletions src/relax/backend/vm/codegen_vm_tir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ class CodeGenVMTIR : public ExprFunctor<ffi::Optional<PrimExpr>(const Expr&)> {
} else {
// every "normal" operator is lowered to a global var in the IRModule. The Attrs for those
// ops are handled in a pass when lowering them to TIR.
TVM_FFI_THROW(InternalError) << "CodeGenVMTIR cannot handle this intrinsic now:\n"
<< call_node->op;
TVM_FFI_THROW(InternalError)
<< "CodeGenVMTIR cannot emit this Relax operator directly. "
<< "Run the appropriate lowering pass, or route the operator to an external "
<< "codegen before VM codegen.\nOffending call:\n"
<< call;
}
} else {
EmitNormalCall(call, dst_reg);
Expand Down
24 changes: 24 additions & 0 deletions tests/python/relax/test_vm_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,30 @@ def foo(x: R.Tensor((3, 4), "float32"), y: R.Tensor((3, 4), "float32")):
tvm.testing.assert_allclose(inp2.numpy(), inp1.numpy(), rtol=1e-7, atol=1e-7)


def test_vm_compile_unlowered_operator_error(exec_mode):
@tvm.script.ir_module
class Conv2dTranspose:
@R.function
def main(
x: R.Tensor((1, 4, 4, 1), "float32"),
w: R.Tensor((1, 2, 3, 3), "float32"),
):
gv = R.nn.conv2d_transpose(
x,
w,
data_layout="NHWC",
kernel_layout="IOHW",
)
return gv

mod = relax.transform.LegalizeOps()(Conv2dTranspose)
with pytest.raises(
tvm.error.InternalError,
match=r"(?s)Offending call:.*(?:R|relax)\.nn\.conv2d_transpose.*data_layout.*NHWC",
):
relax.build(mod, target="llvm", exec_mode=exec_mode)


def test_match_check(exec_mode):
@tvm.script.ir_module
class TestMatchCheck:
Expand Down
Loading