I was trying to implement an op size
to return the number of elements of the input tensor. If returned scalar as the compute result, ran into the following error message on graph runtime. The compute node is Tensor(shape=[], op.name=size)
, it looks correct as we use 0-rank tensor to represent scalar
File "/Users/yongwu/TVM/tvm/topi/tests/python/test_topi_transform.py", line 667, in <module>
test_size()
File "/Users/yongwu/TVM/tvm/topi/tests/python/test_topi_transform.py", line 644, in test_size
check_device(backend)
File "/Users/yongwu/TVM/tvm/topi/tests/python/test_topi_transform.py", line 640, in check_device
f(tvm_input, tvm_output)
File "/Users/yongwu/TVM/tvm/python/tvm/_ffi/function.py", line 153, in __call__
return f(*args)
File "/Users/yongwu/TVM/tvm/python/tvm/_ffi/_ctypes/function.py", line 209, in __call__
raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
[bt] (4) 5 ??? 0x00007ffee7349450 0x0 + 140732777403472
[bt] (3) 4 libffi.6.dylib 0x000000010f459884 ffi_call_unix64 + 76
[bt] (2) 3 libtvm.dylib 0x00000001140fe9d6 TVMFuncCall + 70
[bt] (1) 2 libtvm.dylib 0x000000011410abb5 std::__1::__function::__func<tvm::runtime::WrapPackedFunc(int (*)(void*, int*, int), std::__1::shared_ptr<tvm::runtime::ModuleNode> const&)::$_0, std::__1::allocator<tvm::runtime::WrapPackedFunc(int (*)(void*, int*, int), std::__1::shared_ptr<tvm::runtime::ModuleNode> const&)::$_0>, void (tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)>::operator()(tvm::runtime::TVMArgs&&, tvm::runtime::TVMRetValue*&&) + 277
[bt] (0) 1 libtvm.dylib 0x0000000113745f29 dmlc::LogMessageFatal::~LogMessageFatal() + 57
File "/Users/yongwu/TVM/tvm/src/runtime/module_util.cc", line 73
TVMError: Check failed: ret == 0 (-1 vs. 0) : Assert fail: (0 == tvm_struct_get(arg1, 0, 4)), arg1.ndim is expected to equal 0
Tried to trace the error, the schedule (385 here is the expected size) was mutated to:
produce size {
size[0] = 385
}
from
produce size {
size() = 385
}
The Mutate happens in tvm/3rdparty/HalideIR/src/tvm/node/ir_functor.h#L70-L76. It can be reproduced via the branch.