You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2019/11/15 02:35:23 UTC

[GitHub] [incubator-tvm] FrozenGene commented on issue #4340: [CodeGen] Add build config option disable_assert to control whether to generate assert

FrozenGene commented on issue #4340: [CodeGen] Add build config option disable_assert to control whether to generate assert
URL: https://github.com/apache/incubator-tvm/pull/4340#issuecomment-554183342
 
 
   > Actually, it would be great if we can do it at an earlier point, and add a pass to remove assert. This will allow the same pass to work for both LLVM and C backend
   
   @tqchen  I tried to implement one IRPass (like SkipAssert) to remove assert in `BuildStmt`  https://github.com/apache/incubator-tvm/blob/master/src/codegen/build_module.cc#L389. However, I find that during `lower` https://github.com/apache/incubator-tvm/blob/master/src/codegen/build_module.cc#L444, we will still produce AssertStmt internally. Do you have any good suggestion?
   
   For CodeGenC, one way could be like CodeGenCPU:
   ```c
   void CodeGenC::VisitStmt_(const AssertStmt* op) {
       if (!BuildConfig::Current()->disable_assert) {
           std::string cond = PrintExpr(op->condition);
           PrintIndent();
           if (const auto* str = op->message.as<StringImm>()) {
               // GLOG style check
              stream << "CHECK(" << cond << ") << \"" << str->value << "\";\n";
           } else {
              stream << "assert(" << cond << ");\n";
          }
          this->PrintStmt(op->body);
       }
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services