Hi there,
In current tvm, src/codegen/llvm/codegen_cpu.cc, it generate assert stmt. It would be nice to have a build config option to disable these runtime TVM asserts. Below is just a example of disable it with environment variable. It will be better to use build config to control it. Please let me know your thought. Thanks, -W ``` diff --git a/src/codegen/llvm/codegen_cpu.cc b/src/codegen/llvm/codegen_cpu.cc index fcad0f7b..5842e2ed 100644 --- a/src/codegen/llvm/codegen_cpu.cc +++ b/src/codegen/llvm/codegen_cpu.cc @@ -705,25 +705,32 @@ llvm::Value* CodeGenCPU::CreateIntrinsic(const Call* op) { } void CodeGenCPU::VisitStmt_(const AssertStmt* op) { - using llvm::BasicBlock; - llvm::Value* cond = MakeValue(op->condition); - std::ostringstream os; - os << "Assert fail: " << op->condition; - if (op->message.as<StringImm>()) { - os << ", " << op->message.as<StringImm>()->value; +#ifndef NDEBUG + bool use_tvm_asserts = true; +#else + bool use_tvm_asserts = (std::getenv("TVM_USE_ASSERT_STMT") != nullptr); +#endif // !NDEBUG + if (use_tvm_asserts) { + using llvm::BasicBlock; + llvm::Value* cond = MakeValue(op->condition); + std::ostringstream os; + os << "Assert fail: " << op->condition; + if (op->message.as<StringImm>()) { + os << ", " << op->message.as<StringImm>()->value; + } + llvm::Value* msg = GetConstString(os.str()); + BasicBlock* fail_block = BasicBlock::Create( + *ctx_, "assert_fail", function_); + BasicBlock* end_block = BasicBlock::Create( + *ctx_, "assert_end", function_); + builder_->CreateCondBr(cond, end_block, fail_block, md_very_likely_branch_); + // fail condition. + builder_->SetInsertPoint(fail_block); + builder_->CreateCall(RuntimeTVMAPISetLastError(), {msg}); + builder_->CreateRet(ConstInt32(-1)); + // otherwise set it to be new end. + builder_->SetInsertPoint(end_block); } - llvm::Value* msg = GetConstString(os.str()); - BasicBlock* fail_block = BasicBlock::Create( - *ctx_, "assert_fail", function_); - BasicBlock* end_block = BasicBlock::Create( - *ctx_, "assert_end", function_); - builder_->CreateCondBr(cond, end_block, fail_block, md_very_likely_branch_); - // fail condition. - builder_->SetInsertPoint(fail_block); - builder_->CreateCall(RuntimeTVMAPISetLastError(), {msg}); - builder_->CreateRet(ConstInt32(-1)); - // otherwise set it to be new end. - builder_->SetInsertPoint(end_block); CodeGenLLVM::VisitStmt_(op); } ``` --- [Visit Topic](https://discuss.tvm.ai/t/disable-assert-in-runtime/2152/1) to respond. You are receiving this because you enabled mailing list mode. To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/55b10f319d278bde87f7e24e6822cbed232bc7d613ef2a91e73ecd397f2aa331). Tianqi Chen, UW, Seattle, WA, 98105, United States http://tracking.discuss.tvm.ai/tracking/unsubscribe?msgid=5cyuLfqkli8FZN--W9juhg2