Skip to content

Commit

Permalink
[FIX] Improve error messages and docs (apache#7064)
Browse files Browse the repository at this point in the history
- Better document tvm.relay.create_executor
- Print what was provided in src/target/llvm/llvm_module.cc,
  src/tir/transforms/arg_binder.cc,
  src/tir/transforms/storage_rewrite.cc
  • Loading branch information
tkonolige authored and electriclilies committed Feb 18, 2021
1 parent 77e174c commit 98700df
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
22 changes: 21 additions & 1 deletion python/tvm/relay/build_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,26 @@ def _graph_wrapper(*args, **kwargs):
def create_executor(kind="debug", mod=None, ctx=None, target="llvm"):
"""Factory function to create an executor.
Example
-------
.. code-block:: python
import tvm.relay
import numpy as np
x = tvm.relay.var("x", tvm.relay.TensorType([1], dtype="float32"))
expr = tvm.relay.add(x, tvm.relay.Constant(tvm.nd.array(np.array([1], dtype="float32"))))
tvm.relay.create_executor(
kind="vm", mod=tvm.IRModule.from_expr(tvm.relay.Function([x], expr))
).evaluate()(np.array([2], dtype="float32"))
# returns `array([3.], dtype=float32)`
Parameters
----------
kind : str
The type of executor
The type of executor. Avaliable options are `debug` for the
interpreter, `graph` for the graph runtime, and `vm` for the virtual
machine.
mod : :py:class:`~tvm.IRModule`
The Relay module containing collection of functions
Expand All @@ -421,6 +437,10 @@ def create_executor(kind="debug", mod=None, ctx=None, target="llvm"):
target : :py:class:`tvm.Target`
The corresponding context
Returns
-------
executor : :py:class:`~tvm.relay.backend.interpreter.Executor`
"""
if mod is None:
mod = IRModule()
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/relay/op/contrib/arm_compute_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# under the License.
# pylint: disable=invalid-name, unused-argument
"""Arm Compute Library supported operators."""
import tvm
import numpy as np
import tvm

from tvm.relay.expr import const
from tvm.relay import transform
Expand Down
3 changes: 2 additions & 1 deletion src/target/llvm/llvm_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ class LLVMModuleNode final : public runtime::ModuleNode {
found_linked_params = true;
continue;
}
ICHECK(kv.second->IsInstance<PrimFuncNode>()) << "Can only lower IR Module with PrimFuncs";
ICHECK(kv.second->IsInstance<PrimFuncNode>())
<< "Can only lower IR Module with PrimFuncs, but got " << kv.second->GetTypeKey();
auto f = Downcast<PrimFunc>(kv.second);
if (f->HasNonzeroAttr(tir::attr::kIsEntryFunc)) {
auto global_symbol = f->GetAttr<String>(tvm::attr::kGlobalSymbol);
Expand Down
2 changes: 1 addition & 1 deletion src/tir/transforms/arg_binder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void BinderAddAssert(arith::Analyzer* ana, PrimExpr cond, const std::string& arg
}
if (!is_one(scond)) {
std::ostringstream os;
os << "Argument " << arg_name << " has an unsatisfied constraint";
os << "Argument " << arg_name << " has an unsatisfied constraint: " << cond;
asserts->emplace_back(AssertStmt(scond, tvm::tir::StringImm(os.str()), Evaluate(0)));
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/tir/transforms/storage_rewrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class LinearAccessPatternFinder final : public StmtExprVisitor {
size_t level = scope_.size();
const VarNode* buf = op->buffer_var.get();
auto it = alloc_info_.find(buf);
ICHECK(it != alloc_info_.end());
ICHECK(it != alloc_info_.end()) << "Could not find buffer `" << buf->name_hint
<< "` in the list of allocated buffers. Perhaps you are "
"missing a storage_scope attr for this buffer.";
ICHECK(it->second.alloc == nullptr);
it->second.alloc = op;
it->second.level = level;
Expand Down

0 comments on commit 98700df

Please sign in to comment.