laekov opened a new issue #4929: [Reduction] Lower bound of reduce_axis cannot 
be expr.Var
URL: https://github.com/apache/incubator-tvm/issues/4929
 
 
   I am trying to reduce elements in some certain area of a tensor. 
   
   I found that the lower bound of the `reduce_axis` within an function passed 
to `tvm.compute` cannot be the loop vars given as arguments of the function.
   
   A minimum reproducing script is shown below.
   ```
   import tvm
   
   
   tgt_host = 'llvm'
   tgt = 'cuda'
   n = 10
   
   A = tvm.placeholder((n, ))
   
   def red_fun(i):
       red_axis = tvm.reduce_axis((i, n))
       return tvm.sum(A[red_axis], axis=red_axis)
   
   B = tvm.compute((n, ), red_fun)
   
   s = tvm.create_schedule([B.op])
   
   axis = s[B].fuse(*B.op.axis)
   blk, th = s[B].split(axis, factor=256)
   s[B].bind(blk, tvm.thread_axis('blockIdx.x'))
   s[B].bind(th, tvm.thread_axis('threadIdx.x'))
   
   my_op = tvm.build(s, [A, B], tgt, target_host=tgt_host)
   ```
   
   The error message is 
   ```
   /test/tvm/minimum_reprod.py in <module>
       22 s[B].bind(th, tvm.thread_axis('threadIdx.x'))
       23
   --> 24 my_op = tvm.build(s, [A, B], tgt, target_host=tgt_host)
       25
   
   /incubator-tvm/python/tvm/driver/build_module.py in build(inputs, args, 
target, target_host, name, binds)
      357         flist = lower(inputs, args,
      358                       name=name,
   -> 359                       binds=binds)
      360         if isinstance(flist, LoweredFunc):
      361             flist = [flist]
   
   /incubator-tvm/python/tvm/driver/build_module.py in lower(sch, args, name, 
binds, simple_mode)
      196         return stmt
      197
   -> 198     return ir_pass.MakeAPI(stmt, name, arg_list, 0, 
cfg.restricted_func)
      199
      200
   
   /incubator-tvm/python/tvm/_ffi/_ctypes/packed_func.py in __call__(self, 
*args)
      211                 self.handle, values, tcodes, ctypes.c_int(num_args),
      212                 ctypes.byref(ret_val), ctypes.byref(ret_tcode)) != 0:
   -> 213             raise get_last_ffi_error()
      214         _ = temp_args
      215         _ = args
   
   VMError: Traceback (most recent call last):
    [bt] (3) /home/laekov/incubator-tvm/build/libtvm.so(TVMFuncCall+0x4c) 
[0x7ffa78c8be5c]
    [bt] (2) 
/home/laekov/incubator-tvm/build/libtvm.so(std::_Function_handler<void 
(tvm::runtime::TVMArgs, tvm::runtime:TVMRetValue*), 
tvm::runtime::TypedPackedFunc<tvm::tir::LoweredFunc (tvm::tir::Stmt, 
std::__cxx11::basic_string<char,std::char_traits<char>, std::allocator<char> >, 
tvm::Array<tvm::runtime::ObjectRef, void>, int, 
bool)>::AssignTypedLabda<tvm::tir::LoweredFunc (*)(tvm::tir::Stmt, 
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocatorchar> >, 
tvm::Array<tvm::runtime::ObjectRef, void>, int, bool)>(tvm::tir::LoweredFunc 
(*)(tvm::tir::Stmt, std::__cxx1::basic_string<char, std::char_traits<char>, 
std::allocator<char> >, tvm::Array<tvm::runtime::ObjectRef, void>, int,
   ool))::{lambda(tvm::runtime::TVMArgs const&, 
tvm::runtime::TVMRetValue*)#1}>::_M_invoke(std::_Any_data const&, 
tvm::rntime::TVMArgs&&, tvm::runtime::TVMRetValue*&&)+0xfd) [0x7ffa78799d8d]
    [bt] (1) 
/home/laekov/incubator-tvm/build/libtvm.so(tvm::tir::MakeAPI(tvm::tir::Stmt, 
std::__cxx11::basic_string<cha, std::char_traits<char>, std::allocator<char> >, 
tvm::Array<tvm::runtime::ObjectRef, void>, int, bool)+0x17e2) [0x7fa78805a42]
    [bt] (0) 
/home/laekov/incubator-tvm/build/libtvm.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x33)
 [0x7ffa78544573] File "/home/laekov/incubator-tvm/src/tir/pass/make_api.cc", 
line 215
   VMError: Not all Vars are passed in api_args:  'i'  does not appear in 
api_args
   ```
   
   There will be no problem if the axis is changed to `(0, n - i)`.
   
   Wondering if this is a bug or a feature.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to